For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > June 2004 > RE: [PHP-DB] [PHP]: session problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author RE: [PHP-DB] [PHP]: session problem
Mike Ford

2004-06-25, 3:55 pm

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 g, 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@leedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com