By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,040 Members | 1,103 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,040 IT Pros & Developers. It's quick & easy.

redirection question

P: n/a
Perhaps this is not the best design right now in my php script, but I've
just started with php after a long break.

The thing is that I enter a page called foo1.php, this script do some
calculations and should then send directly send the user to a page called
foo2.php together with the variables $bar and $bar2.

On the page foo1.php there will be no input or any clicking required by the
user. Just as soon as the values are calculated, it should continue.
How can I achieve this?
Jan 30 '07 #1
Share this Question
Share on Google+
18 Replies


P: n/a
On Jan 30, 3:09 pm, Gunnar G <deb...@comhem.sewrote:
Perhaps this is not the best design right now in my php script, but I've
just started with php after a long break.

The thing is that I enter a page called foo1.php, this script do some
calculations and should then send directly send the user to a page called
foo2.php together with the variables $bar and $bar2.

On the page foo1.php there will be no input or any clicking required by the
user. Just as soon as the values are calculated, it should continue.
How can I achieve this?

If the data is not sensitive, you can simply use the header() function
to redirect to the appropriate page passing the variables as
parameters in the URI.

i.e.
header('Location: http://site.com/somepage.php?foo=$foo&bar=$bar");

Otherwise, if you need to hide the parameters, or do not want the page
to be bookmarked you can set the parameters in the session before
redirecting and omit them from the URI.

see:
http://php.net/header
for more info.

Hope that helps,
Carl.

Jan 30 '07 #2

P: n/a
<comp.lang.php>
<Gunnar G>
<Tue, 30 Jan 2007 23:09:59 GMT>
<bf*******************@newsb.telia.net>
Perhaps this is not the best design right now in my php script, but I've
just started with php after a long break.

The thing is that I enter a page called foo1.php, this script do some
calculations and should then send directly send the user to a page called
foo2.php together with the variables $bar and $bar2.

On the page foo1.php there will be no input or any clicking required by the
user. Just as soon as the values are calculated, it should continue.
How can I achieve this?
Is there any good valid reason why you want to redirect to foo2.php ? .

Why not just do the calculations in foo1.php and then display the
results underneath in foo1.php when they are done .
--
www.phptakeaway.co.uk
(work in progress)
Jan 31 '07 #3

P: n/a
On Jan 30, 7:10 pm, Krustov <m...@privacy.netwrote:
<comp.lang.php>
<Gunnar G>
<Tue, 30 Jan 2007 23:09:59 GMT>
<bfQvh.30769$E02.12...@newsb.telia.net>
Perhaps this is not the best design right now in my php script, but I've
just started with php after a long break.
The thing is that I enter a page called foo1.php, this script do some
calculations and should then send directly send the user to a page called
foo2.php together with the variables $bar and $bar2.
On the page foo1.php there will be no input or any clicking required by the
user. Just as soon as the values are calculated, it should continue.
How can I achieve this?

Is there any good valid reason why you want to redirect to foo2.php ? .

Why not just do the calculations in foo1.php and then display the
results underneath in foo1.php when they are done .

--www.phptakeaway.co.uk
(work in progress)
He's probably setting a cookie, which won't be read until a new page
is loaded.
Ya, header("Location: foo2.php"); is what you want.

Jan 31 '07 #4

P: n/a
On Jan 30, 7:44 pm, "GAMEchief" <SegaDra...@gmail.comwrote:
On Jan 30, 7:10 pm, Krustov <m...@privacy.netwrote:
<comp.lang.php>
<Gunnar G>
<Tue, 30 Jan 2007 23:09:59 GMT>
<bfQvh.30769$E02.12...@newsb.telia.net>
Perhaps this is not the best design right now in my php script, but I've
just started with php after a long break.
The thing is that I enter a page called foo1.php, this script do some
calculations and should then send directly send the user to a page called
foo2.php together with the variables $bar and $bar2.
On the page foo1.php there will be no input or any clicking required by the
user. Just as soon as the values are calculated, it should continue.
How can I achieve this?
Is there any good valid reason why you want to redirect to foo2.php ? .
Why not just do the calculations in foo1.php and then display the
results underneath in foo1.php when they are done .
--www.phptakeaway.co.uk
(work in progress)

He's probably setting a cookie, which won't be read until a new page
is loaded.
Ya, header("Location: foo2.php"); is what you want.
Heres an all purposes function. You will run into an issue with
headers if you use any printing before you send the header information
(same with cookies and the session too), this function will send the
request as a JS redirect if the headers have already been sent.

function Redirect($location = "")
{
if (headers_sent())
{
if (!$location)
print '<script language="javascript" type="text/javascript"
>window.history.go(-1)</script>';
else
print '<script language="javascript" type="text/javascript"
>window.location = '.$location.'</script>';
}
else
{
if(!$location)
header("Location: " . $_SERVER["PHP_SELF"];);
else
header("Location: " . $location;);
}
}

Jan 31 '07 #5

P: n/a
..oO(bo*********@gmail.com)
>Heres an all purposes function. You will run into an issue with
headers if you use any printing before you send the header information
(same with cookies and the session too), this function will send the
request as a JS redirect if the headers have already been sent.
How ugly. The "headers already sent" problem can easily be solved
without using unreliable client-side scripting, either be thinking over
the structure of the code or by using output buffering.

Additionally a Location header requires an absolute URL.

Micha
Jan 31 '07 #6

P: n/a
Michael Fesser wrote:
.oO(bo*********@gmail.com)
>>Heres an all purposes function. You will run into an issue with
headers if you use any printing before you send the header information
(same with cookies and the session too), this function will send the
request as a JS redirect if the headers have already been sent.

How ugly. The "headers already sent" problem can easily be solved
without using unreliable client-side scripting, either be thinking over
the structure of the code or by using output buffering.
Totally true: ugly solution.
And besides that, not all clients have JS enabled.
>
Additionally a Location header requires an absolute URL.
Erm...
I think that requirement was dropped some time ago.
And all browsers I have ever seen support the relative URL.
Not tested on Lynx 0.8 beta. ;-)

Regards,
Erwin Moller

>
Micha
Jan 31 '07 #7

P: n/a
..oO(Erwin Moller)
>Michael Fesser wrote:
>Additionally a Location header requires an absolute URL.

Erm...
I think that requirement was dropped some time ago.
HTTP was dropped? Damn. ;)

14.30 Location
http://www.w3.org/Protocols/rfc2616/....html#sec14.30
>And all browsers I have ever seen support the relative URL.
But you haven't seen all. And browsers are not the only user agents. A
bug doesn't become less of a bug, just because it works in the majority.

Micha
Jan 31 '07 #8

P: n/a
Erwin Moller:

[re HTTP Location header]
And all browsers I have ever seen support the relative URL.
The question is have you ever seen a browser that doesn't
support absolute URLs?

--
Jock

Jan 31 '07 #9

P: n/a
On 30 Jan 2007 22:17:11 -0800, bo*********@gmail.com wrote:
>
function Redirect($location = "")
{
if (headers_sent())
{
if (!$location)
.....................
}
else
{
if(!$location)
.............
....
Huh? How's that gonna work?

Jonesy
--
Marvin L Jones | jonz | W3DHJ | linux
38.24N 104.55W | @ config.com | Jonesy | OS/2
*** Killfiling google posts: <http://jonz.net/ng.htm>
Jan 31 '07 #10

P: n/a
John Dunlop wrote:
Erwin Moller:

[re HTTP Location header]
>And all browsers I have ever seen support the relative URL.

The question is have you ever seen a browser that doesn't
support absolute URLs?
lol, some browser that would be!
;-)

Erwin
>
--
Jock
Jan 31 '07 #11

P: n/a
Erwin Moller wrote:
John Dunlop wrote:
>>And all browsers I have ever seen support the relative URL.
The question is have you ever seen a browser that doesn't
support absolute URLs?

lol, some browser that would be!
Somewhere, somehow, you just know... there's an open sores
project that's trying to accomplish that.
Jan 31 '07 #12

P: n/a
Michael Fesser wrote:
.oO(Erwin Moller)
>>Michael Fesser wrote:
>>Additionally a Location header requires an absolute URL.

Erm...
I think that requirement was dropped some time ago.

HTTP was dropped? Damn. ;)
Hope not, then I am out of work!
And since I am really useless without internet...
>
14.30 Location
http://www.w3.org/Protocols/rfc2616/....html#sec14.30
Hmm yes. That sounds convincing.
Never trusts rfcs not recommended by me. ;-)

Here is one for you:
http://www.ietf.org/rfc/rfc3986.txt

It clearly describes relative referencing. (Part 4 and 5 mainly)

But judge for yourself.
>
>>And all browsers I have ever seen support the relative URL.

But you haven't seen all. And browsers are not the only user agents. A
bug doesn't become less of a bug, just because it works in the majority.
Well, that may be true.
I only aim my php for internetbrowsers, so I don't know jack about other
agents.
Thanks for the warning though.

Regards,
Erwin Moller
>
Micha
Jan 31 '07 #13

P: n/a
..oO(Erwin Moller)
>Michael Fesser wrote:
>>
14.30 Location
http://www.w3.org/Protocols/rfc2616/....html#sec14.30

Hmm yes. That sounds convincing.
Never trusts rfcs not recommended by me. ;-)

Here is one for you:
http://www.ietf.org/rfc/rfc3986.txt

It clearly describes relative referencing. (Part 4 and 5 mainly)
I'm familiar with it, but even the most recent and generalized RFC for
URI syntax doesn't change the meaning of "absolute URI", which is
required in the HTTP RFC. RFC 3986 just defines what an absolute URI
actually is.
>But you haven't seen all. And browsers are not the only user agents. A
bug doesn't become less of a bug, just because it works in the majority.

Well, that may be true.
I only aim my php for internetbrowsers, so I don't know jack about other
agents.
Thanks for the warning though.
I can remember someone having a strange problem with using a relative
URI and a query string in a Location header, which didn't work in Lynx
or something like that. The problem vanished after changing to an
absolute URI. It was posted to a German newsgroup, but I didn't bookmark
it and can't find it at Google Groups at the moment ... :(

Of course it doesn't really prove anything, but at least it shows that
there might be problems, which can easily be avoided by just following
the standards. Be it HTML, CSS or HTTP - it's always a good idea to
adhere to the written standards, because then it's not your fault if
something goes wrong.

Micha
Jan 31 '07 #14

P: n/a
On Wed, 31 Jan 2007 08:08:54 -0800, Allodoxaphobia <bi********@config.com
wrote:
On 30 Jan 2007 22:17:11 -0800, bo*********@gmail.com wrote:
>>
function Redirect($location = "")
{
if (headers_sent())
{
if (!$location)
.....................
> }
else
{
if(!$location)
.............
....

Huh? How's that gonna work?

Jonesy
It may, or may not, since it relies on client side scripting. Basically,
it checks if headers have been sent, if so, it tires to "redirect" using
JavaScript, or else it will use PHP's header function to redirect.

--
Curtis, http://dyersweb.com
Feb 1 '07 #15

P: n/a
Michael Fesser wrote:
.oO(Erwin Moller)
>>Michael Fesser wrote:
>>>
14.30 Location
http://www.w3.org/Protocols/rfc2616/....html#sec14.30

Hmm yes. That sounds convincing.
Never trusts rfcs not recommended by me. ;-)

Here is one for you:
http://www.ietf.org/rfc/rfc3986.txt

It clearly describes relative referencing. (Part 4 and 5 mainly)

I'm familiar with it, but even the most recent and generalized RFC for
URI syntax doesn't change the meaning of "absolute URI", which is
required in the HTTP RFC. RFC 3986 just defines what an absolute URI
actually is.
Hi Micha,

For clearity's sake: I completely agree with you that sticking to the
standards makes sense in almost all circumstances.
Deciding WHO decides what the standards are is my current problem.

My meager knowledge of picking the right RFC is to blame. I have dived into
a few, but I have trouble deciding on their 'weight'/importance.

I wonder, which RFC are considered to define standards by most people when
it comes to HTTP and the like?
Do you have/know of some list?

I am a bit confused because just the other day somebody in some javascript
newsgroup made it clear that just the fact somebody dumps a RFC doesn't
make it worth your while.
This is NOT my area of expertise, and I wonder which ones are worth reading
and which not. How do you/others approach that?

TIA

Regards,
Erwin Moller

>>But you haven't seen all. And browsers are not the only user agents. A
bug doesn't become less of a bug, just because it works in the majority.

Well, that may be true.
I only aim my php for internetbrowsers, so I don't know jack about other
agents.
Thanks for the warning though.

I can remember someone having a strange problem with using a relative
URI and a query string in a Location header, which didn't work in Lynx
or something like that. The problem vanished after changing to an
absolute URI. It was posted to a German newsgroup, but I didn't bookmark
it and can't find it at Google Groups at the moment ... :(

Of course it doesn't really prove anything, but at least it shows that
there might be problems, which can easily be avoided by just following
the standards. Be it HTML, CSS or HTTP - it's always a good idea to
adhere to the written standards, because then it's not your fault if
something goes wrong.

Micha
Feb 1 '07 #16

P: n/a
Erwin Moller wrote:
I wonder, which RFC are considered to define standards by most people when
it comes to HTTP and the like?
Do you have/know of some list?
Wow- you'd have to use several RFC's for that.
Most to all of the RFC's reference other RFC's.
For example - the ones for HTTP requires a knowledge of the ones
for DNS - and likley httpS as well.

This is NOT my area of expertise, and I wonder which ones are worth reading
and which not. How do you/others approach that?
Feb 1 '07 #17

P: n/a
Erwin Moller:
My meager knowledge of picking the right RFC is to blame. I have dived into
a few, but I have trouble deciding on their 'weight'/importance.
http://www.rfc-editor.org/

--
Jock

Feb 1 '07 #18

P: n/a
John Dunlop wrote:
Erwin Moller:
>My meager knowledge of picking the right RFC is to blame. I have dived
into a few, but I have trouble deciding on their 'weight'/importance.

http://www.rfc-editor.org/

--
Jock
Hi,

Thanks for the guidance.
This is from their FAQ:

http://www.rfc-editor.org/rfcfaq.html

Are all RFCs Internet standards documents?
In a word, "NO!".

Many RFCs have Informational or Experimental status and do not represent any
kind of standard. They contain information that may be useful or important
to retain in this archival document series.
This is important to understand, because unscrupulous marketeers and a
careless trade press sometimes falsely suggest that every RFC represents a
standard, or that all standards have equal weight. The relationship among
Internet technical specifications is often complex.

How can one tell where in the standards track an RFC is?
Consult the online document "Internet Official Protocol Standards". We
periodically publish a snapshot of this information as an RFC whose number
is divisible by 100; the latest such RFC is STD 1.

These links are also on the RFC Search and Retrieval page.

Which answers my question. :-)

Thanks.

Regards,
Erwin Moller
Feb 1 '07 #19

This discussion thread is closed

Replies have been disabled for this discussion.