Jump to content


Photo

Cookies issue...


  • Please log in to reply
5 replies to this topic

#1 oMIKEo

oMIKEo
  • Members
  • PipPip
  • Member
  • 19 posts
  • LocationLeeds, UK

Posted 27 July 2006 - 08:40 PM

Hi,

Can anyone tell me why this code isnt working, the login script creates a cookie, then redirects you to a profile page, that page first checks to see if the cookie exists otherwise kicks you to a login page.

I added print_r($_COOKIE); onto the profile page to see what cookies are being passed to that page, it comes back with none :S

<?php
include "config.php";

if( (!$username) or (!$password) )
{ header("Location:$HTTP_REFERER"); exit(); }

$conn=@mysql_connect("$db_host","$db_username","$db_password") or die("Could not connect");
$rs = @mysql_select_db($db_main,$conn) or die("Could not select database");

$sql="select * from bn_profile where band_email=\"$username\" and password=\"$password\"";
$rs=mysql_query($sql,$conn) or die("Could not execute query" . mysql_error());
$num12 = mysql_num_rows($rs);
if($num12!=0)
{ 
setcookie("UN", $username, time()+3600, "/", ".breakingtuneshosting.com", 0);
header("Location:profile.php"); exit(); 
}
else
{ header("Location:$HTTP_REFERER"); exit(); }
?>
Also if i echo $num12; i get a value of 1 so it should be creating the cookie.

Any ideas?

#2 realjumper

realjumper
  • Members
  • PipPipPip
  • Advanced Member
  • 399 posts

Posted 27 July 2006 - 09:07 PM

$sql="select * from bn_profile where band_email=\"$username\" and password=\"$password\"";

Doesn't look right to me...shouldn't it be....

$sql="select * from bn_profile where band_email=$username and password=$password";


#3 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 27 July 2006 - 09:12 PM

No it shouldn't - you must surround string values with quotes, although most people probably use single ones.

I would suggest first trying the call to setcookie with only the first three parameters.

Or could it be that as you are doing a redirect straight away, there is no opportunity for the browser to send the cookie? Someone will be along in a minute who knows more than me about such things!
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#4 realjumper

realjumper
  • Members
  • PipPipPip
  • Advanced Member
  • 399 posts

Posted 27 July 2006 - 09:15 PM

Okay, sorry if I missled with my comment...I have never done it with double quotes and a backslash...as you say, single quotes is the norm, which I omitted to add

#5 oMIKEo

oMIKEo
  • Members
  • PipPip
  • Member
  • 19 posts
  • LocationLeeds, UK

Posted 27 July 2006 - 10:01 PM

Thanks guys,

Ive tried using just: setcookie("UN", $username, time()+3600);
but that didnt help (if thats what you meant)

The thing is ive used this exact script on a number of other hosting providers and its worked fine which is why im so confused and really need some help.... thanks

#6 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 28 July 2006 - 10:27 AM

Ok, have you set your browser's security settings to notify you when it recieves a cookie? Then at least you can tell if it's a problem writing the cookie or reading it back.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users