Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems creating cookies

Status
Not open for further replies.

Chucklez

Programmer
Jul 25, 2002
104
US
I am attempting to create 2 cookies in php, but I keep having problems.

Here is where I send the information out to create the cookie:
Code:
redir("[URL unfurl="true"]http://*****cat-ox.com/BMW/includes/setcookie.php?name=$USERNAME&group=$MEMBERLEVEL","Just[/URL] a moment while you are redirected to the BMW Toolbox.");

Here is the coding for the redir() function:
Code:
function redir($target,$msg) {
global $background,$font_face,$title_color;
?>
<head>
	<link rel="stylesheet" type="text/css" href="[URL unfurl="true"]http://www.*****cat-ox.com/BMW/battleboards/css/BMW.css"[/URL] />
   <meta http-equiv="refresh" content="1; url=<?=$target?>">
</head>
<body>
	<center>
		<table width="451" height "1500" cellpadding="0" cellspacing="0" border ="0" id="header">
			<tr>
				<td width="451" height="243">
					<center>
						<h1 style="font-family:vivaldi;font-size:300%">Beta's Most Wanted</h1> 
					</center>
				</td>
			</tr>
		</table>
      <h3>
	      <?=$msg?>
      </h3>
	   <br>
      Please wait...	
 	</center>
</body>
<?
exit;
}
?>

and here is the code of the setcookie.php file:
Code:
<?
<?
   $UNAME=$name;
   $ULEVEL=$group;

   setcookie("BMWmember", $UNAME, time()+36000, "/");
   setcookie("BMWmemberlvl", $ULEVEL, time()+36000, "/");
   header("Location: [URL unfurl="true"]http://www.*****cat-ox.com/BMW/battleboards/");[/URL]   
exit;
?>

$USERNAME and $MEMBERLEVEL ARE filled with the correct info before being sent to the setcookie.php file. I even see the information in the URL, but for some reason, the cookies are not being set, before the page is redirected.

What am I doing wrong? I have used this exact same process in the past for other sites, but I just cant figure this one out.
 
i have found this to be a problem before. the issue seems to be that the browser doesn't like keeping the cookies and redirecting through the header.

i think this should work but haven't been able to make it so! the workaround is to use the html refresh (with a suitably low transit time) instead of redirecting through the header.

 
Chucklez:
Are you running PHP under a IIS webserver?

If so, IIS is the source of your problem. Microsoft has a unique interpretation of the RFC that defines HTTP. If you send a "Location" header, the return value of the entire HTTP exchange is supposed to change. And Microsoft has decided that when that status changes, cookies are not to be sent. IIS will actually strip them out.

If you're running under IIS, try prepending "nph-" to the name of the script. IIS lets "No Parse Headers" files do what they need to with HTTP headers.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Found the solution to the problem.
Code:
<?
   $UNAME=$_GET['name'];
   $ULEVEL=$_GET['group'];
   setcookie("BMWmember", $UNAME, time()+36000, "/");
   setcookie("BMWmemberlvl", $ULEVEL, time()+36000, "/");
   header("Location: [URL unfurl="true"]http://www.pussycat-ox.com/BMW/battleboards/");[/URL]

exit;
?>

Changed it to 'GET' and it worked fine. Like I said, it worked for every one of the other pages I have made, but this is running on a different server, so perhaps the IIS is the problem. I havent yet checked but will when I return to work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top