News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

New tools to help integrating SMF with something else

Started by Andre N, September 19, 2011, 01:35:36 PM

Previous topic - Next topic

Kindred

ah... you are going to have issues...

SMF has its own session handling... which means that previously establish sessions may not survive the load of SMF (and vice-versa)
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Dromo

The only way I could get it to work was to remove the call to smfapi_loadSession() in the API. I don't need an SMF session as all I am doing is adding a member to the forum database. This works: the member is added to the forum and my initial script passes my session variables to the second script correctly.

I tried all kinds of things such as destroying the session after the forum had been updated and then starting a new one with just my own variables but whatever I did, none of it worked.

What I have done is really only a workaround. I would appreciate if somebody could really explain why the session which the API starts should affect a session which is started afterwards

Kindred

I could be wrong... but I don't think that you can have two sessions active at the same time...   so starting a new session either fails or destroys the old session

and, of course, by doing what you have done, you removed part of the SMF security...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Dromo

As far as I understand it, you're right: you can't have two sessions active at once.  That's why, first of all, I tried to kill the session that the API had started once I had finished with it.  No luck.  I don't think I'm compromising the SMF security (although I am happy to be proved wrong).  My use of the API is very limited. The logic of the script goes:

1) Display a form
2) Receive and validate data
3) Add a member to the MySQL database
4) Add a member  to the forum using the API
5) Exit to the next script with the new member's id (MySQL not SMF) as a session variable .

The code for step 4 looks like this:

require_once 'smf_2_api.php';
$forumok = "n";
$member_name = $first_name." ".$last_name;
$email_suffix = 1;
$email_suffix_needed = "n";
$member_name_suffix = 1;
while ($forumok == "n") {
   $regOptions = array('member_name' => $member_name, 'real_name' => $member_name, 'email' => $email, 'password' => $password, 'lngfile'=> $forum_lang);
   $answers = smfapi_registerMember($regOptions);
   if (!is_array($answers)) {
      $forumok = "y";
      continue;
   }else{
        if (in_array("email already in use", $answers)) {
         if ($email_suffix_needed == "n") {
            $email = $first_name. $last_name . "@xxxxx.org";
            $email_suffix_needed = "y";
         }else{
            $email = $first_name. $last_name . $email_suffix . "@xxxxx.org";
            ++$email_suffix;
         }   
      }
      if (in_array("username taken", $answers)) {
         echo "username taken found... \r\n";
         $member_name = $member_name . $member_name_suffix;
         ++$member_name_suffix;
         echo "username = ". $username;
      }   
   }   
}

Thanks for taking the trouble to reply; I appreciate it.

   

Dromo

#164
As you can see from the code in my post of 10 October, in my application the username is a concatenation of the member's first and last names. This is fine when a member is first of all added to the forum, but I have a problem if the member subsequently changes either of their first or last names. Given that it is probably a key to a number of other tables in the database, I imagine that it will not be possible just to update the existing username with a concatenation of the new first and last names.

The only thing that I can think of is to create a completely new user. This would not be a satisfactory solution as there would then be a disconnect between all the other information (posts etc.) that are held in the forum under the old name and information inserted under the new name.

Is there any way that this particular problem can be solved?

Will I have similar problems with email address?

Mex

Nice API.
Is there a function to check if a user is logged in by checking cookie data?

vexq

I'm getting an error

Undefined variable: cookieData [APP\Vendor\smf_2_api.php, line 1909]

It seems to stem from it either never setting up $cookieName or from not setting $cookieData. Is the api still in development or is it stable enough to use?

Kindred

The API has been successfully used on dozens, if not hundred of sites..
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

vexq


Kindred

No...   Especially since 2.1 is still just in beta 1
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Mac Tracbac

Hi,

I have an SMF forum that has been running for a long time. I would now like to be able to post things from an Android app (It will be a very simple thing with an intent-filter that adds itself to the share menu on an Android device. The content will then be posted in a thread). I am an engineer and know how to code, but I am clueless about web-programming and related things. However, people on said forum could help me quite a bit with the server side problems, but I feel like I need to figure out the correct direction first.

Would using this API be feasible and make sense for this application? I know that the API has no ready written functions for posting, but it seems easy to add to the API (as explained earlier in the thread). What is unclear to me is how the Android java would communicate with the API and how the API php-would be integrated in the app.

I am not looking for detailed answers, but I would very much appreciate any comments on the general feasibility and perhaps a few hints so that I could be on my way to find out the details on my own.

Arantor

Well, the API PHP part stays on the server, and the Java client sends commands to the API via HTTP... you don't have to worry about embedding any of the PHP on your app.

Your biggest question is really about getting something going in Java to communicate with the API in all honesty. It's not a task for the faint of heart, regardless of whatever programming background you're coming from.

Mac Tracbac

Quote from: Arantor on January 15, 2015, 01:44:08 PM
Your biggest question is really about getting something going in Java to communicate with the API in all honesty. It's not a task for the faint of heart, regardless of whatever programming background you're coming from.

Thank you very much fow your answer.

I see. This was the part that I didn't grasp, but I assumed it would be a straightforward task (given general knowledge). But do you agree that if it should be done, using the API is the sensible way to go? I have seen that there are more direct solutions, but they seem incredibly messy.

Arantor

I'd suggest the RESTful API - http://www.simplemachines.org/community/index.php?topic=458832.0 - is probably a bit more what you're looking for. This particular one is designed for integration with other systems, not for the kind you're trying to do.

BigOHenry

Is this API compatible with SMF 2.1 beta1? I am developing new application and i would like to use SMF 2.1.

Kindred

I have not checked or tested, but I suspect almost certainly not....
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

BigOHenry

Thank you for quick answer, so i will use 2.0.9 version.

I am getting error in my application when include smf_2_api.php file:

Undefined variable: cookieData [www\integration\smf_2_api.php, line 1909]

Any ideas? :(

Arantor


BigOHenry

not use for now. only included and getting error...

Arantor


Advertisement: