Re: Redirecting in a PHP script
| From: | Haydar Tuna | Date: | Tue, 13 Mar 2007 06:03:00 +0000 |
| Subject: | Re: Redirecting in a PHP script | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-250393@lists.php.net to get a copy of this message | ||
Hello,
In my many projects, I have used PHP header function for redirecting
any URL so you can use like a following command. I haven't got any problem
with this command until now :)
header("Location: http://www.domain.com");
--
Haydar TUNA
Republic Of Turkey - Ministry of National Education
Education Technology Department Ankara / TURKEY
Web: http://www.haydartuna.net
"Larry Bradley" <lhbradley@igs.net> wrote in message
news:5.2.0.9.2.20070312145034.02a096a0@mailbox.ott.igs.net...
>I need to "goto" different PHP pages in my web site depending on what
> happens within some PHP code.
>
> For example, if the user is not logged in when he goes to a page, I want
> to
> send him to a LOGIN page.
>
> I've have everything working fine, using the following Javascript code:
> $location = 'login.php';
> echo "<script language='javascript'>\n";
> echo "document.location.href = '" . $location .
"';\n";
> echo "</script>\n";
>
> I also played around with using the header("location: ...") function.
>
> I understand that the header() function must be issued before any HMTL is
> output.
>
> But I'm not sure about the Javascript code. In every instance in my code,
> I
> use the Javascript before any HTML - this type of action normally occurs
> in
> PHP code called via a form POST.
>
> I presume that the Javascript code really does the same as the PHP stuff,
> and thus must obey the same rules, but I'm not sure.
> Comments?
>
> Larry Bradley
> Orleans (Ottawa), Ontario, CANADA