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.
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:
When you have a session in PHP each page that is included in the session needs a call to
session_start()before the global$_SESSIONcan be accessed.