jacko310592 Posted November 25, 2009 Share Posted November 25, 2009 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 Quote Link to comment Share on other sites More sharing options...
Goldeneye Posted November 25, 2009 Share Posted November 25, 2009 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. Quote Link to comment Share on other sites More sharing options...
jacko310592 Posted November 25, 2009 Author Share Posted November 25, 2009 thanks for the reply, just tried the code, and it seems to redirect whether its coming from my form or not :/ any ideas? and my setup is: form.php --> process.php --> message_sent.php Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted November 25, 2009 Share Posted November 25, 2009 is process.php redirecting to message_sent.php via header ('Location: message_sent.php')? Quote Link to comment Share on other sites More sharing options...
jacko310592 Posted November 25, 2009 Author Share Posted November 25, 2009 that is correct Quote Link to comment Share on other sites More sharing options...
jacko310592 Posted November 25, 2009 Author Share Posted November 25, 2009 can anyone see a problem with this code? <?php if ($_SERVER['HTTP_REFERER'] != "./process.php" ){ header('Location:./form.php'); } ?> Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted November 25, 2009 Share Posted November 25, 2009 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(); } ?> Quote Link to comment Share on other sites More sharing options...
jacko310592 Posted November 25, 2009 Author Share Posted November 25, 2009 thanks for the reply mrMarcus, but no luck yet :/ anymore ideas? Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted November 25, 2009 Share Posted November 25, 2009 did you change: http://www.yoursite.com/full/path/to/ to match the URL for your site? Quote Link to comment Share on other sites More sharing options...
jamesxg1 Posted November 25, 2009 Share Posted November 25, 2009 maybe use tokens. Quote Link to comment Share on other sites More sharing options...
jacko310592 Posted November 25, 2009 Author Share Posted November 25, 2009 yeah, but its still redirecting no matter what page it comes from :/ Quote Link to comment Share on other sites More sharing options...
jacko310592 Posted November 25, 2009 Author Share Posted November 25, 2009 think ive found the problem even though the form page loads the process page, the process page for some reason doesnt get put down as the referral page so i had to use the form as the referral page Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted November 25, 2009 Share Posted November 25, 2009 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. Quote Link to comment Share on other sites More sharing options...
jacko310592 Posted November 25, 2009 Author Share Posted November 25, 2009 youve been a great help mrMarcus, thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.