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
    New Coder
    Join Date
    Sep 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    not accessing some sessions

    ok, im about to tear my hair out over this and im sure its some really easy problem to fix, bassically, i have a session ($_SESSION['loggedin']), and i access it with an if statement towards the top of a page, if the statement returns TRUE, then it prints some stuff out, if it returns FALSE, then it prints something else out. but this doesnt work, it always prints out what it should if the IF statement were false.

    heres why its confusing: later in the same script, i access the same session, with the exact same if statement, and it works flawlessly. i dont alter, touch, even access the session in between these two instances. as well, the session isnt set on the page its being accessed from, so im lost, code is below:

    Code:
    if ($_SESSION['loggedin'] == TRUE) {
    				print("Messaging system coming in next release!");
    			} else {
    				print(' 
    					<form name="login" action="index.php?action=login" method="POST">
    					Username:<input type="text" name="username"> &nbsp;&nbsp;
    					Password:<input type="password" name="password">
    					<input type="submit" value="Submit">
    					</form>
    				');
    			}
    heres where the session works and is accessed perfectly

    Code:
    if ($_SESSION['loggedin'] == TRUE) {
    		print("<div align=\"center\">Logged in as: <br> " . $_SESSION['username']);
    		print("<hr width=\"100\"> <br> <a href=\"index.php?action=login&mode=logout\">Logout</a>");
    		print("</div>");
    	}
    please help, thanks

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Do you have session_start() somewhere before the if?
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    New Coder
    Join Date
    Sep 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes, its at the very begining of the page

  • #4
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,855
    Thanks
    22
    Thanked 157 Times in 148 Posts
    Usually, in my experience, session problems occur when you forget to use:

    PHP Code:
    session_start() 
    at the top of the page, or you forget to define your session variables, or you're session variables are set using faulty POST data....
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #5
    New Coder
    Join Date
    Sep 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, figured it out, i had session_start; rather than session_start();

    i got an error for something else on the same line, changed both of them, and well, kinda hard to describe, anyways thanks for the help.


  •  

    Posting Permissions

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