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

script in body

P: n/a
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 (php script is in javascript
that is in body) and if so i will print out the url to wich the
javascript must redirect the browser
<body>
<script language="javascript">
window.location=<?php a lots of ifs thens and elses and finaly print
"index2.php"; ?>
</script>
</body>

everything works fine but he browser doesn't redirect...

the page source shows
<body>
<script language="javascript">
window.location=index2.php
</script>
</body>

please help

thanks
--
What's the point in running when the light at the end of the tunnel iz
just another train...
Jul 23 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Sentinel wrote:
window.location=index2.php


Don't forget the quotes. Otherwise php will be interpreted as a property
of an index2 object.

window.location="index2.php"
Daniel
Jul 23 '05 #2

P: n/a
Jc
Sentinel wrote:
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 (php script is in javascript
that is in body) and if so i will print out the url to wich the
javascript must redirect the browser


There are better ways to do this than relying on javascript, which the
browser might not support, or have enabled. It also requires
downloading the page, parsing it, loading the script into the scripting
engine, and then (from script) navigating to a different page.

Since you have control over the web server response in the first place
(through php), you should really use the built-in HTTP mechanism to
redirect a web browser to a different page. This method will be much
nicer/faster than using javascript, and the user will likely not even
know they were redirected since they won't see a page load and then
quickly redirect, it will happen at a lower level.

This site has an example php script you can use:
http://www.edoceo.com/creo/php-redirect.php

FYI: Another solution that is better than using javascript is to output
a meta redirect to the browser, this is a special HTML tag that doesn't
require javascript support.

Jul 23 '05 #3

P: n/a
"Sentinel" <su*****@elma.hr> kirjoitti
viestissä:d8**********@ss405.t-com.hr...
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 (php script is in javascript
that is in body) and if so i will print out the url to wich the
javascript must redirect the browser
<body>
<script language="javascript">
window.location=<?php a lots of ifs thens and elses and finaly print
"index2.php"; ?>
</script>
</body>

everything works fine but he browser doesn't redirect...

the page source shows
<body>
<script language="javascript">
window.location=index2.php
</script>
</body>


Ditch the javascript and redirect with php directly
<?php header("Location: index2.php"); ?>

--
"I am pro death penalty. That way people learn
their lesson for the next time." -- Britney Spears

et****************@5P4Mgmail.com
Jul 23 '05 #4

P: n/a
Kimmo Laine 17.6.2005 19:27:59 <d8**********@phys-news1.kolumbus.fi>
et*******************@Mgmail.com comp.lang.javascript Kimmo
"Sentinel" <su*****@elma.hr> kirjoitti
viestissä:d8**********@ss405.t-com.hr...
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 (php script is in javascript
that is in body) and if so i will print out the url to wich the
javascript must redirect the browser
<body>
<script language="javascript">
window.location=<?php a lots of ifs thens and elses and finaly print
"index2.php"; ?>
</script>
</body>

everything works fine but he browser doesn't redirect...

the page source shows
<body>
<script language="javascript">
window.location=index2.php
</script>
</body>


Ditch the javascript and redirect with php directly
<?php header("Location: index2.php"); ?>


can i send any data to the child page this way?

--
What's the point in running when the light at the end of the tunnel iz
just another train...
Jul 23 '05 #5

P: n/a

This site has an example php script you can use:
http://www.edoceo.com/creo/php-redirect.php
will try this... thanks

FYI: Another solution that is better than using javascript is to
output a meta redirect to the browser, this is a special HTML tag
that doesn't require javascript support.

this i tryed and it works... but can i send any data to the child page
this way?
--
What's the point in running when the light at the end of the tunnel iz
just another train...
Jul 23 '05 #6

P: n/a
"Sentinel" <su*****@elma.hr> kirjoitti
viestissä:d9**********@ss405.t-com.hr...
Kimmo Laine 17.6.2005 19:27:59 <d8**********@phys-news1.kolumbus.fi>
et*******************@Mgmail.com comp.lang.javascript Kimmo
"Sentinel" <su*****@elma.hr> kirjoitti
viestissä:d8**********@ss405.t-com.hr...
> 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 (php script is in javascript
> that is in body) and if so i will print out the url to wich the
> javascript must redirect the browser
>
>
> <body>
> <script language="javascript">
> window.location=<?php a lots of ifs thens and elses and finaly print
> "index2.php"; ?>
> </script>
> </body>
>
>
>
> everything works fine but he browser doesn't redirect...
>
> the page source shows
> <body>
> <script language="javascript">
> window.location=index2.php
> </script>
> </body>


Ditch the javascript and redirect with php directly
<?php header("Location: index2.php"); ?>


can i send any data to the child page this way?

Yes, via GET method.

<?php header("Location: index2.php?foo=1&bar=2"); ?>
Parameters foo and bar are now available to index2.php. Oh and I should
mention also, that the example I gave you works in most browsers, but the
standard says you need to always always include the entire address, and not
just the relative filename. In other words: always use
<?php header("Location: http://www.your-domain.com/path/to/index2.php"); ?>
and never ever use
<?php header("Location: index2.php"); ?> without the entire url.

I should also mention that header data must be sent before any output. You
can't print or echo anything before you've sent headers.

Copy & Follow-up to: comp.lang.php
--
"I am pro death penalty. That way people learn
their lesson for the next time." -- Britney Spears

et****************@5P4Mgmail.com
Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.