Advertisement:

Author Topic: New tools to help integrating SMF with something else  (Read 220007 times)

Offline ankifreeze

  • Semi-Newbie
  • *
  • Posts: 21
Re: New tools to help integrating SMF with something else
« Reply #20 on: December 22, 2011, 07:43:18 PM »
yeah I have deleted $_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT']  yesterday and it works now....I have enable Use subdomain independent cookies  in admin center but still doesn't work... :(

Offline ankifreeze

  • Semi-Newbie
  • *
  • Posts: 21
Re: New tools to help integrating SMF with something else
« Reply #21 on: December 23, 2011, 01:54:27 AM »
also how to remove register and login form?I have removed one in tempate function but I didn't find in another place......I have removed login and register link but if someone using url like index.php?action=login or index.php?action=register site will calling  login and registration function and  login or register form still appear and if session or cookie has expired  the site will called login form or register form too... :(

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #22 on: December 23, 2011, 07:05:22 AM »
Run a test script in both site/forum and site

Code: [Select]
require_once('path/to/api');
global $cookiename;
echo $cookiename;
echo '<br /><pre>';
print_r($_COOKIE[$cookiename]);
echo '</pre><br />';
$data = unserialize($_COOKIE[$cookiename]);
if (!$data) {
    echo 'Unable to unserialize cookie';
} else {
    echo '<pre>';
    print_r($data);
    echo '</pre>';
}

for the login and register link, if you want to remove them and redirect to something else, you'd look in /index.php. It shows:
Code: [Select]
'login' => array('LogInOut.php', 'Login'),
and
Code: [Select]
'register' => array('Register.php', 'Register'),

so login maps to /Sources/LogInOut.php function Login() and register maps to /Sources/Register.php function Register()

go to those files and at the top of the function redirect to your other login and register page :)

Code: [Select]
// Ask them for their login information.
function Login()
{
        //redirect to other login
        header('Location: http://www.somewhere.com/login.php');

global $txt, $context, $scripturl;

// In wireless?  If so, use the correct sub template.
if (WIRELESS)
$context['sub_template'] = WIRELESS_PROTOCOL . '_login';
// Otherwise, we need to load the Login template/language file.
else
{
loadLanguage('Login');
    ...
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline ankifreeze

  • Semi-Newbie
  • *
  • Posts: 21
Re: New tools to help integrating SMF with something else
« Reply #23 on: December 23, 2011, 08:11:57 AM »
I have tested it.....I think it doesn't work in site folder...

http://localhost/site/test.php [nofollow]
Code: [Select]
SMFCookie956
Notice:  Undefined index: SMFCookie956 in C:\xampp\htdocs\site\test.php on line 8
Notice: Undefined index: SMFCookie956 in C:\xampp\htdocs\site\test.php on line 10
Unable to unserialize cookie

http://localhost/site/forum/test.php [nofollow]
Code: [Select]
SMFCookie956

a:4:{i:0;s:1:"1";i:1;s:40:"9188720a1bfe3a5bd315d7cbb4e9f84a6f140e4d";i:2;i:1356238923;i:3;i:3;}


Array
(
    [0] => 1
    [1] => 9188720a1bfe3a5bd315d7cbb4e9f84a6f140e4d
    [2] => 1356238923
    [3] => 3
)


I have put header('Location: http://localhost/site/login.php [nofollow]') in login function and it works but how about login form?  login form is appear when session expired? where I can delete it? :(


Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #24 on: December 23, 2011, 08:54:35 AM »
Ok, I have 2 ideas as to what might be causing the API to not work outside your /forum directory.

1. The cookie is set for /forum. Can you manually verify the cookie path, either by using firecookie or opening your browser settings to view the cookies and check your SMFCookie956 to make sure the path is '/'. If you aren't sure how to see, please pm me a link to your site and a test user login.

2. The API might not be locating your Settings.php file. It will search for smfapi_settings.txt file first, which is a save file it creates with the location of your Settings.php file. Then it will check if you've specified the location of the file, around line 574. Then it will see if Settings.php is in the same directory it is. Then it will start searching for it. The search might time out if your server resources are low or you have lots of files and directories, so it's possible that the API finds your Settings file when it is in the same directory, but times out looking for it when it is not. You can specify the path to your SMF Settings.php file on about line 574 (depending on which version of the API you have).
You'll see a line that looks like:
Code: [Select]
// specify the settings path here if it's not in smf root and you want to speed things up
//$settings_path = $_SERVER['DOCUMENT_ROOT'] . /path/to/Settings.php

Let me know :)

The login form is located at /Themes/default/Login.template.php
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #25 on: December 23, 2011, 09:18:45 AM »
Thinking about this some more, I'm positive this is a cookie issue with the cookie not being on the right path.
If the script timed out, it wouldn't have rendered the output. Plus it did get the name of the cookie, that comes from the Settings.php file. Your SMF cookie isn't viewable outside of /forum and that is the issue here
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline ankifreeze

  • Semi-Newbie
  • *
  • Posts: 21
Re: New tools to help integrating SMF with something else
« Reply #26 on: December 23, 2011, 06:53:47 PM »
cookie path location is http://localhost/site/forum [nofollow]
[nofollow]



and about setting.php location I have made newfolder and changed location in smf_2_api.php...I think that is not a problem... :)

Code: [Select]
// specify the settings path here if it's not in smf root and you want to speed things up
//$settings_path = $_SERVER['DOCUMENT_ROOT'] . /path/to/Settings.php

// get the forum's settings for database and file paths
if (file_exists(dirname(__FILE__) . '/newfolder/Settings.php')) {
    require_once(dirname(__FILE__) . '/newfolder/Settings.php');
} elseif (isset($settings_path)) {
    require_once($settings_path);
} else {

Offline ankifreeze

  • Semi-Newbie
  • *
  • Posts: 21
Re: New tools to help integrating SMF with something else
« Reply #27 on: December 26, 2011, 07:40:30 AM »
I have solved the cookie issue....thanks... :)

Offline Bugo

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 1,453
  • Gender: Male
    • dragomano on GitHub
    • @dragomano on Twitter
    • Russian translations for SMF mods
Re: New tools to help integrating SMF with something else
« Reply #28 on: December 27, 2011, 01:13:38 PM »
Hi, I use this code for authentification:
Code: [Select]
...
if (smfapi_authenticate($login, $pass))
smfapi_login($login);
...
and get these errors:
Quote
Message: Undefined index: content
Filename: smf_2_api.php
Line Number: 988
Quote
Message: Undefined index: character_set
Filename: smf_2_api.php
Line Number: 988

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #29 on: December 27, 2011, 02:16:20 PM »
Hi, I use this code for authentification:
Code: [Select]
...
if (smfapi_authenticate($login, $pass))
smfapi_login($login);
...
and get these errors:
Quote
Message: Undefined index: content
Filename: smf_2_api.php
Line Number: 988
Quote
Message: Undefined index: character_set
Filename: smf_2_api.php
Line Number: 988

@Bugo, try changing this in line 988:
Code: [Select]
if ($context['character_set'] == 'utf8'
                && !empty($modSettings['previousCharacterSet'])
                && $modSettings['previousCharacterSet'] != 'utf8')
to be this:
Code: [Select]
if (isset($context['character_set']) && $context['character_set'] == 'utf8'
                && !empty($modSettings['previousCharacterSet'])
                && $modSettings['previousCharacterSet'] != 'utf8')
and you're problem there should go away :)
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline ledaladdin.com

  • Newbie
  • *
  • Posts: 5
Re: New tools to help integrating SMF with something else
« Reply #30 on: January 09, 2012, 09:48:30 PM »
Thanks for pointing me in the right direction!

Offline Meriadoc

  • SMF Friend
  • Sophist Member
  • *
  • Posts: 1,263
  • Gender: Male
  • For the world is changing
    • Philip Renich: Websites
Re: New tools to help integrating SMF with something else
« Reply #31 on: February 02, 2012, 07:59:49 PM »
Hey, this API I think will be great. I'm having a couple issues though myself.

I'm just trying to do a basic test right now to make sure it's working. I've logged into the forum (./discuss on my server) and verified the cookie is being set. It's sub-domain agnostic and the path is '/'

When I check my script that's including the API everything is required() correctly. I can print_r() out the $user_info but it is showing me as a guest even though I'm logged in in the forum.

I ran your little cookie test and it said it could not unserialize it. I tried stripslashes() and it worked fine unserializing the cookie. I tried adding the stripslashes() code to the two spots in smfapi_loadUserSettings() (lines 1862 and 1869) but it doesn't seem to be doing anything.

Doing some tests led me to the place it's failing out. It is following the if/else statements to line 1865 and setting $id_member to 0. But it seems, based on the comment, that that inner if/else statement is just a PHP4.3 fix (I'm running PHP 5.x)

Shouldn't there be some other logic there to grab the cookie info even if the preg_match fails?

Thanks!
If I know the way home and am walking along it drunkenly, is it any less the right way because I am staggering from side to side? : Leo Tolstoy
Everything I know I learned from Calvin and Hobbes.
And patience is about the most useful thing you could ever have.  That and backups. : [Unknown]
If I choose to send thee, Tuor son of Huor, then believe not that thy one sword is not worth the sending. : Ulmo, Lord of the Waters - Unfinished Tales, by J.R.R. Tolkien

Offline Meriadoc

  • SMF Friend
  • Sophist Member
  • *
  • Posts: 1,263
  • Gender: Male
  • For the world is changing
    • Philip Renich: Websites
Re: New tools to help integrating SMF with something else
« Reply #32 on: February 02, 2012, 08:09:28 PM »
I was able to "fix" this (hopefully) by ALSO adding a strip slashes to the $_COOKIE[$cookiename] of the preg_match on line 1861. Hopefully those three instances of that function doesn't do bad things.

If it matters I just looked at magic_quotes_gpc are ON (though _runtime and _sybase are OFF)
If I know the way home and am walking along it drunkenly, is it any less the right way because I am staggering from side to side? : Leo Tolstoy
Everything I know I learned from Calvin and Hobbes.
And patience is about the most useful thing you could ever have.  That and backups. : [Unknown]
If I choose to send thee, Tuor son of Huor, then believe not that thy one sword is not worth the sending. : Ulmo, Lord of the Waters - Unfinished Tales, by J.R.R. Tolkien

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #33 on: February 02, 2012, 10:03:24 PM »
yeah, if you can turn the magic quotes off you should be ok

if not, look for where the cookie is unserialized:
Code: [Select]
list ($id_member, $password) = @unserialize($_COOKIE[$cookiename]);

and strip the slashes at that point so it will unserialize ok
Code: [Select]
list ($id_member, $password) = @unserialize(stripslashes($_COOKIE[$cookiename]));

I found 2 spots
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline Meriadoc

  • SMF Friend
  • Sophist Member
  • *
  • Posts: 1,263
  • Gender: Male
  • For the world is changing
    • Philip Renich: Websites
Re: New tools to help integrating SMF with something else
« Reply #34 on: February 03, 2012, 06:27:40 PM »
Yep that does it. Also necessary to stripslashes() on this line:
Code: [Select]
if (preg_match('~^a:[34]:\{i:0;(i:\d{1,6}|s:[1-8]:"\d{1,8}");i:1;s:(0|40):"([a-fA-F0-9]{40})?";i:2;[id]:\d{1,14};(i:3;i:\d;)?\}$~i', $_COOKIE[$cookiename]) == 1) {

That way the regex / preg_match() will work out when it needs to.
If I know the way home and am walking along it drunkenly, is it any less the right way because I am staggering from side to side? : Leo Tolstoy
Everything I know I learned from Calvin and Hobbes.
And patience is about the most useful thing you could ever have.  That and backups. : [Unknown]
If I choose to send thee, Tuor son of Huor, then believe not that thy one sword is not worth the sending. : Ulmo, Lord of the Waters - Unfinished Tales, by J.R.R. Tolkien

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #35 on: February 04, 2012, 03:59:43 PM »
Very helpful to know. I should just add the stripslashes command to the next release, because it definitely wouldn't hurt anything to always call it there
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline lilsammy1989

  • Newbie
  • *
  • Posts: 7
Re: New tools to help integrating SMF with something else
« Reply #36 on: February 13, 2012, 10:11:00 AM »
Hi I am trying to use this to add to a registration function I already have, I am running a website with its own user database and then at the same time I want to register the user into the form.

Anyway I am trying to get the basic functionality working like so. If you could help me out I would appreciate it as the function for registering them into the site seems to be working but the part to register them into SMF isn't working.

Also will the register function work if after I get it working I disable it on the SMF in admin settings or does this need to be left on?

Code: [Select]
if (!isset($_POST['name']) && !isset($_POST['steam']) && !isset($_POST['email']) && !isset($_POST['email2']) && !isset($_POST['password']) && !isset($_POST['password2']) && !isset($_POST['acceptTerms'])) {
echo "Waiting User Input";
}else{
include './static/classes/validation.php';

$name = $_POST['name'];
$steam = $_POST['steam'];
$email = $_POST['email'];
$email2 = $_POST['email2'];
$pass = $_POST['password'];
$pass2 = $_POST['password2'];
$userIP = getenv('REMOTE_ADDR');
require_once ('./static/classes/smf_2_api.php');

$sha_passwd = sha1(strtolower($name).smfapi_unHtmlspecialchars($pass));
 
if((validate_username($name) == true) && ($email == $email2) && (check_email_address($email) == true) && ($pass == $pass2)){
include './static/classes/config.php';

$conn = mysql_connect($host,$user,$pass);
if (!$conn) {
die('Could not connect: ' . mysql_error());
}

mysql_select_db($db, $conn);
mysql_set_charset('utf8',$conn);

$sql_username="SELECT * FROM User WHERE User_Name = '$name'";
$sql_email="SELECT * FROM User WHERE User_Email = '$email'";

$user_check=mysql_query($sql_username);
$email_check=mysql_query($sql_email);

if (mysql_num_rows($user_check) > 0){
echo "Error - 02"; // Username in Use.
}else{
if (mysql_num_rows($email_check) > 0){
echo "Error - 03"; // Email in Use.
}else{

$reg= array(
'member_name' => '$name',
'email' => '$email',
'require' => 'nothing',
'password' => '$pass',
'password_check' => '$pass2',
);
smfapi_registerMember($reg);

$new_user=mysql_query("INSERT INTO User (User_Name, User_Pass, User_IP, User_Admin, User_Beta, User_SteamID, User_Registered, User_Email) VALUES ('$name', '$sha_passwd', '$userIP', '0', '1', '$steam', 'NOW()', '$email')");
if (!$new_user) {
$message  = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
};



echo "Registered";
};
};
};
};
?>

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #37 on: February 13, 2012, 11:08:11 AM »
Hi,
It looks like the problem with your registration into SMF is that you're setting the registration variables incorrectly. You have:
Code: [Select]
$reg= array(
'member_name' => '$name',
'email' => '$email',
'require' => 'nothing',
'password' => '$pass',
'password_check' => '$pass2',
);
which is going to put the string '$name' into the SMF db as the name, instead of the variable value which is what you want. Try it without the quotes and it should work.
Code: [Select]
$reg= array(
'member_name' => $name,
'email' => $email,
'require' => 'nothing',
'password' => $pass,
'password_check' => $pass2,
);
You can disable the registration in SMF admin and it will still register through the API. Another way to do it would be to modify the registration template or methods to redirect to your other registration page. That way when someone tries to register in SMF instead of an error message they will get sent to a place they can register.
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline lilsammy1989

  • Newbie
  • *
  • Posts: 7
Re: New tools to help integrating SMF with something else
« Reply #38 on: February 13, 2012, 12:52:06 PM »
That worked great I thought it was somthing simple I just wasn't getting, In my defense I am coding high ;)

Offline frytec

  • Jr. Member
  • **
  • Posts: 134
  • Admin Aika F√≥rum
    • CataLink.com.br
Re: New tools to help integrating SMF with something else
« Reply #39 on: February 17, 2012, 12:36:40 PM »
im trying to synchronize the login of my site with smf.

im using it this way:

Code: [Select]
require_once ('/forum/smf_2_api.php');
if (smfapi_authenticate($username, $password))
smfapi_login($username);

but nothing seems to happen.

i open 2 browser tabs, my site and smf, bothe logged off.

i login into my website and go to smf tab and refresh the page, but its still logged off!

can you help me?
« Last Edit: February 17, 2012, 02:09:52 PM by frytec »
Comunidade Aika Forum > http://www.aikaforum.com.br
Portal DetetiveWEB > http://www.detetiveweb.com.br
CataLink.com.br > http://www.catalink.com.br