im trying to use sessions to pass an object from one page to another...im facing the problem of sessions not being set in the next page...
i think i know the problem but i dont know how to fix it.
the problem in my opinion is that the second page in included inside the first page using a require...thats why i think sessions are not being transfered to the second page....
this is only what i think but i might be mistaken....i will include a small code to demonstrate what im doing:
the following is the code inside a file named profile.php
Code: Select all
<?php
session_start();
if(isset ($_POST['username']) && isset ($_POST['password'])) {
$username = htmlentities(addslashes($_POST['username']), ENT_QUOTES);
$password = htmlentities(addslashes($_POST['password']), ENT_QUOTES);
}
require 'Objects/DB_Objects/User.php';
require 'Objects/Service_Providers/Tools.php';
require 'Objects/Service_Providers/config.inc.php';
$userObject = login($username, md5($password));
if($userObject != false) {
$path = "succeed";
$_SESSION['userObject'] = serialize($userObject);
print "i did set the session";
}else {
$path = "failed";
}
require 'http://localhost/HR/Objects/Service_Providers/Page_Parts/User_Area/content.php?login=' . $path;
?>
Code: Select all
<?php
session_start();
require '../../../DB_Objects/User.php';
if(isset ($_SESSION['userObject'])) {
print "i am in the succeed part";
$login = "succeed";
}else {
print "i am in the failed part";
$login = "failed";
}
if($login == "succeed") {
if(unserialize($_SESSION['userObject']) instanceof User) {
$user = unserialize($_SESSION['userObject']);
}else {
print "login failed";
}
thanks in advance