473,382 Members | 1,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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

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
5 1785
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
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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Massimiliano Alberti | last post by:
My program is heavily template based, and I use the VC++, so I have to keep the templates in the header file. My .cpp files are quite empty (they are more a connection between header files). Now,...
6
by: skubik | last post by:
Hi everyone. I'm attempting to write a Javascript that will create a form within a brand-new document in a specific frame of a frameset. The problem is that I can create the form and input...
6
by: Sentinel | last post by:
how can i place a script in body (it must be ran automaticly when html interpreter reaches it) that will redirect to another page? what i am doing is checking in php if login is successful...
9
by: bmgz | last post by:
I need to execute a JavaScript function "onload". The only problem is I don not have access to the <body> tag as it is a part of the standard page-header include (a separate file). How could I have...
11
by: Matt Kruse | last post by:
This is a common requirement - "freeze panes" in a table, so that some header rows and some columns on the left are frozen while the body content scrolls. This makes large tables more usable on...
1
by: ceolino | last post by:
Hi all. I have a simple default.aspx file where I declare a JavaScript function: <script type="text/javascript" language="JavaScript"> .... function rotate() { .... } </script>
2
by: 2291980 | last post by:
Hello can any body tell me the dff between function redirect($url) { echo "<script>"; echo "window.location='".$url."'"; echo "</script>"; }
3
by: Noorain | last post by:
I designed a site. i want to header,footer,left & right column fixed but body information only scrolling. this site screen to be 800/600 px. i designed this way but when i used position fixed all...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.