IS there any way to add HTML before; <?php header( 'Location: http://www.yoursite.com/new_page.html' ) ; ?> ???????
You can add html before this tag. I have used it many time if you are getting error - "header already sent" , cause of that error is some other thing. Plz paste your code here so i can help
Im pretty certain you cant put: <?php header( 'Location: http://www.yoursite.com/new_page.html' ) ; ?> after HTML, as that redirect is processed before anything is outputted to the browser (even the HTML beforehand). That is why you get the headers already sent message.
You can if you use ob_start() at the start of your page. However, it is not recommended as this will increase your overhead. If you have ever output HTML before header(), it is advisable to re-design your logic flow.
<script language="javascript"> var ref = escape(document.referrer)+" "; var entry = escape(unescape(location.href)); document.write( '<' + 'script language="javascript" src="http://www.linksjuice.com/axroi/script.php?ref=' + ref + '&entry=' + entry+ '"><' + '/script>' ); </script> <?php header( 'Location: http://www.linksjuice.com' ) ; ?> Code (markup): That's ideally how i'd like it to be so it runs the js, and has SE friendly redirect.. Someone else told me about ob_start() but i don't get it
How things are performed: Client browser requests your URL. Your HTTP server must return a HTTP status code. If it is a redirect code (3xx value), there is no room for any HTML output. So the code header( 'Location: http://www.yoursite.com/new_page.html' ) ; PHP: will return 302 redirect HTTP status code, and header function is not allowed after any output. So you can try to: 1. Perform redirect via javascript (but it will be not SEO-friendly): window.location = "http://www.yoursite.com/new_page.html" HTML: 2. Perform redirect via META REFRESH html tag (not SEO-friendly): <meta http-equiv="Refresh" content="0; url=http://www.yoursite.com/new_page.html"> HTML: 3. Change your processing logic
Thanks for the tips, but i was hoping if i could get this to be se friendly... I've got; <?php ob_start(); ?><script language="javascript"> var ref = escape(document.referrer)+" "; var entry = escape(unescape(location.href)); document.write( '<' + 'script language="javascript" src="http://www.linksjuice.com/axroi/script.php?ref=' + ref + '&entry=' + entry+ '"><' + '/script>' ); </script> <?php Header( "HTTP/1.1 301 Moved Permanently" ); header( 'Location: http://www.linksjuice.com' ) ; ob_end_flush(); ?> Code (markup): But now it seems to skip the js
As I said before - no html processing will be performed by browser with header("Location") call. ob_start just starts output capturing and your code can be rewritten without ob_start as: <?php header( 'Location: http://www.linksjuice.com' ) ; ?> <script language="javascript"> var ref = escape(document.referrer)+" "; var entry = escape(unescape(location.href)); document.write( '<' + 'script language="javascript" src="http://www.linksjuice.com/axroi/script.php?ref=' + ref + '&entry=' + entry+ '"><' + '/script>' ); </script> PHP: But it does not solve problem. Browser does not process additonal html if http redirect instruction found.