Jump to content


Photo

setcookie problem


  • Please log in to reply
6 replies to this topic

#1 brob

brob
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 24 July 2006 - 01:03 PM

hi here is my 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
{

and for some reason it isn't setting the cookie can anyone see a reason for this?

Thanks

#2 Joe Haley

Joe Haley
  • Members
  • PipPipPip
  • Advanced Member
  • 103 posts
  • LocationCanada, eh?

Posted 24 July 2006 - 01:09 PM

0 as a timestamp is equil to January 1 1970 00:00:00 GMT

So setting a cookie that expired isnt going to have the result you want ;)

http://php.net/manua...nction.time.php
Give a man a fish; you have fed him for today.  Teach a man to fish; and you have fed him for a lifetime
Don't teach men to program. Teach them to fish.

Please, try the RTFM solution before asking for help:
http://php.net/manual/en/index.php

#3 brob

brob
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 24 July 2006 - 01:57 PM

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.

setcookie ("dbghstudent", "$username",time()+36000,"/");

any ideas why this is?

For some reason its just not setting the cookie.

#4 Joe Haley

Joe Haley
  • Members
  • PipPipPip
  • Advanced Member
  • 103 posts
  • LocationCanada, eh?

Posted 24 July 2006 - 01:59 PM

are cookies enabled in your browser?

is the value of $username false?
Give a man a fish; you have fed him for today.  Teach a man to fish; and you have fed him for a lifetime
Don't teach men to program. Teach them to fish.

Please, try the RTFM solution before asking for help:
http://php.net/manual/en/index.php

#5 brob

brob
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 24 July 2006 - 02:02 PM

hi this is the code in full

<?php
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",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>';
			}
		
?>	

I have used this system on another site and it worked but for this site it seems to fail

#6 crashmaster

crashmaster
  • Members
  • PipPipPip
  • Advanced Member
  • 169 posts
  • LocationCzech Republic, Prague

Posted 24 July 2006 - 02:29 PM

Problem can be, if this code isnt in HEADER>...
Setting COOKIE has to be done BEFORE ANY HTML CODE..
I'll never be the same...

#7 brob

brob
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 24 July 2006 - 02:40 PM

yeah the cookie is set before any HTML is declaired




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users