I am building a php web app and I am having some trouble with the navigation. It seems the user have to hit back twice to get past one of my apparent traps. . .
Consider this situation. The user wants to upload a file with a description, so he hits upload and gets directed to the upload.php page. He fills out the form and submits the form to uploader.php. Uploader.php redirects him back to upload.php?yay=true.
From here, he needs to hit back twice to get back to the page where he hit the upload button.
Is there a clever way to keep track of which page he originally came from (this case, 2 pages back) or do i need to keep his navigation story in say the session variable?
I could also just redirect to the page from where the user hit the upload button, but this means that the back button will take him to the fileupload.php page instead of the page previously to the one that had the upload button.
Any help appriciated!
Simple after doing upload stuff, justt redirect him to the original page like
// do the upload stuff
header('location:the_page_name.php');//the page where user originaly came from
Related
I have a page called a.php . It has a form and submit data via POST to same file (a.php) . Page loads with no error. Then I click any link (b.php or b.html) on that page . it directs to any page as usual. Then when I click back button from b.php or b.html it does not show previous page.
Any help to solve this matter ?
Thanks
About Method
The $_POST Method used for SUBMITTING FORMS something Create or Modify it is a secure method.In other words POST is sending data to server from browser
FOR EXAMPLE
Creating Articles
Editing Articles
File Uploading
In your case you are getting values POST is not for getting values Use $_GET method for this
Why Document Expires ?
I taken this Image from wikipedia.
Why Browser Do this?
It is because it prevent from duplicate submission.
For Example : On any shopping site there are payment options user buy a product and pay for it , now if he/she(user) refresh page again the payment done two times .
according to your question, page a.php is submitting data (post) to the page itself, so if you go to other page and then want to back again to page a.php (by clicking the back button on browser) it causes document expired because when you click it you are not submitting any data (post) to page a.php.
Having an interesting time trying to get an upload to work. So here's the thing: I have a form that uses some javascript to pretend it's 3 separate pages. It's all one form, but as you click "next" one section fades away and another section is shown. The last page is the page where you can make the most errors....if you miss a required field or you're trying to sign up with an already used email address the app will kick out an error, but it has to do a:
redirect(/path/to/app#!section2);
to show the correct page where the error is located. I can get all the data back, by quickly putting all the variables into a flashvar. So IF this redirect were to happen I have all the data to show back in the form....except....if you tried to upload a photo, I've lost the photo upload. My first thought was to try and save the $_FILES data to a flashvar, but I don't think that will work.
Anyone see this before? There has to be a way around this.
Thanks
I would make the entire process ajax based so you wouldn't have to worry about preserving data through redirects. You could do all of your validation in your controllers as usual and then either return json or javascript code back to the browser to parse and handle what to do next.
I am a newbie to programming. I have a PHP website which works as follows
Index Page - Search Results - Show a Product
The site user enters search critera on Index Page and the page is POSTed to Search Results page. From there, the site user clicks on a Product href that takes him to the Product Details. This is working fine till here.
The problem occurs when the user click the browser BACK button. The Search Result page comes up totally crashed and the user has to press F5/Browser Refresh to re-submit it. Any idea/technqiue that I can use to avoid this crash?
When a browser goes back to a page that comes from POSTing some data, the browser often times needs to re-POST the data in order to get the same page back. Since that can sometimes be bad (e.g. re-POSTing an order form), many browsers require the user to force a refresh with a warning.
You can generally use a GET instead of a POST form to avoid this.
An idea would be using GET for the method of your search form instead of POST (that apparently you are using). That way, even if going back in browser history, your server could re-supply its search results.
You would need the following:
change method="post" to method="get" in your search form
change every $_POST relating to the search form data to $_GET in your search form processing php file.
Of course, it could not work for your specific usecase. That's just an idea.
I have a classifieds website, and when posting a new classified users fill out a form offcourse. Then they hit the submit button, and a "verify" page appears which displays what they have filled out, and if it looks good, the users hit the "ok" button and the classified is posted.
Here is a short example:
<form action="verify.php" name="main_form" etc
Then from verify.php if the classified looks good, they hit OK, and it is posted.
However, here they have the option of clicking "back" to change something, which is where my problem comes in.
Now, at the bottom of the main_form, I have file-upload tool, which refreshes the page for each upload. This is what is causing the problem. However, it is too late for me to change it to a non-refreshing file-upload now (ajax for instance).
Anyways, the problem is that IF the user have uploaded a file and submits the page, the verify page opens. So from here the back button only displays a "Warning: page has expired" instead of showing the form with the images uploaded.
However, users are able to press F5 (refresh) to refresh the browser and the form will appear once again as it was, but this is no good solution.
How can I fix this?
And how come other browsers don't have this problem, they actually go back and display the full form with the images?
Also, offcourse, if no images are uploaded, the back button works fine in IE.
If you need more input let me know...
BTW; NOT TESTED IN IE8 YET.
see: Chris Shiflett: How to Avoid "Page Has Expired" Warnings:
RecapTo avoid "Page Has Expired" warnings, set session.cache_limiter to private, and make sure that any form using the POST method submits to an intermediate processing page that redirects the user to a different URL.
Just do not use verify.php, but make it all on the same page.
http://en.wikipedia.org/wiki/Post/Redirect/Get
this is a little bit tricky.
usually when someone clicks on a link that requires him to register, this person will be redirected to the registration page and then back to the last visited page. this is possible cause the link sent a GET key through the url to the registration.php which uses the key to go back to last visited page.
but i intend to use jquery ajax for registration. basically ive got 3 different php pages. all of them include the same header.php. and in header.php ive got a registration button which i have id tagged. when this button is clicked ( $(#registration_button).click()... ) jquery will show a box (a div that was hidden in the center of the browser) with registration information. then he will register and i will redirect him to the last visited page, that is to say the current one he sees. i have to refresh the php-page to be able to show all links that a registered user can see, thats why i have to use window.location.href.
now to the question. how do i let jquery know which page is the current one he is visiting? ive got 3 php-pages.
if there is something you dont understand, please free to ask.
or if you got suggestions of other solutions, let me know. but i really want to display the registration box right away without redirecting him to another page.
You can set cookies initially in php and then update/read them via js.
You could assign the page to a session and do it that way.
$_SESSION["page_visited"] = "x.php";
Make sure to use session_start on the pages using sessions. Then just redirect to the relevant page.
header('Location: http://www.example.com/'$_SESSION["page_visited"]);
I did a similar thing not two weeks ago, correct me if I'm wrong, but if you want the registration to direct to the page the user was on, after the user has been registered in the ajax just add:
window.location.href=window.location.href;
That way the after the registration is done, it just reloads where the member was with the environment of a logged in user. This method worked great for me.