Jump to content

mysql_real_escape_string Substitue When There is NO DB Connection


nightkarnation

Recommended Posts

Hey Guys...Here is my doubt:

We all know that mysql_real_escape_string only works when the php file connects to a Database.

 

What if I only have a php file that receives variables from a form and then send those variables to an email address.

Working Example:

 

//back up email
if ($action == "backupEmail")
{
	$email=$_POST['email'];
	$date = date("F j, Y");

	//send email
	if( $email == true )
	{
		$sender = $email;
		$receiver = "[email protected];
		$client_ip = $_SERVER['REMOTE_ADDR'];
		$email_body = "Email: $sender \n\nIP: $client_ip \n\nDate: $date";		
		$extra = "From: $sender\r\n" . "Reply-To: $sender \r\n" . "X-Mailer: PHP/" . phpversion();

		//echo "success=yes";

		if( mail( $receiver, "New Email Subscriber - $subject", $email_body, $extra ) ) 
		{
			echo "success=yes";
		}
		else
		{
			echo "success=no";
		}
	}
}

 

 

If I were connected to a database I would:

$email=mysql_real_escape_string($_POST['email']);

 

Any suggestions on what I could do to prevent any querie attack from the email variable coming from form?

 

Thanks in advance!

Cheers,

Why would you think you need to use mysql_real_escape_string() when you don't intend to use the data in a mysql DB query? For email, you need to worry more about header injection and XSS prevention.

Why would you think you need to use mysql_real_escape_string() when you don't intend to use the data in a mysql DB query? For email, you need to worry more about header injection and XSS prevention.

 

hmmm.... nc

 

 

See here... http://uk2.php.net/manual/en/security.database.sql-injection.php

Basically it suggests addslashes() amongst other things...

 

 

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.