Jump to content

[SOLVED] Saving Data in Cookies ...


bsamson

Recommended Posts

Hello. I am fairly new to cookies. I have basically 3 pages at this point.

 

Login.php

Validate.php

front.php

 

A user goes to the Login page and provides their credentials. The Validate page looks like this:

 

<?php
require_once("common.php"); // Loads ConnectTo Function

$connection = ConnectTo("main");

$query = "SELECT * FROM employees WHERE uName='$_POST[uName]' AND pWord='$_POST[pWord]'";
$result = mysql_query($query);

if (mysql_num_rows($result) == 0) { 
header("Location: http://mydomain.com/Login.php?err=1"); 
} else {

while ($row=mysql_fetch_array($result)) {
setcookie("sns_fname", $row['fname'], time()+3600);
setcookie("sns_lname", $row['lname'], time()+3600);
setcookie("sns_uName", $row['uName'], time()+3600);
setcookie("sns_added", $row['added'], time()+3600);
setcookie("sns_updated", $row['updated'], time()+3600);
setcookie("sns_lastlogin", $row['lastlogin'], time()+3600);
}

header("Location: http://mydomain.com/front.php");
}
?>

 

By the way, if i comment out the header line from Login.php, and put in this line:

<?php echo $_COOKIE['sns_fname']; ?>

It displays the name.

 

if the username & password were found the user ends up @ front.php. Now, on front.php I try this:

<?php echo $_COOKIE['sns_fname']; ?>

 

And it doesn't display the name. Am i missing something obvious? Thanks in advance for any assistance!

Link to comment
Share on other sites

Ok, now that you edited your post, do some simple troubleshooting.  First make sure the cookie value is being set.  Don't use a MYSQL result for it, use something you know works..

 

setcookie("sns_fname", "Fred", time()+3600);

 

Link to comment
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.