Page 1 of 1

problem in session

Posted: Thu Feb 03, 2005 6:52 am
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;
?>
------------------------------------------------------------------------

Posted: Thu Feb 03, 2005 7:58 am
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; 
?> 
------------------------------------------------------------------------

Posted: Thu Feb 03, 2005 10:06 am
by feyd
mixing session_register and $_SESSION is not the greatest idea. Nor is programming with register globals on.

Posted: Thu Feb 03, 2005 10:12 am
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?

Posted: Thu Feb 03, 2005 10:17 am
by feyd
to itsmani, sorry. :)