PDA

View Full Version : [PHP] ip ban and exit(); help.



Tylenol
13-09-2009, 03:45 PM
Hey people, I have a contact form that I put ip ban into. I am using this:

$deny = array("111.111.111.111", "222.222.222.222");

if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
echo 'You have being banned from the form..';
exit();
}It works, it's just I am putting the form into my page using <?php include("contact.php"); ?> and when it reaches exit(); the rest of the site fails to load. Is there anyway to have it so when kills the code using exit(); that it will continue to lead the rest of the site without putting the contact form in an iframe. Like, having it just end the php code when it reaches exit(); something like this:
if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
echo 'You have being banned from the form..';
exit(echo '?>');
}I know that won't work, but it's just an idea. Like I want the script to think it's done if they are banned, instead of it completely killing it, and the website. I don't know php very well, so bare with me.

Here is the entire code, it was coded by my friend, and not by me. He is offline, or I would be asking him for the answer:

<?php

$contact_email = 'MY EMAIL';
$ip = $_SERVER['REMOTE_ADDR'];
$reasons = array(0 => 'Please select a reason..', 1 => 'General', 2 => 'Job', 3 => 'Report a Bug');
$thanks_message = 'Thanks for contacting us. :) We\'ll get back to you ASAP!<br><br><a href="javascript:history.back(1)" title="Go back!">Go back.</a>';
$deny = array("111.111.111.111", "222.222.222.222");
$error = false;

if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
echo 'You have being banned from the form..';
exit();
}

if (isset($_POST['submit'])) {
if ($_POST['contact-habbo-name'] == '') {
echo 'Please enter a Habbo name..<br /><br />';
$error = true;
}

if ($_POST['contact-reason'] == 0) {
echo 'Please select a reason..<br /><br />';
$error = true;
}

if ($_POST['contact-email'] == '') {
echo 'Please enter an e-mail; this is how we contact you!<br /><br />';
$error = true;
}

if ($_POST['contact-message'] == '') {
echo 'Please enter some contact message of some sort.<br /><br />';
$error = true;
}

if ($error === true) {
echo '<a href="javascript:history.back(1)" title="Go back!">Go back.</a>';
} else {
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: ' . stripslashes($_POST['contact-email']) . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = 'Habbo: ' . stripslashes($_POST['contact-habbo-name']) . "\r\n" .
'Reason: ' . $reasons[addslashes($_POST['contact-reason'])] . "\r\n" .
'E-mail: ' . stripslashes($_POST['contact-email']) . "\r\n" .
'IP: ' . $ip . "\r\n \r\n" .
'Message: ' . stripslashes($_POST['contact-message']);
mail($contact_email, 'uHabbo Contact Form: ' . $reasons[addslashes($_POST['contact-reason'])], $message, $headers);
echo $thanks_message;
}
} else {
echo '<form action="./?module=contact" method="post">
Habbo name:<br />
<input name="contact-habbo-name" id="contact-habbo-name" type="text" class="contact_form" />
<br><br>
Contact E-Mail: (You must enter a valid email, as this is how we will be replying to you)<br />
<input name="contact-email" id="contact-email" type="text" class="contact_form" />
<br><br>
Contact reason:<br />
<select name="contact-reason" id="contact-reason" class="contact_form">';
foreach ($reasons as $key => $reason) {
echo '<option value="' . $key . '"'; if ($key==0){ echo ' selected="selected"'; } echo'>' . $reason . '</option>';
}
echo '</select>
<br><br>
Message:
<textarea name="contact-message" id="contact-message" class="contact_form">Please enter a message. &lt;3</textarea>
<br><br>
<input name="submit" type="submit" id="submit" value="Send!" />
</form>';
}
?>Thanks for the help, +rep to any good attempts to help :)

Tylenol
13-09-2009, 04:47 PM
Solved, close thread.

Want to hide these adverts? Register an account for free!