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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Oct 2005
    Location
    Surrey, England
    Posts
    286
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Problems calling a session

    The problem i have really confuses me.

    When i classify a session to the user (in either the login.php or register.php page) the page userarea.php displays properly.

    If i then refresh the page or click a link to userarea.php all the info disappears.

    I have tried echoing the session variable to see whats going on and instead of being "1" (the users id number) the variable changes to "Array" once refreshed.

    I never actually touched the variable and all three pages have session_start(); in them.

    Any ideas?
    Daniel Warner
    - - - - - - - - - -
    GuitarMart.co.uk - Free Online Classified Advertisement for Guitarists in the United Kingdom. Free Ads with a Free Photo.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Find out what's in the session variable:
    PHP Code:
    var_dump($_SESSION); 
    It's being modified somewhere in the file(or one that it includes). Do a search for $_SESSION in your file(s).

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,959
    Thanks
    2
    Thanked 304 Times in 296 Posts
    It is likely that the session is not starting. Add the following two lines after the first opening <?php tag to get php to help you -

    PHP Code:
    ini_set ("display_errors""1");
    error_reporting(E_ALL); 
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #4
    Regular Coder
    Join Date
    Oct 2005
    Location
    Surrey, England
    Posts
    286
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Thanks for the error reporting code. I probably should just leave that in for good practice.

    I found the error too. I was calling a variable called $username and my session was called $_SESSION['username'] which for some reason made itself break.

    Is there a way of turning this off?

    Thanks.
    Daniel Warner
    - - - - - - - - - -
    GuitarMart.co.uk - Free Online Classified Advertisement for Guitarists in the United Kingdom. Free Ads with a Free Photo.

  • #5
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,959
    Thanks
    2
    Thanked 304 Times in 296 Posts
    That's due to register globals being on. Turn them off or use unique names for all program/post/get/cookie/session variables.

    In addition to being a security risk by intentionally populating same name variables from external variables, register globals also causes unintentional overwriting of same name variables even if you don't want them to be.
    Last edited by CFMaBiSmAd; 03-10-2008 at 07:01 PM.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

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