Web Analytics Made Easy -
StatCounter Sessions not functioning properly - CodingForum

Announcement

Collapse
No announcement yet.

Sessions not functioning properly

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sessions not functioning properly

    I have got the session working somewhat, but can't figure out what is wrong with the set up.

    I have it at the point where when I log in it will work, but it won't allow me into any of my pages that have the sessions required. If I don't want to allow you to access the page directly, the change password page or my main page as an example, it won't allow me in at anytime.

    I have my the login page set up to redirect you to the main page, but when it redirects, I get the "You must be logged in" message and I am not sure what is wrong.

    Here is what I have.

    Loginck Page

    Code:
    <?php
    $userid=mysql_real_escape_string($userid);
    $password=mysql_real_escape_string($password);
    
    if($rec=mysql_fetch_array(mysql_query("SELECT * FROM employees WHERE userid='$userid'
    AND password = sha1('$password')"))){
    	if(($rec['userid']==$userid)&&($rec['password']==sha1($password))){
    	 include "include/newsession.php";
    	 	 echo "<center>You are Successfully Logged In!!<br><br><a href='logout.php'> Log OUT </a><br><br>
    			<a href=GEMain.php>Click here if your browser is not redirecting automatically.  You should
    			be redirected to the Main Menu in approximately 5 seconds.</a><br></center>";
         print "<script>";
           print "self.location='GEMain.php'"; // Comment this line if you don't want to redirect
              print "</script>";
    						}
    flush();
     sleep(6);
    		}
    	else {
    		session_unset();
    echo "<font face='Verdana' size='3' color=blue><B><CENTER>The username or password you entered
    is not valid!!<BR> <BR>Please try again!!<BR></CENTER></B> <br><center><input type='button'
    value='Retry' onClick='history.go(-1)'></center>";
    		}
    and this is what I have in the GEMain page and the change password page.
    Code:
    include "myconnect.php";
    include "include/session.php";
    if(!isset($_session['userid'])){
    echo "<center><B><font face='Verdana' size='2' color=red>Sorry, You must be logged
    in to use this Page!! </font></B></center>";
    exit;
    }
    The include/newsession.php file has the following in it
    Code:
    //error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR);
    $_session['id']=session_id();
    $_session['userid']=$userid;
    //echo $session['userid'];
    The include/session.php files has this in it:
    Code:
    session_start();
    session_register("session");

    One thing I am not sure about is whether $Session and $_Session can be used interchangeably. In the code directly above I use $_session, but on the loginck page it used $session (in the include/session file), so am not sure if that is causing a problem. I have tried changing them around and it still does not resolve the problem.

    Thanks for the help

    Ken

  • #2
    $_session should be uppercase

    i.e $_SESSION['id']

    Comment

    Working...
    X