Jump to content

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

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.