bsamson Posted July 16, 2008 Share Posted July 16, 2008 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! Quote Link to comment Share on other sites More sharing options...
revraz Posted July 16, 2008 Share Posted July 16, 2008 <?php echo "Hello" .$_COOKIE['sns_fname']; ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted July 16, 2008 Share Posted July 16, 2008 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); Quote Link to comment Share on other sites More sharing options...
bsamson Posted July 16, 2008 Author Share Posted July 16, 2008 I know the values load on the Login.php page though. What would you recommend I do to test it? p.s.: Thanks for all your help in the past! Quote Link to comment Share on other sites More sharing options...
revraz Posted July 16, 2008 Share Posted July 16, 2008 Change header("Location: http://mydomain.com/front.php"); to header("Location: front.php"); You are probably setting the cookie on www.mydomain.com and then you redirect to mydomain.com. Use Relative paths, not absolute. Quote Link to comment Share on other sites More sharing options...
bsamson Posted July 16, 2008 Author Share Posted July 16, 2008 Thanks ... but is it a subdomain that is referenced via: http://sub.mydomain.com/ and cant be referenced the other way (such as http://www.sub.mydomain.com/) Quote Link to comment Share on other sites More sharing options...
revraz Posted July 16, 2008 Share Posted July 16, 2008 Then you need to set your cookie to allow for sub domains. Quote Link to comment Share on other sites More sharing options...
discomatt Posted July 16, 2008 Share Posted July 16, 2008 setcookie( 'name', 'value', time()+3600, '/', '.mydomain.com' ); Quote Link to comment Share on other sites More sharing options...
bsamson Posted July 16, 2008 Author Share Posted July 16, 2008 Awesome! Works, thanks for all your help! Quote Link to comment 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.