Jump to content

Code adding weird %0D%0A


waiwai933

Recommended Posts

Hi,

 

For some reason, my code is attaching

%0D%0A
to one of the cookies it's setting and not the other, which makes it somewhat easier to diagnose, but I can't do it, partially because I've been working with the code for 2 hours and it feels fine. Here's a quick explanation of the code below: $serversecuritycode is fetched from the user , $safeusername is the username submitted through a form and taken through mysql_real_escape_string. When it's setting the cookies, the $serversecuritycode (the securitycode cookie) gets the %0D%0A attached. The username one stays fine.

 

Here's the relevant code:

 

if (!isset($_POST["username"]) || !isset($_POST["password"]))
	{
	$displayform=1;
	}
else
	{
	$safeusername=mysql_real_escape_string($_POST["username"]);
	$safepassword=mysql_real_escape_string($_POST["password"]);
	$serverpassword = mysql_query("SELECT `password` FROM `users` WHERE username = \"{$safeusername}\"");

	$serversecuritycode = mysql_query("SELECT `securitycode` FROM `users` WHERE username = \"{$safeusername}\"");

	if(mysql_num_rows($serversecuritycode)==0)
		{
		$displayincorrect=1;
		}		
	else
		{		
		if($safepassword==mysql_result($serverpassword,0,0))
			{
                                 // *** COOKIE AREA ***
			$serversecuritycode = mysql_result($serversecuritycode,0,0);
			setcookie("securitycode", $serversecuritycode, time()+63072000); /* Expires in 2 years */ 	
			setcookie("username", $safeusername, time()+63072000);		
			$success=1;
			}
		else 
			{
			$displayincorrect=1;
			}
		}
	}

 

Another weird thing: At the part where I put the ***COOKIE AREA***, I used to have the following for debug purposes:

echo ("$serversecuritycode");

For some reason, it never spat out a header error, which it has done before. Can anyone explain why?

 

 

Link to comment
https://forums.phpfreaks.com/topic/158692-code-adding-weird-0d0a/
Share on other sites

Ok, I've done some more fiddling with this, and I think this may be a database problem. It fixes itself when I delete the last character from the database, save, and re-add the last character, saving of course. Is this just a lucky correlation, or should I ask for this to be moved to the MySQL forum?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.