Redirecting

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

elitecodex
New php-forum User
New php-forum User
Posts: 68
Joined: Tue Jul 09, 2002 8:45 am
Location: East Coast, USA
Contact:

Redirecting

Postby elitecodex » Tue Jul 09, 2002 8:49 am

I am having a problem getting my PHP scripts to redirect. This is what I use:

Code: Select all

header("Location: http://www.mydomain.com");
exit();


or something of that nature. The script just halts and doesnt do anything. What am I doing wrong? Any help is greatly appreciated. Thanks

Will

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Re: Redirecting

Postby WiZARD » Tue Jul 09, 2002 10:32 pm

elitecodex wrote:I am having a problem getting my PHP scripts to redirect. This is what I use:

Code: Select all

header("Location: http://www.mydomain.com");
exit();


or something of that nature. The script just halts and doesnt do anything. What am I doing wrong? Any help is greatly appreciated. Thanks

Will


Hi!
In manual some peaple wrote:
Make sure that code below does not get executed when we redirect.
Try change your:

Code: Select all

header("Location: http://www.mydomain.com");
exit();

at the

Code: Select all

header("Location: http://www.mydomain.com");
exit;


Maybe this helped to you 8)

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Wed Jul 10, 2002 12:53 am

This code must be in beginnig of the page...

TRUE!

Code: Select all

<?
header("Location: http://www.mydomain.com");
exit();
?>
<html><body></body></html>
 



FALSE!

Code: Select all

<html><body></body></html>
<?
header("Location: http://www.mydomain.com");
exit();
?>

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Re: Redirecting

Postby WiZARD » Wed Jul 10, 2002 1:09 am

Main that after

Code: Select all

exit;
no more present enything else code...
Pejone right!

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Wed Jul 10, 2002 1:20 am

=)

elitecodex
New php-forum User
New php-forum User
Posts: 68
Joined: Tue Jul 09, 2002 8:45 am
Location: East Coast, USA
Contact:

Redirecting - Still having problems, but narrowed it down

Postby elitecodex » Wed Jul 10, 2002 5:00 am

I managed to get some of my scripts to work. They only seem to not redirect when I include a certain file. This file is nothing but full of functions that help layout my page (Link Here) . I have checked and double checked, and have not seen anywhere where I put any kind of output (Unless certain functions are specifcally called). You will notice that I also include another page where I keep my stats (Link Here). Again, I dont see how I output anything. What else is keeping my pages from redirecting? I have tried all the before-mentioned ideas, same result. I thank everyone for any help in advance.

Will

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Re: Redirecting - Still having problems, but narrowed it dow

Postby WiZARD » Wed Jul 10, 2002 6:27 am

elitecodex wrote:I managed to get some of my scripts to work. They only seem to not redirect when I include a certain file. This file is nothing but full of functions that help layout my page (Link Here) . I have checked and double checked, and have not seen anywhere where I put any kind of output (Unless certain functions are specifcally called). You will notice that I also include another page where I keep my stats (Link Here). Again, I dont see how I output anything. What else is keeping my pages from redirecting? I have tried all the before-mentioned ideas, same result. I thank everyone for any help in advance.

Will


You can make redirect via HTML I dont remeber how, but somthing like this:

Code: Select all

base=<linkmake>
refresh=0


That is this?

Code: Select all

  $returnValue = $returnValue . "<table border="0" cellpadding="0" cellspacing="0" style="width: 100%">";
        $returnValue = $returnValue . "<tr><td style="text-align: center; font-weight: 600; font- size: smaller; background-color: #DDDDFF; color: #000000;">Battle Poll</td></tr>";
        $returnValue = $returnValue . "<tr><td style="font-size: smaller;">What feature would you like to see next on BattlePages.com?</td></tr>";
        $returnValue = $returnValue . "<tr><td>&nbsp;</td></tr>";
        $returnValue = $returnValue . StartMyPoll_ShowResults("next_feature", "VE Manager", "nf_vem", $ref)

Why you using variables like that:

Code: Select all

$setVar= $seVar."bla, bla, bla";

or you have very powrfull server?
most programmer not using thats princeples.

If i write some site lake this, i'm using templates

elitecodex
New php-forum User
New php-forum User
Posts: 68
Joined: Tue Jul 09, 2002 8:45 am
Location: East Coast, USA
Contact:

Postby elitecodex » Wed Jul 10, 2002 6:51 am

Sorry, but as I said before, Im kinda new to this web programming envirnoment. I just started coding and didnt really think of any other options (Lack of planning). The site seems to run fine for right now, but if performance becomes an issue, i will definately change it.

Did you happen to see anything in there that would stop a redirect from working though? Im still stomped on that.

Thanks

Will

khote
New php-forum User
New php-forum User
Posts: 7
Joined: Tue Jul 23, 2002 6:15 am
Location: San Bernardino, Ca, USA
Contact:

Postby khote » Tue Jul 23, 2002 6:33 am

If you are using mixed html-php in the manner of:
<HTML>
.... more html stuff
<?php
.... more php stuff
header("Location: http://www.somehwere.com");
exit;
?>

It will likely fail. header is a function that puts things out in the http header, and php will not allow you to put out header stuff after it has already finished with it. This is true for cookies as well, any output that has already occurred will cause a problem in these situations.

One thing I use is ob_start(): see http://www.php.net/manual/en/function.ob-start.php

This way php will buffer all output before sending it. You can then add header information.

<?php ob_start() ?>
<HTML>
.....
<?php
header("Location: http://www.somwhere.com");
exit;
?>

PS: Make sure that you do it in this manner:
<?php ob_start(); .... ?>
and NOT in this manner:
<?php
ob_start();
....
?>
and also make sure it is the very first line in whatever file you are using it in.


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google Feedfetcher and 3 guests

cron