I inserted the following code into a blank index.php file <?php header("Location: http://www.eselfhypnosis.com/self-help/"); ?> Now when I go to www.eselfhypnosis.com I get this message: Warning: Cannot modify header information - headers already sent by (output started at /home/eselfhyp/public_html/index.php:1) in /home/eselfhyp/public_html/index.php on line 2 Can anyone tell me what I'm doing wrong? I just want to redirect the main index file to my forum directory which is called "self-help" www.eselfhypnosis.com/self-help Thanks!
Have you got a carriage return before th <?php tag? The error message that you are seeing is because some html has already been output.
You may want to try this <?php/** * Place in a blank PHP page */// Change to the URL you want to redirect to$URL="http://www.example.com";header ("Location: $URL");?> HTML:
Welcome to Digital Point! Because a user can turn Javascript off or a browser might not be compatible. They can't argue a PHP-redirect since it is server side. It really isn't a hassle and in fact is quicker. With Javascript you have to have a full HTML page.. PHP needs 1 line.
I changed the code to what homer suggested Now when I go to www.eselfhypnosis.com I just get a bank page. I attached the index.php file to this post...am I suppost to have <html> and <head> tags? or should it be completly blank.
Totally blank page. The only code on the page should be the <?php ?> line. Having HTML code on the page (before the PHP redirect) will cause it to fail. I believe it is also good manners to put an exit statement after the redirect. Your whole file will be: <?php header("location:http://www.eselfhypnosis.com/self-help"); exit; ?> PHP:
To avoid the "headers already sent" errors you can add <?php ob_start(); ?> PHP: to the start of the page.
Make sure nothing is been send the use before calling this line. Sometime, a space char at the file header can do the effect