Jump to content

Way to prevent page from showing if....


jacko310592

Recommended Posts

hey guys

 

i have a 'sent message' php page which my 'contact' page redirects to once someone has sent me a message, is there a way that if someone was to just type my sent message page into the url (if they where to manually load the sent message page) can it be made to automatically redirect to the contact page?

 

(if they send a messgae via the contact page, it shows the sent message page,

but if they try to open the sent message page them selves it redirects away)

 

 

i hope ive manage to explain this properly

 

thanks guys

Link to comment
https://forums.phpfreaks.com/topic/182934-way-to-prevent-page-from-showing-if/
Share on other sites

Well, you could do something like:

 

(for your sent-message page)

<?php
if(isset($_POST['submit'])){
    //Send the message
}
header('Location: index.php') and exit;
?>

 

You can redirect to any page, it doesn't have to be index.php.

 

Edit: This is assuming you have .php file to process your form and another .php or .html file to display the form.

try the full path instead:

 

<?php
if ($_SERVER['HTTP_REFERER'] != "http://www.yoursite.com/full/path/to/process.php" ){ //full path here;
header('Location: ./form.php');
}
?>

 

EDIT: had the lines mixed up.

 

EDIT2: always exit() your header() redirections:

 

<?php
if ($_SERVER['HTTP_REFERER'] != "http://www.yoursite.com/full/path/to/process.php" ){ //full path here;
     header('Location: ./form.php');
     exit (0); //or exit; or exit();
}
?>

i never use http_referer .. doesn't appear to set (at all) when a header() redirect is used.  just did a little test myself.

 

your best bet is to lose the redirect and opt for checking if the form was submitted:

 

<?php
if (isset ($_POST['submit'])) { //form was submitted .. run code;
}
else
{ header ('Location ./form.php'); exit (0); }
?>

 

like i said .. i've never use http_referer before, otherwise, i would've been able to help you out earlier.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.