Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-26-2007, 12:52 AM   PM User | #1
me2
New Coder

 
Join Date: Oct 2007
Posts: 88
Thanks: 8
Thanked 3 Times in 3 Posts
me2 is an unknown quantity at this point
POSTs only from one site

is there a way to check if post requests only come from the host site or not

i tried this
PHP Code:
if(isset($_POST) && preg_match("/" $_SERVER['SERVER_NAME'] . "/i",$_SERVER['HTTP_REFERER'])){
    
//code to be executed here

and i found out that $_SERVER['HTTP_REFERER'] was not set in my phpinfo thing so that way couldnt work.. ideas or scripts that you use would be appriciated
me2 is offline   Reply With Quote
Old 11-26-2007, 01:13 AM   PM User | #2
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,711
Thanks: 2
Thanked 251 Times in 243 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
The HTTP_REFERER (all the HTTP_xxxxxx) headers are optional, may or may not be set, and can be faked (the popular phproxy web proxy script sets the HTTP_REFERER to be the same as the site being requested so that all requests look like they came from someone already on the site of the page being requested.)

The best you can do is start a session and set a session variable to some known value on the page your form is on and then start/resume the session on your form processing page and check that the session variable exists with the value you expect. This will require that the person (or a script) at least visits the page that your form is on to establish the session.

If you are having a problem with spam content, anything you can do to the form to make sure it is your form submitting to your form processing code can be figured out and bypassed. Your form processing code is the last line of defense. You must also validate all input from the form and detect the spam content or email header injection attempts and discard the submitted data.
__________________
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

Last edited by CFMaBiSmAd; 11-26-2007 at 01:17 AM.. Reason: fixed word
CFMaBiSmAd is offline   Reply With Quote
Old 11-26-2007, 01:48 AM   PM User | #3
me2
New Coder

 
Join Date: Oct 2007
Posts: 88
Thanks: 8
Thanked 3 Times in 3 Posts
me2 is an unknown quantity at this point
i have taken your idea and is using sessions now and it is working great..

i was just wondering y does isset($_POST) always return true even when i dont submit anything
me2 is offline   Reply With Quote
Old 11-26-2007, 02:06 AM   PM User | #4
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,711
Thanks: 2
Thanked 251 Times in 243 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
A form submits an empty $_POST array when nothing is set, but the variable $_POST exists, so isset() is true.

You could use empty() instead, it will detect an empty array.
__________________
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.
CFMaBiSmAd is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:22 PM.


Advertisement
Log in to turn off these ads.