RE: [PHP]: session problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 24 June 2004 16:44, H. J. Wils wrote:

> this is the code, but this code works on my hosting provider but not
> on my own server. I think i have to change settings in php.ini but
> dont know which...
> first page:
> 
> session_start();
> 
> include "connect.php";
> include "functions.php";
> 
> 	    $user= $_GET["email"];
> 	    $ww = $_GET["ww"];
> 
> 	    $check_user_query = "select id,email, password from user where
> email='$user' and password='$ww'";
> 	    $check_user_res = mysql_query($check_user_query) or
> die(mysql_error().": $check_user_query");
> 
> 	    if (mysql_num_rows($check_user_res) == 1){
> 		   //user is ingelogd
> 
> 		                 $userdata =
> mysql_fetch_array($check_user_res);
> 	 		 $sid=session_id();
> 		                 $uid=$userdata["id"];
> 			 $_SESSION['logged_in'] = true;
> 			 $_SESSION['sid'] = $sid;
> 			 $_SESSION['user'] = $uid;
> 
> 	 		 $dt = date("Y-m-d H:i:s");
> 
>   	       header("location: user.php?action=0");
> 	    }else{
> 		   header("location: user.php?action=9");
> 		}

Redirecting like this will not pass the session id in the URL if that is
necessary, which it would be if cookies are not being used.  Since you say
it works for you from your provider's system but not your local one, this
suggests that your provider has session.use_cookies turned on, but you have
it turned off.

If this is so, you can solve your immediate problem by turning that option
on in your php.ini, but the redirects will still not work correctly for
anyone who has cookies turned off in their browser.  If you are bothered
about this, you need to make use of the handy-dandy SID constant that PHP
helpfully provides, thusly:

          header("Location: user.php?action=0&".SID);

or, if you're a tidy-URL geek, something like:

          header("Location: user.php?action=0".(SID?"&".SID:""));

(BTW, notice the correct spelling of the "Location" header, with a capital
L; and, yes, others are right when they say it should be a full absolute
URL.  These things have been known to matter to some browsers, so it's best
to make a habit of getting them right!)

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: m.ford@xxxxxxxxxxxxxx
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux