Forum Moderators: phranque
I am using a PHP script on a server and want to ensure that the return url takes the user back to the page he/she was on when he submitted the php POST action.
But I want the return URL to do NOTHING! Ie not to refresh the page or have any effect at all.
Any ideas on what to put into the return url to ensure this on any browser and in any situation?
Hope the above is clear - if not let me know!
Thanks
The attempt to load 'Accessing URL:http://www.domain.com/mail.handler.php' failed.
but the php script does its job and sends me an email detailing the hit on the page in my site accessed. So I guess its IE not liking the return url?
Any further ideas - thanks for your help anyway!
...will take you back from whence you came.
Or you could:
<?php
die(implode("",file($_SERVER['HTTP_REFERER']));
?>
...if you want to do spit out the HTML without redirecting the browser. The URL shown in the address bar will not change in this case.
If you are writing the result of a POST operation, its usually best to use a GET redirect so if they bookmark or press refresh, it won't screw things up.
HTH
I'll turn on email notification. Post more specifics if you need more info.
I dont have access to the php code on the server. I am able to set the return-url I want to get back from the server within a form before I do the form action POST to hit the php code on the server. So I need something that will be returned that will NOT cause a page refresh and simply leave the existing page on the screen.
I've tried "javascript:null", "javascript: void(null)", "javascript:history.go(-1)" but it seems browsers will not allow javascript to be used in this way - ie: within a return url.
Any more ideas?
Thanks!
OK I'm with you. Tricky one.
Try this..
instead of: <input type=hidden name="return_url" value="your_return_url">
...use:
<script>
document.write('<input type=hidden name="return_url" value="'+document.location+'">');
</script>
That places the URL of the original page into the hidden form field, so the return URL will always be the URL that the user came from (ie the location of the form)
If you want to go back to the page BEFORE the form, replace "document.location" with "document.referer" (or that may be with 2 Rs, I can't remember offhand)
Is that what you're after?
Cheers,
Alex
Thanks for everyone's input - I'm still not there!
To be clear, I have no control over what the PHP script on the server does. Whatever return_url I give it via a form submit will be the url issued when it completes its script. It HAS to issue some sort of return url. Whilst in most cases this is something the user needs to take them to a response/thankyou page, there are instances where I want the user to remain on the page from which they issue the form submit. Because the pages are heavy in content, a refresh is not useful as the user sees the page being slowly reloaded and over dial-up lines it is not a great user experience!
So I am trying to find a return_url that I can insert via JS into the hidden field so that when the php script server issues it will NOT cause any action at the user's end. Essentially a generalised "null action" return url.
Hope that clarifies and makes sense. I've tried "javascript: null" etc but the browsers don't accept that being issued externally. Leaving the return_url field blank causes a blank window to be loaded.
Any further ideas or suggestions, anyone?
Thanks, Chris