sdlyr8 Posted January 31, 2009 Share Posted January 31, 2009 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"); Quote Link to comment https://forums.phpfreaks.com/topic/143239-cookie-not-saving/ Share on other sites More sharing options...
premiso Posted January 31, 2009 Share Posted January 31, 2009 Try actually using the path and domain parameters of setcookie setcookie("token", $array[token], time()+1209600, "/", ".yourdomain.com"); And see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/143239-cookie-not-saving/#findComment-751300 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.