Page 1 of 1

desperate php script help needed

Posted: Thu Jun 29, 2006 2:33 am
by ppc
I have a script that checks the persons ip address, if its "banned" they see a banned message but if its not they see an email form, they enter there email address and click submit and then they are sent to a webpage and a cookie is created. I would then get an email containing the persons email adddress and ip address. This worked fine on a shared hosting plan i had. I had to switch to a VPS plan and now all of a sudden the script stopped working. The person puts there email address in and goes to that page and i get an email but the email it sends to me is missing all of the persons info.

I have tried desperatly to find a solution but cant. Would there be some php setting or something else that is preventing this from working on the VPS.

The script is below:

Code: Select all

<?php include ("ipban.php"); ?>
<?php
session_start();
$ip = $REMOTE_ADDR;
$recipient="myemail@myemail.com";
$subject="A email form for a survey has been submited";
$msg="E-Mail Address: $email IP: $ip OptIn: $opt";
$email = $_POST["email"];

if(array_key_exists($ip,$iplook)){
print 'IP BANNED';
}

if((!ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.
              '@'.
              '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
              '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $email)) 
                && (! array_key_exists($ip,$iplook)) 
                    && (! isset($_SESSION['email'])))              
                
{
print "<center>
Please enter a valid e-mail address to continue: <p>
<form action=\"$SERVER[self_php]\" method=\"post\">
Email: <input name=\"email\" type=\"test\" size=\"20\" maxlength=\"100\"><p>
checkbox<input type=\"checkbox\" name=\"opt\" CHECKED>
<p>&nbsp;</p>
<b></b><p></p><input name=\"Submit\" type=\"submit\" value=\"Submit\"><p>&nbsp;</p></center>";
}

if((ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.
              '@'.
              '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
              '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $email)) 
                && (! array_key_exists($ip,$iplook)) 
                    && (! isset($_SESSION['email']))){
if(mail($recipient, $subject, $msg)){

$_SESSION['email'][] = array('email' => $email);
$email=null;}}


if(isset($_SESSION['email'])){
$site = file_get_contents('http://www.google.com');
print "$site";
}


?>
here is the ip ban file(this file is where i put the banned ip addresses):

Code: Select all

<?php
$iplook['68.239.139.166'] = '68.239.139.166';
?>
any help is greatly appreciated.

Thanks so much

ppc :?: :?:

Posted: Thu Jun 29, 2006 3:57 am
by bmcewan
Hi,

You have an error in one of your form fields.

Code: Select all

type=\"test\"
it should be

Code: Select all

type=\"text\"
here

Code: Select all

Email: <input name=\"email\" type=\"test\" size=\"20\" maxlength=\"100\">

Posted: Thu Jun 29, 2006 4:10 am
by bmcewan
Also, another error...

Code: Select all

<form action=\"$SERVER[self_php]\" method=\"post\">
should be

Code: Select all

<form action=\"".$_SERVER['php_self']."\" method=\"post\">
Additionally, this line relies on register globals

Code: Select all

$msg="E-Mail Address: $email IP: $ip OptIn: $opt";
and appears before this line

Code: Select all

$email = $_POST["email"];
This section should look like

Code: Select all

$opt = $_POST["opt"];
$email = $_POST["email"];
$msg="E-Mail Address: $email IP: $ip OptIn: $opt";
Hope this helps.

Posted: Thu Jun 29, 2006 4:34 am
by Jenk
Holy security holes batman!

Firstly, $SERVER should be $_SERVER :)

Then note that $_SERVER['PHP_SELF'] can be tainted! I believe $_SERVER['SCRIPT_NAME'] would be better, but it too could be tainted.. probably best to just hard-write the address instead of assign a dynamic value to it, when it's not likely to be dynamic.

Onto email:

You so, so need to be careful when using user data for sending emails. Spammers paradise is a website that does not check thoroughly for unwanted email headers in their user created emails.

There are many discussions about emails on these forums (if they haven't vanished since I last looked)

:)