problem in session

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

problem in session

Post by itsmani1 »

Code: Select all

$query= ("SELECT userid,clientid,accesspoint,lang1,lang2,lang3 FROM users where login = '$username' and password = '$password' and clientid=$company");
	$result= mysql_query($query);

	if (!$result)
	{
    	echo mysql_error();
	    exit();
	}

	$num = mysql_num_rows($result);
	if ($num > 0) 
	{
		while($row = mysql_fetch_object($result))
		{
			$userid = $row -> userid;
			$accesspoint = $row -> accesspoint;
			$lang1 = $row -> lang1;
			$lang2 = $row -> lang2;
			$lang3 = $row -> lang3;
			session_start();
			session_register('userid','$userid');
			$HTTP_SESSION_VARSї"userid"] = $userid;
			header("location:test.php?");
			exit;
here is code of test.php
there is no problem with the above code means its not giving any error
but on the other hand when it moves to test.php it did not works
any help plz.
i also want to know tht method i used to register session is ok or not if not wots correct one?

Code: Select all

---------------------------test.php----------------------------------------------
<?

	if(!session_is_registered('userid'))
	&#123;
		echo "i am here";exit;
		header("location:default.php?log=false");
		exit;
	&#125;
	echo "I am here000000!";
	exit;
?>
------------------------------------------------------------------------
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

If it was me, i would have done these script like this

Code: Select all

session_start(); 
$query= ("SELECT userid,clientid,accesspoint,lang1,lang2,lang3 FROM users where login = '$username' and password = '$password' and clientid=$company"); 
   $result= mysql_query($query); 

   if (!$result) 
   &#123; 
       echo mysql_error(); 
       exit(); 
   &#125; 

   $num = mysql_num_rows($result); 
   if ($num > 0) 
   &#123; 
      while($row = mysql_fetch_object($result)) 
      &#123; 
         $userid = $row -> userid; 
         $accesspoint = $row -> accesspoint; 
         $lang1 = $row -> lang1; 
         $lang2 = $row -> lang2; 
         $lang3 = $row -> lang3; 
 
         $_SESSION&#1111;'userid'] = $userid; 
         header("location:test.php?"); 
         exit;


Code: Select all

---------------------------test.php---------------------------------------------- 
<? 

   session_start();

   if(!empty($_SESSION&#1111;'userid')) 
   &#123; 
      echo "i am here";exit; 
      header("location:default.php?log=false"); 
      exit; 
   &#125; 
   echo "I am here000000!"; 
   exit; 
?> 
------------------------------------------------------------------------
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mixing session_register and $_SESSION is not the greatest idea. Nor is programming with register globals on.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

feyd wrote:mixing session_register and $_SESSION is not the greatest idea. Nor is programming with register globals on.
Was that a me or the original poster?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

to itsmani, sorry. :)
Post Reply