Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts

    losing session object when using header("Location:

    Hiya,

    I've added the header("Location: http://wheretoforward"); to my security class whereas before I was using javascript to forward, and now my serialized session object is null, anyone know why? or will I be forced to use javascript instead?

    Saving the object
    Code:
    # save this object on the session
    				$_SESSION["securityObj"] = serialize($this);
    								
    				#$this->makeJavaScriptStr();
    				header("Location: http://".$_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) ."/cm/");
    Restoring the object on another page
    Code:
    $sObj = unserialize($_SESSION["securityObj"]);
    					
    					print "<br>type of securityObj: " . gettype($_SESSION["securityObj"]);
    					print "<br>Test variable, getUserLoginName(): " . $sObj->getUserLoginName();
    If I don't use the header("location: etc...") and use javascript window.location.href = "some place"; then the object is restored without problems and I can access all its members and properties, yet using the header method to forward users results in the object being Null.

    Any ideas welcome

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Changing pages within a site won't have an effect on the session since it is a browser session for that site. Have you verified that the value is set before the header is given? And is the URL you are redirecting to still within the site, ie not a another different domain or a subdomain? Also you might want to add this to the top of the pages

    PHP Code:
    error_reporting(E_ALL); 
    This will show any errors that may be happening and are not being displayed.
    Last edited by Spookster; 01-17-2004 at 03:22 PM.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, the variable is defo set, if I remove the header line, the forwarding is then controlled by javascript and that works ok

    All on the same site etc... perhaps... hmmm, the javascript forwards with window.location.href= 'cm/ '; and the header builds the entire string http://localhost/testarea/cm/, that loses the session, I've just added the SID to end of the path using header, and it works ok.

    Thx


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •