NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP Question

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-28-2007, 10:15 AM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: Feb 2006
Posts: 97
rkahn144 is on a distinguished road
 



PHP Question


Hey folks -

I have a contact form setup at www.mydomain.com/contact.html .

After someone enters there info, /mail.php processes it and they are then returned to my homepage.

An issue I am having is that people (or bots) are going to /mail.php directly which causes me to have a blank contact form sent to me.

Is there a way to restrict individuals from going directly to /mail.php or to prevent the blank contact forms from being sent to me?

Any suggestions will be appreciated. Thanks!
rkahn144 is offline  
Old 05-28-2007, 10:20 AM   #2 (permalink)
NamePros Regular
 
monaco's Avatar
Join Date: Jul 2005
Location: Tucson, AZ
Posts: 689
monaco will become famous soon enough
 



You could use mod_rewrite to check the referrer and handle it at the httpd level

OR

You could use PHP's $_SERVER['HTTP_REFERER'] property to just not submit the form.
__________________
My Website | My Blog
monaco is offline  
Old 05-28-2007, 10:33 AM   #3 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
You could check if there is anything in the message variable. Post the code of mail.php and someone can edit it for you.
Dan is offline  
Old 05-28-2007, 10:39 AM   #4 (permalink)
NamePros Regular
 
monaco's Avatar
Join Date: Jul 2005
Location: Tucson, AZ
Posts: 689
monaco will become famous soon enough
 



Originally Posted by Dan
You could check if there is anything in the message variable. Post the code of mail.php and someone can edit it for you.
He mentioned bots might be doing it. I proposed my solution because it could help him avoid getting spammed when the spam crawler bots decide to shove it full of advertisements.
????: NamePros.com http://www.namepros.com/programming/332883-php-question.html

But yea, post the code, all of the techniques mentioned are simple < 2 minute edits.
__________________
My Website | My Blog
monaco is offline  
Old 05-28-2007, 10:56 AM   #5 (permalink)
NamePros Member
 
Wildhoney's Avatar
Join Date: Sep 2006
Posts: 78
Wildhoney is an unknown quantity at this point
 



Alternatively you could use an image verification such as Captcha. This will typically prevent bots from bypassing the form without entering the correct code. It need not be anything complex as the only sites that have to worry about their complexity would be such sites like Gmail, who would be a prime target for people trying to decipher their verification image.
Wildhoney is offline  
Old 05-28-2007, 10:59 AM   #6 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold
 




You could just use this:
PHP Code:
//Put this immediatly after the <?php tag
if(!isset($_POST['variable_name']) || empty($_POST['variable_name'])){
     
header('Location: http://www.domain.com/page.php');
????: NamePros.com http://www.namepros.com/showthread.php?t=332883
}
Barrucadu is offline  
Old 05-28-2007, 11:35 AM THREAD STARTER               #7 (permalink)
NamePros Member
Join Date: Feb 2006
Posts: 97
rkahn144 is on a distinguished road
 



Mikor or anybody else...if you could mod this and make the code that you add in bold so I can see it, that would be appreciated.

<?
????: NamePros.com http://www.namepros.com/showthread.php?t=332883
$company_name = $_REQUEST['company_name'] ;
$first_name = $_REQUEST['first_name'] ;
$last_name = $_REQUEST['last_name'] ;
$title = $_REQUEST['title'] ;
$address = $_REQUEST['address'] ;
$city = $_REQUEST['city'] ;
$state = $_REQUEST['state'] ;
$zip = $_REQUEST['zip'] ;
$phone = $_REQUEST['phone'] ;
$email = $_REQUEST['email'] ;
$hearaboutus = $_REQUEST['hearaboutus'] ;
$number_of_employee = $_REQUEST['number_of_employee'] ;
$industry = $_REQUEST['industry'] ;
$description = $_REQUEST['description'] ;
mail("NAME@NAME.com","Contact Request"," Contact name: $company_name\n First Name: $first_name\n Last Name: $last_name\n Title: $title\n Address: $address\n City: $city\n State: $state\n Zip: $zip\n Country: $country\n Phone: $phone\n Email: $email\n Hear about us: $hearaboutus\n Number of Employees: $number_of_employee\n Industry: $industry\n Comments: $description");
?>
<script>
<!--
window.location= "/home.html"
//-->
</script>
<?php
exit;?>
rkahn144 is offline  
Old 05-28-2007, 11:41 AM   #8 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold
 




PHP Code:
<?php
//The script will ONLY send the email if all the values are sent, and none of them are empty

if(isset($_REQUEST['company_name'])&&!empty($_REQUEST['company_name'])&&
isset(
$_REQUEST['first_name'])&&!empty($_REQUEST['first_name'])&&
isset(
$_REQUEST['last_name'])&&!empty($_REQUEST['last_name'])&&
isset(
$_REQUEST['title'])&&!empty($_REQUEST['title'])&&
isset(
$_REQUEST['address'])&&!empty($_REQUEST['address'])&&
isset(
$_REQUEST['city'])&&!empty($_REQUEST['city'])&&
isset(
$_REQUEST['state'])&&!empty($_REQUEST['state'])&&
isset(
$_REQUEST['zip'])&&!empty($_REQUEST['zip'])&&
isset(
$_REQUEST['phone'])&&!empty($_REQUEST['phone'])&&
isset(
$_REQUEST['email'])&&!empty($_REQUEST['email'])&&
isset(
$_REQUEST['hearaboutus'])&&!empty($_REQUEST['hearaboutus'])&&
isset(
$_REQUEST['number_of_employee'])&&!empty($_REQUEST['number_of_employee'])&&
isset(
$_REQUEST['industry'])&&!empty($_REQUEST['industry'])&&
isset(
$_REQUEST['description'])&&!empty($_REQUEST['description'])){
     
$company_name $_REQUEST['company_name'];
????: NamePros.com http://www.namepros.com/showthread.php?t=332883
     
$first_name $_REQUEST['first_name'];
     
$last_name $_REQUEST['last_name'];
     
$title $_REQUEST['title'];
     
$address $_REQUEST['address'];
     
$city $_REQUEST['city'];
     
$state $_REQUEST['state'];
     
$zip $_REQUEST['zip'];
     
$phone $_REQUEST['phone'];
     
$email $_REQUEST['email'];
     
$hearaboutus $_REQUEST['hearaboutus'];
     
$number_of_employee $_REQUEST['number_of_employee'];
     
$industry $_REQUEST['industry'];
     
$description $_REQUEST['description'];
????: NamePros.com http://www.namepros.com/showthread.php?t=332883
     
mail("NAME@NAME.com","Contact Request"," Contact name: $company_name\n First Name: $first_name\n Last Name: $last_name\n Title: $title\n Address: $address\n City: $city\n State: $state\n Zip: $zip\n Country: $country\n Phone: $phone\n Email: $email\n Hear about us: $hearaboutus\n Number of Employees: $number_of_employee\n Industry: $industry\n Comments: $description");
}

header('Location: home.php');
?>
Barrucadu is offline  
Old 05-28-2007, 01:14 PM THREAD STARTER               #9 (permalink)
NamePros Member
Join Date: Feb 2006
Posts: 97
rkahn144 is on a distinguished road
 



Mikor - thanks for the post.

The fields that we require in the HTML contact form are:
company_name
first_name
last_name
address
city
state
phone
email

Is there a way that the php form that you posted could be modded for this?
rkahn144 is offline  
Old 05-28-2007, 03:04 PM   #10 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold
 




Done

PHP Code:
<?php 
//The script will ONLY send the email if all the values are sent, and none of them are empty 

if(isset($_REQUEST['company_name'])&&!empty($_REQUEST['company_name'])&& 
isset(
$_REQUEST['first_name'])&&!empty($_REQUEST['first_name'])&& 
isset(
$_REQUEST['last_name'])&&!empty($_REQUEST['last_name'])&& 
isset(
$_REQUEST['address'])&&!empty($_REQUEST['address'])&& 
isset(
$_REQUEST['city'])&&!empty($_REQUEST['city'])&& 
isset(
$_REQUEST['state'])&&!empty($_REQUEST['state'])&& 
????: NamePros.com http://www.namepros.com/showthread.php?t=332883
isset(
$_REQUEST['phone'])&&!empty($_REQUEST['phone'])&& 
isset(
$_REQUEST['email'])&&!empty($_REQUEST['email'])){ 
     
$company_name $_REQUEST['company_name']; 
     
$first_name $_REQUEST['first_name']; 
     
$last_name $_REQUEST['last_name']; 
     
$title $_REQUEST['title']; 
????: NamePros.com http://www.namepros.com/showthread.php?t=332883
     
$address $_REQUEST['address']; 
     
$city $_REQUEST['city']; 
     
$state $_REQUEST['state']; 
     
$zip $_REQUEST['zip']; 
     
$phone $_REQUEST['phone']; 
     
$email $_REQUEST['email']; 
     
$hearaboutus $_REQUEST['hearaboutus']; 
     
$number_of_employee $_REQUEST['number_of_employee']; 
     
$industry $_REQUEST['industry']; 
     
$description $_REQUEST['description']; 
     
mail("NAME@NAME.com","Contact Request"," Contact name: $company_name\n First Name: $first_name\n Last Name: $last_name\n Title: $title\n Address: $address\n City: $city\n State: $state\n Zip: $zip\n Country: $country\n Phone: $phone\n Email: $email\n Hear about us: $hearaboutus\n Number of Employees: $number_of_employee\n Industry: $industry\n Comments: $description"); 


header('Location: home.php'); 
?>
Barrucadu is offline  
Old 05-28-2007, 03:32 PM   #11 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
1.) Do not use $_REQUEST, use the proper $_POST or $_GET
2.) Here's another way:

PHP Code:
<?php

// Array of field name => required (true or false)
$fields = array(
    
'company_name'       => true,
    
'first_name'         => true,
    
'last_name'          => true,
????: NamePros.com http://www.namepros.com/showthread.php?t=332883
    
'address'            => true,
    
'city'               => true,
    
'state'              => true,
    
'phone'              => true,
    
'email'              => true,
    
'zip'                => false,
    
'country'            => false,
    
'hearaboutus'        => false,
    
'number_of_employee' => false,
    
'industry'           => false,
    
'description'        => false
);

$empty = array();

foreach (
$fields AS $field => $required)
{
    if ((
$required) AND (!isset($_POST[$field]) OR empty($_POST[$field]))
    {
        
$empty[$field] = 1;
    }
}

//The script will ONLY send the email if all the values are sent, and none of them are empty 
if(count($empty) == 0)
{
    foreach (
$fields AS $field => $required)
????: NamePros.com http://www.namepros.com/showthread.php?t=332883
    {
        $
$field trim(stripslashes(strip_tags($_POST[$field])));
    }

    
mail("NAME@NAME.com","Contact Request"," Contact name: $company_name\n First Name: $first_name\n Last Name: $last_name\n Title: $title\n Address: $address\n City: $city\n State: $state\n Zip: $zip\n Country: $country\n Phone: $phone\n Email: $email\n Hear about us: $hearaboutus\n Number of Employees: $number_of_employee\n Industry: $industry\n Comments: $description");
}

header('Location: home.php');
exit;

?>
Eric is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 12:04 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger