Jump to content

Working with $_SESSION in a amfphp environment


Jonob

Recommended Posts

I have a flex application that uses mysql and php on the backend, which is run through an amfphp installation. Data is transferred between the database and the front end via amfphp. I have this all working 100%.

 

In this scenario, there are a number of php files, each of which contains one class (and each class has the same name as the file name). Within each class there are a number of functions.

 

I am now considering the security side of the app, and would like to implement $_SESSION variables. I have read up on how to work with sessions in PHP, but its been pretty difficult to try decipher how to implement it in a amfphp environment.

 

Am I even on the right track here?

 

1. Once a user has been logged in, you store 1 or more pieces of data in the $_SESSION variable, such as the user_id or user_name. So, something like this:

 

<?php
class login
{
  function do_login
  {
     session_start();
     session_unset();
     //Code to check if the login is correct
     //If login is valid then create the session
     if (!isset($_SESSION['userID'])) 
     {
          $_SESSION['userID'] = $userID;
     }     
   }
}
?>

 

2. On all subsequent service calls, I need to check

if(!isset($_SESSION['userID']))
{ 
   return "Error: Session not set";
}

 

Where does this check take place? After the opening <?php tag, inside the class, or at the start of each function?

 

Any other glaring errors or omissions?

 

Thanks for any tips that you can give.

Link to comment
Share on other sites

The only problem that I see with the code with a quick glance is that you are using session_start() and then session_unset() right after that. The session start obviously starts the session but when you run the session_unset you are pretty much destroying the session. You don't want to run that until you want to get rid of the session. If you are trying to get rid of sessions before they login I suggest you put it above the session_start() or just remove it as it is not needed.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.