Forum Moderators: coopster

Message Too Old, No Replies

$ server['http referer']

         

charger9

3:18 pm on Oct 6, 2008 (gmt 0)

10+ Year Member



I have a php form I only want to be submitted from a specific referring page. From what I can tell I can do something like this:

if ($_SERVER['HTTP_REFERER']="http://www.example.com/example.php") {

send the form }

else {
take them back to www.example.com
}

I have 3 pages.
1) The form page
2) The page that sends the email
3) Thank you page

Where does this code need to go in order to make this work?

cameraman

3:40 pm on Oct 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In 2. You need another equal sign though:
if ($_SERVER['HTTP_REFERER']=="http://www.example.com/example.php") {

charger9

4:30 pm on Oct 6, 2008 (gmt 0)

10+ Year Member



Works great! Thanks!

grallis

7:41 pm on Oct 6, 2008 (gmt 0)

10+ Year Member



Hi charger9 -

$_SERVER['HTTP_REFERER'] is set by the browser, not by PHP. Therefore it can be faked. If you find you're having problems in the future, you're better off setting a few $_SESSION variables using $_SERVER['SCRIPT_FILENAME'] to track which script is being executed, and the last one to be executed. I think that would be more accurate.

cameraman

7:50 pm on Oct 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or you could just set one session variable from the referring page you want, then unset it on form submission once you're happy with the submission (that is, you're not going to kick the visitor back to the page for corrections).

grallis

8:01 pm on Oct 6, 2008 (gmt 0)

10+ Year Member



Leave it to me to over complicate the matter :P