Forum Moderators: phranque

Message Too Old, No Replies

Return URL from PHP - need it to have no effect!

URL returns - how to avoid a page refresh

         

chrisjones2004

12:12 pm on May 13, 2004 (gmt 0)

10+ Year Member



Hi

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

volatilegx

1:47 pm on May 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is a problem for me, too. I know there is a meta tag that tells the browser to refresh a page every time it's viewed, but I don't know of a tag that does the opposite.

bcolflesh

1:51 pm on May 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



javascript: history.go(-1)

chrisjones2004

2:58 pm on May 13, 2004 (gmt 0)

10+ Year Member



Thanks. The javascript:history.go(-1) in the return url causes the form submit I use to come back with an error. I'm using IE5.
I get this:

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!

ginga

11:02 pm on May 13, 2004 (gmt 0)

10+ Year Member



<?php
echo "<script>location='{$_SERVER['HTTP_REFERER']}'</script>";
?>

...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.

chrisjones2004

7:50 am on May 14, 2004 (gmt 0)

10+ Year Member



Hi Ginga

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!

ginga

8:09 am on May 14, 2004 (gmt 0)

10+ Year Member



Hi Chris,

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

volatilegx

5:33 pm on May 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think we may have veered off from what chrisjones2004 was really asking about. It looks to me like he is trying to avoid the message (the one that directs you to refresh the page) that pops up in most browsers when you hit the back button and return to a page that was created via a POST request. Simply having the URL available in the script won't affect this.

chrisjones2004

7:52 am on May 16, 2004 (gmt 0)

10+ Year Member



Hi

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

ginga

9:47 am on May 16, 2004 (gmt 0)

10+ Year Member



try just #

better?

roitracker

2:36 pm on May 16, 2004 (gmt 0)

10+ Year Member



Have you considered putting the form in an iframe instead?

chrisjones2004

7:34 am on May 17, 2004 (gmt 0)

10+ Year Member



Ginga

Still no joy! I tried a straight "#" and got an error back from the php script. Also tried "http://#" which my browser errored with "Server not found".

Maybe I've got the url construct wrong? Any ideas?

Thanks!
Chris

ginga

7:53 am on May 17, 2004 (gmt 0)

10+ Year Member



I'm running out of ideas TBH.

you've tried "javscript:null", "//" and "#" - one of these usually does the trick...

I know you don't have access to the PHP script to edit it, but can you get hold of the source to examine?

mcavic

3:10 am on May 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't believe that there's a way to stay on the *same* page and avoid a refresh when you're submitting a form. No matter what you put in the form action, the browser will want to go to some new page.

willybfriendly

4:41 am on May 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am not aware of a way to do this either. How about cracking the nut with another method. How about a return url with something like

function back()
{
history.go(-1);
}

<body onLoad="back()">

(Warning, my JS stinks. I offer the concept only.)

WBF

grandpa

7:16 am on May 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If I understand the problem, it has more to do with the page cache. If the form request is returning to the original page, with a lot of content, then the solution might be to enforce cache control.

chrisjones2004

11:02 am on May 18, 2004 (gmt 0)

10+ Year Member



Grandpa

Thanks - how do I enforce cache control?

Regards

Chris

DaveAtIFG

11:07 am on May 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It seems to me that your POST operation takes you from one page to another, defined by the POST action. The return URL takes you to a third page.

If the second page included some scripting to act like a browser's back button...