Jump to content

Recommended Posts

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

[code]<?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(); }
?>[/code]
Also if i echo $num12; i get a value of 1 so it should be creating the cookie.

Any ideas?
Link to comment
https://forums.phpfreaks.com/topic/15834-cookies-issue/
Share on other sites

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!
Link to comment
https://forums.phpfreaks.com/topic/15834-cookies-issue/#findComment-64834
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/15834-cookies-issue/#findComment-64856
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.