Re: Most portable back button in php
| From: | Henry | Date: | Fri, 09 Aug 2002 07:44:26 +0000 |
| Subject: | Re: Most portable back button in php | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-111779@lists.php.net to get a copy of this message | ||
Thanks Justin
I'll have a go ;-)
Henry
"Justin French" <justin@indent.com.au> wrote in message
news:B979548A.C6EF%justin@indent.com.au...
> I have this code on one of my sites... it sits inthe config file, so every
> page is able to establish their URL.
>
> For my site, the definition of URL is just the stuff after
> http://www.domain.com/.
>
>
> $script = $_SERVER['PHP_SELF'];
> $script = eregi_replace('^/', '', $script);
> $qs = $_SERVER['QUERY_STRING'];
> $this_ref = base64_encode($script."?".$qs);
>
>
> The result? $this_ref will look like dir/dir/file.php?getvar=foo if the
> current URL is http://www.mysite.com/dir/dir/file.php?getvar=foo<_ƒ
> 2ÿ. �žÚÝ«
>
>
> The if I need to pass the referrer onto another script (in my case a login
> procedure), I just do this:
>
> <A HREF="login.php?return_ref=<?=$this_ref?>">login here</a>
>
>
> login.php passes $_GET['return_ref'] around in the URL through the login
> form, the validation, the error messages, the password reminder script,
and
> all sorts of other stuff, and once the user is finally logged in, I can do
> this:
>
> $return_ref = base64_decode($_GET['return_ref']);
>
> and supply them with:
>
> <A HREF="<?=$return_ref?>">Click here to continue</a>
>
> ... or better still, once they're logged in, I just:
>
> header("Location: {$return_ref}");
>
>
> If you wanted to do it for a full domain URL, then store your full domain
as
> a var $base_url, and prepend it to $this_ref
>
> $base_url = "http://www.mydomain.com"; // without
> trailing slash
> $script = $_SERVER['PHP_SELF'];
> $qs = $_SERVER['QUERY_STRING'];
> $this_ref = base64_encode($base_url.$script."?".$qs);
>
>
>
> The only thing this doesn't cover is pages with POST variables, but I
> wouldn't want it to.
>
>
> Justin French
>
>
>
> on 09/08/02 1:40 AM, Henry (henry@teacake.f9.co.uk) wrote:
>
> > I have an idea then.
> >
> > How can I best generate a full URL from PHP_SELF and other variables on
the
> > referrer page such that I can generate the back link on the page I get
to
> > even if the referrer page is on a different server?
> >
> > as an eample if I know that the page to go back to will be at
> > http://www.myprimary.com/referrer.php and I generate a
> > page at
> > http://www.mysecondary.com/info.php I can ensure that
> > there is the
following
> > html in place
> >
> > <a
> > href="http://www.myprimary.com/referrer.php">go
> > back</a>
> >
> > TIA
> >
> > Henry
> >
> > "Stas Maximov" <maximov@eircom.net> wrote in message
> > news:008601c23eef$cc25f260$ec000064@nexus...
> >> Yes, indeed. Thanks, Justin, I forget to mention this one. It works
really
> >> well on forums and comments, i.e. the cases when you do POSTs. The good
> >> thing here is that you passing the whole URL (taking it from PHP_SELF),
so
> >> you save on the decision logic in the end.
> >>
> >> Regards, Stas
> >>
> >> ----- Original Message -----
> >> From: "Justin French" <justin@indent.com.au>
> >> To: "Stas Maximov" <maximov@eircom.net>; "Henry"
<henry@teacake.f9.co.uk>
> >> Cc: "PHP General" <php-general@lists.php.net>
> >> Sent: Thursday, August 08, 2002 4:03 PM
> >> Subject: Re: [PHP] Most portable back button in php
> >>
> >>
> >>> Just to add in some more ideas, you can always pass the referring
script
> >> to
> >>> the second script manually...
> >>>
> >>> I do this when someone has to login, then return back to the original
> > page
> >>> they were on... I just get the URL + query string, base64_encode()
it,
> >> then
> >>> pass it around in the URL or POST until i need it, then
base64_decode()
> > it
> >>> and header("Location: ...") the user to the right page.
> >>>
> >>> Works really well, depending on your situation.
> >>>
> >>>
> >>> Justin
> >>>
> >>>
> >>> --
> >>> PHP General Mailing List (http://www.php.net/)
> >>> To unsubscribe, visit:
> >>> http://www.php.net/unsub.php
> >>>
> >>>
> >>
> >
> >
>