Redirect

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
guerillacity
Forum Newbie
Posts: 7
Joined: Wed Aug 06, 2008 3:04 pm

Redirect

Post by guerillacity »

is it possible to put a redirect in a function because i get an error when i try:

Code: Select all

function SrtringToLong()
              {   
                              
                    header( 'Location: http://www.php.net' ) ;
                 
                   exit(); 
              }
JB4
Forum Commoner
Posts: 33
Joined: Tue Jul 22, 2008 6:07 pm
Location: Utah

Re: Redirect

Post by JB4 »

On their website it says this:

Code: Select all

 
<?php
header("Location: http://www.example.com/"); /* Redirect browser */
 
/* Make sure that code below does not get executed when we redirect. */
exit;
?>
 
 
only differences I notice are:
" instead of '
exit; instead of exit();

I'm not very smart, but I figured I'd tell you what I saw.
xitura
Forum Newbie
Posts: 20
Joined: Fri Sep 07, 2007 11:25 am

Re: Redirect

Post by xitura »

What error message do you get?
guerillacity
Forum Newbie
Posts: 7
Joined: Wed Aug 06, 2008 3:04 pm

Re: Redirect

Post by guerillacity »

i get: Warning: Cannot modify header information.
xitura
Forum Newbie
Posts: 20
Joined: Fri Sep 07, 2007 11:25 am

Re: Redirect

Post by xitura »

That error message is displayed when you have output (anything displayed in the screen + blank spaces and newlines) before the header-function is called.
guerillacity
Forum Newbie
Posts: 7
Joined: Wed Aug 06, 2008 3:04 pm

Re: Redirect

Post by guerillacity »

Cheers i got rid of all the white space even before the first php open.

Works Prefectly. THANKS ALL.
Post Reply