Jump to content

Sessions


adam84

Recommended Posts

I am having a problem with sessions.  I have three pages, leftPage(toolbar) and rightPage(extra) and centerPage(main content). I am using ajax to load all three pages into one mainPage. All of my pages have included the session file. But when I attempt to log in the sesson login function gets called and the variables get set. But when I then reload the leftPage using ajax, it seems that the variables are not set anymore because the content is not changing.

 

 

This is my session file, its just has a few variables. I just want to get it working before I add more stuff to it.

<?
class session{
   var $userid;
   var $logged_in;

   function session(){
       session_start();   
   }

   function login($userID){
$this->logged_in = true;
             $this->userid = $_SESSION['userid'] = $userID;
   }


   function logout(){
      unset($_SESSION['userid']);
      $this->logged_in = false;  
   }

};
$session = new session;
?>

 

This is the leftPage file

<?
include("include/session.php");

if( $session->logged_in ){
	echo "Logged in, YAY!";
}else{

            echo "Not logged in<BR>";
                         echo "<A HREF=javascript:void(0); ONCLICK=loadMenuItem(1);</A>Login</A>";
}
?>

 

<?
include("include/session.php");

$link = mysql_connect ("~~~");
mysql_select_db ("~~~"); 
            
             $user = $GET['user'];
             $pass = $GET['pass'];

$query = "SELECT * FROM user WHERE user = '$user' AND pass= '$pass'";
$r = mysql_query( $query, $link );
if( mysql_num_rows( $r ) > 0){
	$session->login( $row[0] );
}
                     echo "user not found";
?>

 

My ajax file is where I call the function to update the leftPage

Link to comment
Share on other sites

should this say

 

<?php
include("include/session.php");
$session = new session(); //this is what i added
if( $session->logged_in ){
	echo "Logged in, YAY!";
}else{

            echo "Not logged in<BR>";
                         echo "<A HREF=javascript:void(0); ONCLICK=loadMenuItem(1);</A>Login</A>";
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.