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

can any body tell me the dff between Rredirect through javascript & header

P: n/a
Hello

can any body tell me the dff between
function redirect($url)
{
echo "<script>";
echo "window.location='".$url."'";
echo "</script>";

}
and

header("Location $url")
syntex belong to php

Feb 19 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Feb 19, 1:40 pm, "2291980" <stephenhb...@gmail.comwrote:
Hello

can any body tell me the dff between
function redirect($url)
{
echo "<script>";
echo "window.location='".$url."'";
echo "</script>";

}

and

header("Location $url")

syntex belong to php
Dear Stephen,

In the first solution PHP creates a JavaScript and sends it via a
'normal' HTML page to the browser. If the browser has JavaScript
enabled it loads the new URL. If it is disabled, nothing happens.

In the second solution PHP sends a redirect statement with the URL to
the browser. The browser loads the new URL.

Cheers
Martin

------------------------------------------------
online accounting on bash bases
Online Einnahmen-Ausgaben-Rechnung
http://www.ea-geier.at
------------------------------------------------
m2m server software gmbh
http://www.m2m.at

Feb 19 '07 #2

P: n/a
On 19 Feb, 12:40, "2291980" <stephenhb...@gmail.comwrote:
Hello

can any body tell me the dff between
function redirect($url)
{
echo "<script>";
echo "window.location='".$url."'";
echo "</script>";

}

and

header("Location $url")

syntex belong to php
When a browser sees header("Location whatever-is-the-value-of-$url")
it will barf because it should say header("Location: whatever-is-the-
value-of-$url").

However, supposing that you had put the correct value in the call
then, as soon as it sees the header location value, it can go off to
get the new page. With
function redirect($url)
{
echo "<script>";
echo "window.location='".$url."'";
echo "</script>";
}
it has to load your page before it can see the script to execute.

Feb 19 '07 #3

P: n/a
On 19 Feb, 12:51, "Martin Mandl - m2m tech support"
<martin.ma...@gmail.comwrote:
On Feb 19, 1:40 pm, "2291980" <stephenhb...@gmail.comwrote:


Hello
can any body tell me the dff between
function redirect($url)
{
echo "<script>";
echo "window.location='".$url."'";
echo "</script>";
}
and
header("Location $url")
syntex belong to php

Dear Stephen,

In the first solution PHP creates a JavaScript and sends it via a
'normal' HTML page to the browser. If the browser has JavaScript
enabled it loads the new URL. If it is disabled, nothing happens.

In the second solution PHP sends a redirect statement with the URL to
the browser. The browser loads the new URL.

Cheers
Martin

------------------------------------------------
online accounting on bash bases
Online Einnahmen-Ausgaben-Rechnunghttp://www.ea-geier.at
------------------------------------------------
m2m server software gmbhhttp://www.m2m.at- Hide quoted text -

- Show quoted text -
Not quite. In the second situation you should get an error because the
header is invalid. It should have a colon after Location.

Feb 19 '07 #4

P: n/a
Rik
On Mon, 19 Feb 2007 13:40:35 +0100, 2291980 <st**********@gmail.comwrote:
Hello

can any body tell me the dff between
function redirect($url)
and
header("Location $url")
Like the others already said, and keep in mind a lot more visitors to your
site will support a header redirect then a javascript redirect, for
instance searchbots. That's not to say they will all obey: just as
javascript, following redirects is left to the browser, and a lot of them
have settings to either follow or not.
syntex belong to php
To the HTTP protocol.
--
Rik Wasmus
Feb 19 '07 #5

P: n/a
"Rik" <lu************@hotmail.comwrote in message
news:op.tn0eqagcqnv3q9@misant...
>
To the HTTP protocol.
To the Batmobile!

....I'll get my coat.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Feb 20 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.