php redirect question

8 replies
hey guys I have been using this code

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://myhoplink.net/");
exit();
?>

I have usually used this successfully until now. I am trying to do it for a new site and I get this error: Warning: Header may not contain more than a single header, new line detected. in /home/homesuc1/public_html/fat-burning-tips.com/fatburningfurnace.php on line 4

I am not doing anything different, so why is it not working?:confused:
#php #question #redirect
  • Profile picture of the author GeorgR.
    why do you have that 301 in there? I have never seen a PHP redirect with two header lines, its simply

    <?php
    header("Location: http://myhoplink.net/");
    ?>

    thats how i do it for ages Maybe that some obsolete ways to use which doesnt work anymore with newer PHP..my guess...
    Signature
    *** Affiliate Site Quick --> The Fastest & Easiest Way to Make Affiliate Sites!<--
    -> VISIT www.1UP-SEO.com *** <- Internet Marketing, SEO Tips, Reviews & More!! ***
    *** HIGH QUALITY CONTENT CREATION +++ Manual Article Spinning (Thread Here) ***
    Content Creation, Blogging, Articles, Converting Sales Copy, Reviews, Ebooks, Rewrites
    {{ DiscussionBoard.errors[1595004].message }}
    • Profile picture of the author AnnaHamer
      Originally Posted by GeorgR. View Post

      why do you have that 301 in there? I have never seen a PHP redirect with two header lines, its simply

      <?php
      header("Location: http://myhoplink.net/");
      ?>

      thats how i do it for ages Maybe that some obsolete ways to use which doesnt work anymore with newer PHP..my guess...
      thanks! Worked a treat! I don't know why that code works for my other sites and not this one.
      {{ DiscussionBoard.errors[1595052].message }}
  • Profile picture of the author AnnaHamer
    Originally Posted by ProductCreator View Post

    Maybe a dumb question but is fat-burning-tips.com your site?
    Yes it is. Planning on doing it up and flipping it.
    {{ DiscussionBoard.errors[1595043].message }}
  • Profile picture of the author Forest_Parks
    It's similar to the code I always use:

    <?php header( "HTTP/1.1 301 Moved Permanently" );
    header('Location: http://intended-address.com'); ?>


    As you see I don't have the exit code.
    {{ DiscussionBoard.errors[1595045].message }}
    • Profile picture of the author AnnaHamer
      Originally Posted by Forest_Parks View Post

      It's similar to the code I always use:

      <?php header( "HTTP/1.1 301 Moved Permanently" );
      header('Location: http://intended-address.com'); ?>


      As you see I don't have the exit code.
      My guess is, I am always cutting and pasting it; it must have gotten jumbled up.
      {{ DiscussionBoard.errors[1595063].message }}
  • Profile picture of the author CliveG
    Your original version should work and is preferable becuase it sends a 301 code rather than 302.

    Watch out for empty lines and spaces between PHP open and close tags. PHP does not ignore them.
    {{ DiscussionBoard.errors[1595128].message }}
    • Profile picture of the author AnnaHamer
      Originally Posted by CliveG View Post

      Your original version should work and is preferable becuase it sends a 301 code rather than 302.

      Watch out for empty lines and spaces between PHP open and close tags. PHP does not ignore them.
      I've just been double checking, and the new .php files I am doing were identical, apart from the hop links. Looked for spaces, and there weren't any. I am baffled why it wasn't working.
      {{ DiscussionBoard.errors[1595159].message }}

Trending Topics