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
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.

Link to comment
Share on other sites

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();
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.