PHP Help

Branden

Seasoned Veteran
Joined
Sep 8, 2009
Messages
2,892
Reaction score
0
FP$
6
Code:
<?php
function isInjected($str) {
	$injections = array('(\n+)',
	'(\r+)',
	'(\t+)',
	'(%0A+)',
	'(%0D+)',
	'(%08+)',
	'(%09+)'
	);
	$inject = join('|', $injections);
	$inject = "/$inject/i";
	if(preg_match($inject,$str)) {
		return true;
	}
	else {
		return false;
	}
}

$email_address = $_REQUEST['email_address'] ;
$comments = $_REQUEST['comments'] ;

// Edit with your email.
else {
mail( "[email protected]", "Done",
  $comments, "From: $email_address" );
header( "Location: index.html" );
}
?>

I can not seem to get this to work the correct way. Does anybody know how to make it work?

The error I get is
Code:
Parse error: syntax error, unexpected T_ELSE in /home/branden/public_html/themes/fastfolio/send.php on line 25
 
Code:
<?php
function isInjected($str) {
   $injections = array('(\n+)',
   '(\r+)',
   '(\t+)',
   '(%0A+)',
   '(%0D+)',
   '(%08+)',
   '(%09+)'
   );
   $inject = join('|', $injections);
   $inject = "/$inject/i";
   if(preg_match($inject,$str)) {
      return true;
   }else {
      return false;
   }
}

$email_address = $_REQUEST['email_address'] ;
$comments = $_REQUEST['comments'] ;

// Edit with your email.
} else {
mail( "[email protected]", "Done",
  $comments, "From: $email_address" );
header( "Location: index.html" );
}
?>
 
Code:
Parse error: syntax error, unexpected '}' in /home/branden/public_html/themes/fastfolio/send.php on line 24

It does not seem to be working.
 
I am not sure but I think the problem stems from you not having an "if" statement to go along with the "else"

The previous "if" is already tied to your function, that is why you are getting the expected end of file error.

I am not sure what you are trying to do here. I suggest you create an account over at phpfreaks.com and post your question there. They are sure to be able to help you.
 
Parse error: syntax error, unexpected T_ELSE in /home/branden/public_html/themes/fastfolio/send.php on line 25

That's basically saying that there's an error, there's a T_ELSE but no T_IF (i think it's called t_if 😛 )
 
Thanks to all for the responses. You guys have all helped me.
 
Code:
<?php
function isInjected($str) {
   $injections = array('(\n+)',
   '(\r+)',
   '(\t+)',
   '(%0A+)',
   '(%0D+)',
   '(%08+)',
   '(%09+)'
   );
   $inject = join('|', $injections);
   $inject = "/$inject/i";
   if(preg_match($inject,$str)) {
      return true;
   }
   else {
      return false;
   }
}

if (!isInjected($_REQUEST['email_address']) AND !isInjected($_REQUEST['comments'])){

$email_address = $_REQUEST['email_address'] ;
$comments = $_REQUEST['comments'] ;

// Edit with your email.
mail( "[email protected]", "Done", $comments, "From: $email_address" );
header( "Location: index.html" );
}
else {
die("injected.");
}
?>

That will check if isInjected email and comments are both false, if they are it'll continue to send an email if not kill the page.
 
(keke007 bumped this thread, don't blame me)

But for that code, you need to be using exit, not die... holy herpa derp
 
Back
Top Bottom