Results 1 to 9 of 9

Thread: SESSION not working =(

  1. #1
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default SESSION not working =(

    Okay, as the topic says, I am having a problem with the SESSION thing-a-ma-jig. . .

    I can get the session to set with no error messages, the cookie on the comp points to the correct session (of course) , and when I "print $_SESSION['username'];" it works fine. However, when I go to another page and try to bring up the info. . . . NOTHING.

    Here is the part of the code in question:

    Code:
    #--------------page one-------------------
    <?php
    # . . . . . . MySQL_query.  . . .
     
    SESSION_START();
    	$S1 = $row['username'];
    	$S2 = $row['password'];
    	$S3	= $row['accesslevel'];
    	$S4	= $row['webstatus'];
    	$_SESSION['username'] 		= $S1;
    	$_SESSION['password'] 		= $S2;
    	$_SESSION['accesslevel'] 	= $S3;
    	$_SESSION['webstatus'] 		= $S4;
    
    	print '<a href="./settings/test.php">CLICK ME</a>';
    ?>
    Code:
    #----------------Page two---------------
    <?php
    
    if ($_SESSION['username'] == 'Jas'){
    	print 'hi';
    }else{	
    	print 'bye';
    }
    	print $_SESSION['username'];
    	print $_SESSION['password'];
    	print $_SESSION['accesslevel'];
    	print $_SESSION['webstatus'];
    
    ?>
    Page two is just a test, but you get the picture. The second page does not pull up the info. Anyone know why?
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    On page 2, place session_start() at the top (just underneath the opening PHP tag).

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    thanks. I'll try that!
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  4. #4
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Yeah, every page containing session variables must contain the session_start().
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You may have run into this problem in that not having that command at the start will actually work in some cases, but not others. Sometimes, the data is still sent, but most times is not, so you'd have inconsistant results with that.
    So, yes, just add that at the very start of each page, and that's it.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Or, you can configure your server to start the session automatically.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  7. #7
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Quote Originally Posted by tech_support View Post
    Or, you can configure your server to start the session automatically.
    You can, but not many people have access to the server configuration, or do not have the "know-how" to do so. Perhaps the most effective way to do this would be to manually start the session each time (on each page using session_start() ).
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  8. #8
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    also, the session declaration must be at the very top of the page, so that it will place the appropriate headers into the file

    Code:
    <?php
    session_start();
    ?>
    
    __DOCTYPE_DECLARATION___
    <html>
    ...
    </html>

  9. #9
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    Thanks guys! it works great.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

Bookmarks

Posting Permissions

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