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");