473,378 Members | 1,236 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Why can't I set this cookie?

Hi there,

I'm working on a login script and I am pulling out my hair trying to figure out why I can never seem to get my cookie set I will post my code below and hope someone with a much larger I.Q. can help me figure out my problem/problems.

Expand|Select|Wrap|Line Numbers
  1. <?php include ('../../Connections/login_db.php');?>
  2. <?php 
  3. error_reporting(E_ALL); 
  4.     ini_set("display_errors", true); 
  5.     header("Content-Type: text/plain"); 
  6.  
  7. if(isset($_COOKIE['ID_my_site']))
  8. //if there is, it logs you in and directes you to the members page
  9. { $username = $_COOKIE['ID_my_site'];  
  10. $pass = $_COOKIE['Key_my_site'];
  11. $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
  12. while($info = mysql_fetch_array( $check )) 
  13. {
  14. if ($pass != $info['password']) 
  15. {
  16.     die ('blah');
  17. }
  18. else
  19. {
  20. header ('location:../admin.php');
  21.  
  22. }
  23. }
  24. }
  25. //if the login form is submitted 
  26. if (isset($_POST['submit'])) { // if form has been submitted
  27.  
  28. // makes sure they filled it in
  29. if(!$_POST['username'] | !$_POST['pass']) {
  30. die('You did not fill in a required field.');
  31. }
  32. // checks it against the database
  33.  
  34. if (!get_magic_quotes_gpc()) {
  35. $_POST['email'] = addslashes($_POST['email']);
  36. }
  37. $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());
  38.  
  39. //Gives error if user dosen't exist
  40. $check2 = mysql_num_rows($check);
  41. if ($check2 == 0) {
  42. die('That user does not exist in our database. 
  43. <p><a href=add.php>Click Here to Register</a>');
  44.   }
  45.   while($info = mysql_fetch_array( $check )) 
  46.   {
  47.   $_POST['pass'] = stripslashes($_POST['pass']);
  48.   $info['password'] = stripslashes($info['password']);
  49.   $_POST['pass'] = md5($_POST['pass']);
  50.  
  51.   //gives error if the password is wrong
  52.   if ($_POST['pass'] != $info['password']) {
  53.   die('Incorrect password, please try again.');
  54.   }
  55. else 
  56. // if login is ok then we add a cookie 
  57. setcookie("ID_my_site", ($_POST['username']), time()+60*60*24*30, "/"); 
  58. setcookie("Key_my_site",($_POST['pass']), time()+60*60*24*30, "/");
  59. //**when domain is specified and form is submitted I wind up with a forever loading page and upon refreshing it I wind up with a page cannot be displayed error. 
  60. //then redirect them to the members area 
  61. header("location: ../admin.php");
  62. exit;
  63. else 
  64. // if they are not logged in 
  65. ?>
  66. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  67. <html xmlns="http://www.w3.org/1999/xhtml">
  68. <head>
  69. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  70. <meta name="robots" content="noindex,nofollow"/>
  71. <title>Administrator logon</title>
  72. <link href="../../page.css" rel="stylesheet" type="text/css" />
  73.   </head>
  74. <body>
  75. <div id="container">
  76. <div id="header"><?php include ("../../login_header.php") ?></div>
  77. <div id="photoNav"><?php include ("../../mainNav.php") ?></div>
  78. <div id="tableContent">
  79. <div class="bold_16" style="margin-top:40px">Administrator Login</div>
  80. <div class="padding_top"><div style="padding-top:10px; text-align:center;">
  81.  
  82. </div>
  83.  
  84. <form action="" method="post"> 
  85. <table border="0" align="center"> 
  86. <tr><td colspan=2><div class="bold_14" style="padding-bottom:20px;">Please enter your login information</div></td></tr> 
  87. <tr><td>Username:</td><td> 
  88. <input name="username" type="text" size="23" maxlength="40"> 
  89. </td></tr> 
  90. <tr><td>Password:</td><td> 
  91. <input name="pass" type="password" size="24" maxlength="50"> 
  92. </td></tr> 
  93. <tr><td colspan="2" align="right"> 
  94. <input type="submit" name="submit" value="Login"> 
  95. </td></tr> 
  96. </table> 
  97. </form> 
  98. <?php 
  99.  
  100. ?>   
  101.  
Thank you for all help in advance
Nov 20 '10 #1
0 949

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Shannon Jacobs | last post by:
I'm doing some trivial surveys, and I want to know if the same user answers twice. Can't really know that, but at least I thought I could check for the same browser/computer combination by using a...
5
by: brettr | last post by:
When I reference document.cookie, there is a long string of key=value; pairs listed. I may have 100 hundred cookies on my hard drive. However, most only have one key=value pair. Does the...
4
by: socialism001 | last post by:
I'm trying to store a value in a cookie but its not working. Can anyone see what I might be doing wrong. Thanks, Chris ~~~~~~~~~~~~~~~~~~ <script language="javascript">...
9
by: Marco Krechting | last post by:
Hi All, I have a page with a list of hyperlinks. I want to save information in a cookie about the fact that I entered an hyperlink or not. When I click one of the hyperlinks I want this stored...
1
by: rushik | last post by:
Dear all, We have created a business portal for our organization. The technology used for that is LAMP. Our major access management system of the portal is based on cookies. we set some user...
3
by: Wysiwyg | last post by:
After a server created cookie is processed on the client I want it removed, cleared, or expired in the javascript block but have been unable to do this. If I set a cookie value in the server code...
1
by: CR1 | last post by:
I found a great cookie script below, but don't know how to make it also pass the values sent to the cookie, to a querystring as well for tracking purposes. Can anyone help? If there was a way to...
4
by: gl | last post by:
I'm currently making a web app that stores a user id in a cookie, and builds user information off of that in the differnt pages of the site. The cookie is created on login, and is separate from the...
6
by: kelvlam | last post by:
Hello all, I'm still a bit new with JavaScript, and I hope the guru here can shed some light for me. It's regarding handling cookie and the case-sensitive nature of JavaScript itself. My...
1
by: xhe | last post by:
Hi, I met a technical difficulty and can not overcome. I have 2 windows, let's name it window1 and window2. Now in window1, I need to select an image, so I click the link on window1 to open...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.