Jump to content

Cookie not saving


sdlyr8

Recommended Posts

I'm working on a login script for a site right now, and am having problems saving cookies. After I save the cookies, later in the script I can access them and they do have the correct data. but one any other pages it doesn't have any knowledge of the cookie even existing! i've been working for way too long on this so maybe just a good night's sleep or a fresh set of eyes would help. But does anyone see a problem with my code?

 

Thanks!

 

<?php

require_once("../db/connect.php");

$uname = $_POST['username'];
$pword = $_POST['password'];

$sql = "SELECT * FROM Users WHERE user_name like '$uname' AND password = MD5('$pword');";
$result = mysql_query($sql);
$array = mysql_fetch_array($result);
$rows = mysql_num_rows($result);


if($rows==0)
        $url="Signin.php?error=1";
else if($array[activated]!=1)
        $url="Welcome.php";
else {
# Username matches password!
session_start();

$_SESSION['uname'] = $uname;
$_SESSION['id']    = $array[user_id];
$_SESSION['name']  = $array[first_name];

if($_POST['rememberme']=="on") {
        setcookie("uname", $uname, time()+1209600); # 14 days
        setcookie("token", $array[token], time()+1209600);
}
$url="index.php";
}
header("Location: ../$url");

Link to comment
https://forums.phpfreaks.com/topic/143239-cookie-not-saving/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.