brob Posted July 24, 2006 Share Posted July 24, 2006 hi here is my code[code]import_request_variables("gP","");$md5pass = md5($password);include('db_stu_connect.php');$getusername = mysql_query("select email1,passw_c from contacts_cstm,contacts where contacts.id = contacts_cstm.id_c and email1 = '$username' and contacts_cstm.passw_c = '$md5pass'");$gotusername = mysql_fetch_row($getusername);if ($gotusername[0] != ""){$username = $gotusername[0];setcookie ("dbghstudent", "$username",0,"/");?><script language="JavaScript">parent.location='http://www.site.net/other_pages/test.php';</script><?php}else{[/code]and for some reason it isn't setting the cookie can anyone see a reason for this?Thanks Link to comment https://forums.phpfreaks.com/topic/15482-setcookie-problem/ Share on other sites More sharing options...
Joe Haley Posted July 24, 2006 Share Posted July 24, 2006 0 as a timestamp is equil to January 1 1970 00:00:00 GMTSo setting a cookie that expired isnt going to have the result you want ;)http://php.net/manual/en/function.time.php Link to comment https://forums.phpfreaks.com/topic/15482-setcookie-problem/#findComment-62796 Share on other sites More sharing options...
brob Posted July 24, 2006 Author Share Posted July 24, 2006 hi thanks for the reply,It still doesn't seem to work even though I have set the time for an hour ahead i.e.[code]setcookie ("dbghstudent", "$username",time()+36000,"/");[/code]any ideas why this is?For some reason its just not setting the cookie. Link to comment https://forums.phpfreaks.com/topic/15482-setcookie-problem/#findComment-62840 Share on other sites More sharing options...
Joe Haley Posted July 24, 2006 Share Posted July 24, 2006 are cookies enabled in your browser?is the value of $username false? Link to comment https://forums.phpfreaks.com/topic/15482-setcookie-problem/#findComment-62844 Share on other sites More sharing options...
brob Posted July 24, 2006 Author Share Posted July 24, 2006 hi this is the code in full[code]<?phpimport_request_variables("gP","");$md5pass = md5($password);include('db_stu_connect.php');$getusername = mysql_query("select email1,passw_c from contacts_cstm,contacts where contacts.id = contacts_cstm.id_c and email1 = '$username' and contacts_cstm.passw_c = '$md5pass'");$gotusername = mysql_fetch_row($getusername);if ($gotusername[0] != ""){$username = $gotusername[0];setcookie ("dbghstudent", "$username",time()+36000,"/");?><script language="JavaScript">parent.location='http://www.site.net/other_pages/test.php';</script><?php}else{?>sorry invalid login<? if ($gotusername[0] == "") { echo '<p><font color="#FF0000">Invalid username and/or password. Please try again.</font></p>'; } ?> [/code]I have used this system on another site and it worked but for this site it seems to fail Link to comment https://forums.phpfreaks.com/topic/15482-setcookie-problem/#findComment-62845 Share on other sites More sharing options...
crashmaster Posted July 24, 2006 Share Posted July 24, 2006 Problem can be, if this code isnt in HEADER>... Setting COOKIE has to be done BEFORE ANY HTML CODE.. Link to comment https://forums.phpfreaks.com/topic/15482-setcookie-problem/#findComment-62870 Share on other sites More sharing options...
brob Posted July 24, 2006 Author Share Posted July 24, 2006 yeah the cookie is set before any HTML is declaired Link to comment https://forums.phpfreaks.com/topic/15482-setcookie-problem/#findComment-62881 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.