March 20, 200917 yr i need to be able to redirect back from a page within a site, i've tried doing it with a meta tag <meta http-equiv="refresh" content="7; url=http://www.website.com"> however you have to put a specific url and as people will be coming to this page from multible pages its not suitable so i tried doing it with javascript <a href='#' onclick='history.go(-1);return false;'>RETURN TO PREVIOUS PAGE</a> which works but it doesnt refresh the browser, so the info my users submited is still in the form, this will probably mean people will keep submiting over and over again thinking its not working because they cant see their comments posted i also tried using a meta tag telling the browser not to cache the page, but these dont work on most browsers does anybody know of any other solutions i can use thanks Seth
March 20, 200917 yr I wouldn't use JavaScript for something like that, peroid. Here's the PHP soloution: define('REDIRECT_BACK', 'index.php'); // PAGE AND WHAT NOT. // WHERE YOU WANT THE REDIRECT header('Location: '. REDIRECT_BACK); REDIRECT_BACK can be changed for anything you want. As can index.php, obviously. This is a very good method and the user wouldn't even know they've been redirected. Here's an example of it in action: whotoseelive.com/layout
March 20, 200917 yr Once they've submitted the data you could just show them a message saying 'thank you for your response' or w.e ? I'm not entirely sure what your trying to do, can you do a step by step process? Is it something like Form Submit form Data sent Return to form page Data still there (common sense suggests it's not been sent, but it has) Spammed to hell by confused people
March 20, 200917 yr Use the code above but grab where the user came from. So instead of redirecting to index you redirect to where they came from. so instead of defining it as index define it as whatever is in $HTTP_REFERER. Its not fool proof but it will work.
March 20, 200917 yr Or another way would be to send the current url when they click through to the next page and then use that as the redirect url.
March 23, 200917 yr Author Or another way would be to send the current url when they click through to the next page and then use that as the redirect url. but how do you do that
March 23, 200917 yr There's many options. The easiest would most likely be a GET or a SESSION to pass the page URL.
March 23, 200917 yr but how do you do that Like tom cash suggests you could use a GET or SESSIONS to pass the info to the next page. The easiest way is to use the get and just send the current url as an attachment to the url eg: current url = form.php next url = result.php?previous=form then on the result page you could grab the value of previous and use that as the url you want to redirect to. You could add that variable as a hidden variable on your form. I wouldnt personally do it that way but that is how you would send it as part of your form. Its not ideal because you will run into problems if you start trying to send special characters, question marks and stuff. You would be much better off using sessions if you can, its really still quite simple. just set the session variable to your current page and then grab it on your next page.
March 24, 200917 yr Author the thing is my php knowledge is really basic, i'm using the code from this tutorial http://www.zimmertech.com/tutorials/php/25...pt-tutorial.php the problem is his redirect doesnt work
March 24, 200917 yr Author sorry Skidz i didnt mean to over look your coding, it was just when i use it it just redirects to the homepage
March 24, 200917 yr did u come from the home page? That'll take u back to the page your user agent refers you from
March 24, 200917 yr Author no, the form is on several pages, none of which are the homepage has the problem got anything to do with the way that tutorial uses includes as apose to just being on one page
March 24, 200917 yr I thought you were looking for a way to redirect back to the page you came from? Am I mis understanding?
March 24, 200917 yr Author yeah thats correct, i wanted it to come back to the page they posted the comments from not the home page. could have i installed the code wrong which is causing it to go to the home page and not return to the page they came from, all i did was copy and paste the code into the bottom of the page which gives the thank you message, on that tutorial its submitcomment.php
July 21, 201016 yr Who's the daddy Hi Could you please help me. I have the same problem. I am using the following (as a test example) contact form : www.gruffe.co.uk/contact.htm with the following VERY simple PHP www.gruffe.co.uk/contact.php I want it so that whatever address the original HTML file...gets passed to the PHP so that at the end, the user can be re-directed back without having their browsing experience interrupted (dont want them to have to renavigate click any button...just want submit, then back to same page - with fields now blank - so dont get spammed to death) Any help greatly appreciated!!!!
July 21, 201016 yr Do you control all the forms that post to to your post script? Yes I control all of the forms....index.htm, example1.htm, example2.htm...all using the same form as seen on index-4.htm My ideal solution would be.... Enter details onto form (no validation needed as this a voluntary form) Click submit Page (appears) to stay the same Message box appear "Thank you for your interest" or if there is an error Message box appear "There appears to be an error, please use the info@gruffe.co.uk link provided" The same type of message box that appears when you personal message a member on this site, caution box with a Message Sent alert Any help greatly appreciated Thanks Luke
July 21, 201016 yr I'm posting on an iPhone at the moment but if nobody has given you the correct solution by the time I get to my office in the morning 10 hours from now. Ill post sample code for you then
July 21, 201016 yr I'm posting on an iPhone at the moment but if nobody has given you the correct solution by the time I get to my office in the morning 10 hours from now. Ill post sample code for you then Thinking you are going to be the man for the job! This will allow me to finish my site...then I can get some customers! Thanks
July 21, 201016 yr U could also ideally create a function to handle redirects function redirect($loc){ header("Location:".$loc); die(); } Then use the function like this redirect("index.php");
July 21, 201016 yr U could also ideally create a function to handle redirects function redirect($loc){ header("Location:".$loc); die(); } Then use the function like this redirect("index.php"); But wont this just take me to index.php every time? I want it to be relative to the page the user came from...including the extra message box funcationality Would it be possible for a sample .htm and .php to be produced. I am a newb to PHP so no idea where to put this function even if I created it
July 21, 201016 yr But wont this just take me to index.php every time? I want it to be relative to the page the user came from...including the extra message box funcationality Would it be possible for a sample .htm and .php to be produced. I am a newb to PHP so no idea where to put this function even if I created it Will inside the function u have this $loc thats called a parameter or param for short so where u have index.php right here redirect("index.php"); you can plug in any page into the param so u could easily change it to redirect("contact.php"); ect...
July 21, 201016 yr Will inside the function u have this $loc thats called a parameter or param for short so where u have index.php right here redirect("index.php"); you can plug in any page into the param so u could easily change it to redirect("contact.php"); ect... But this would be static right? I want one contact.php....that will be accessed by several .htm pages....and want the user to be directed back to the html page after the mail sent. with messages etc
July 21, 201016 yr I find that this is fairly effective (and stupidly simple): <?php header("Location: ".$_SERVER['HTTP_REFERER']); die("Redirecting..."); ?>
July 21, 201016 yr I find that this is fairly effective (and stupidly simple): <?php header("Location: ".$_SERVER['HTTP_REFERER']); die("Redirecting..."); ?> Ok so if I had a HTML file with the form elements, and my contact.php file...where would the above coding go...how would I integrate it. My PHP really is very very basic Ideally I would like it so that the users browser experience is not affected, so the page they are...they stay on...the email gets sent silently...or at worst it sends then comes straight back to the page In any case would like message box to relay to the user that the message send was successful / not successful Thanks
July 22, 201016 yr But this would be static right? I want one contact.php....that will be accessed by several .htm pages....and want the user to be directed back to the html page after the mail sent. with messages etc Then in the function redirect u would just put the page u wanna redirect back to like redirect("contact.php"); or whatever
July 22, 201016 yr I find that this is fairly effective (and stupidly simple): <?php header("Location: ".$_SERVER['HTTP_REFERER']); die("Redirecting..."); ?> I must also stress about this that $_SERVER['HTTP_REFERER'] can not always be trusted considering that Not all user agents will set this.
July 22, 201016 yr I must also stress about this that $_SERVER['HTTP_REFERER'] can not always be trusted considering that Not all user agents will set this. True, which is why I said 'fairly' effective
July 22, 201016 yr True, which is why I said 'fairly' effective Ohh im sorry i think i missed that part
July 22, 201016 yr Ohh im sorry i think i missed that part As I said, it cant be static... So need it to refer back to the main page Could someboy please provide me with an example PHP file to post the mail then return user to the form (which could be any number of 20 pages so needs to know where it came from)...and then provide the user with a message box (or HTML popup) saying "Thanks, message posted"
July 22, 201016 yr As I said, it cant be static... So need it to refer back to the main page Could someboy please provide me with an example PHP file to post the mail then return user to the form (which could be any number of 20 pages so needs to know where it came from)...and then provide the user with a message box (or HTML popup) saying "Thanks, message posted" Or am I missing something? The redirect script...would be static...I want a dynamic script that pushes browser back. Or does the redirect pass a fixed (pre-defined) variable forward to the PHP, so it knows where to re-direct back to How would I use the redirect script....do you have an exmaple htm and php file, not sure how id integrate it All I have at present is a tempalte www.gruffe.co.uk/contact.htm along with the php www.gruffe.co.uk/contact.php All your help is very much appreciated
July 22, 201016 yr //example form.php <form action="contact.php" method="post"> <input type="text" name="your_name" /> <input type="hidden" name="redirect" value="<?php (($_SERVER['SERVER_PORT'] == 80) ? "http://" : "https://").$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>" /> <input type="submit" name="submit" value="Submit" /> </form> //example contact.php /* * Do what you need to do with the form elements here */ header('Location: '.$_POST['redirect']); exit();
Create an account or sign in to comment