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 Link to comment https://forums.phpfreaks.com/topic/182934-way-to-prevent-page-from-showing-if/ 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. Link to comment https://forums.phpfreaks.com/topic/182934-way-to-prevent-page-from-showing-if/#findComment-965558 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 Link to comment https://forums.phpfreaks.com/topic/182934-way-to-prevent-page-from-showing-if/#findComment-965563 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')? Link to comment https://forums.phpfreaks.com/topic/182934-way-to-prevent-page-from-showing-if/#findComment-965564 Share on other sites More sharing options...
jacko310592 Posted November 25, 2009 Author Share Posted November 25, 2009 that is correct Link to comment https://forums.phpfreaks.com/topic/182934-way-to-prevent-page-from-showing-if/#findComment-965565 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'); } ?> Link to comment https://forums.phpfreaks.com/topic/182934-way-to-prevent-page-from-showing-if/#findComment-965584 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(); } ?> Link to comment https://forums.phpfreaks.com/topic/182934-way-to-prevent-page-from-showing-if/#findComment-965591 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? Link to comment https://forums.phpfreaks.com/topic/182934-way-to-prevent-page-from-showing-if/#findComment-965593 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? Link to comment https://forums.phpfreaks.com/topic/182934-way-to-prevent-page-from-showing-if/#findComment-965596 Share on other sites More sharing options...
jamesxg1 Posted November 25, 2009 Share Posted November 25, 2009 maybe use tokens. Link to comment https://forums.phpfreaks.com/topic/182934-way-to-prevent-page-from-showing-if/#findComment-965598 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 :/ Link to comment https://forums.phpfreaks.com/topic/182934-way-to-prevent-page-from-showing-if/#findComment-965604 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 Link to comment https://forums.phpfreaks.com/topic/182934-way-to-prevent-page-from-showing-if/#findComment-965607 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. Link to comment https://forums.phpfreaks.com/topic/182934-way-to-prevent-page-from-showing-if/#findComment-965610 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 Link to comment https://forums.phpfreaks.com/topic/182934-way-to-prevent-page-from-showing-if/#findComment-965619 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.