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
https://forums.phpfreaks.com/topic/42447-sessions/
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
https://forums.phpfreaks.com/topic/42447-sessions/#findComment-205937
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.