2

i'm trying to make a login page in php using ajax and php functions.. i'm trying to create a session inside the function. and i fail to make it work. this is basicly what i'm trying to do

the ajax code is

$.post("process.php?do=createSession", 
function(data) {alert("Data Loaded: " + data);});

in process.php i got this script

include ( 'bod_function.php' ); 
$process_func = $_REQUEST['do'];
echo BODeal::$process_func();

and in the bod_function.php i got this running

class BODeal {
public static function createSession() {
    session_start();
    $_SESSION['test']='Success';
    return 'yeah';
   }
}

i got the alert box running and saying 'yeah' but $_SESSION['test'] is empty. no session has been created.

1 Answer 1

1

The session needs to be started in each new page you open. I think what you want to do is start the session from the page you are calling from and leave it empty. Then when you make your AJAX call you will need to start the session again, as you have, and then set:

$_SESSION['test']='Success';

When you have a session in PHP each page that is included in the session needs a call to session_start() before the global $_SESSION can be accessed.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you so much!!! i included session_start(); at my index.php and it works now! thank you again!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.