jprazen Posted December 9, 2008 Share Posted December 9, 2008 Hey there! I'm a novice with PHP, and am trying to set up a simple script for an index.php page that will do the following: 1) Redirect to another URL 2) Include in the URL to that page a variable representing a keyword captured in the original URL. So to be clear, say someone clicked on an ad related to the keyword "hippo". They would be directed to http://mysite.com?kw=hippo. I'd then like the script to redirect them to: http://myothersite.com?s=hippo. I've tried to do it with the following, but I'm sure I've got the syntax screwed up somehow: <?php header("HTTP/1.1 301 Moved Permanently"); header("http://www.myothersite.com?s=<?=$_GET['kw']?>"); ?> Any suggestions? Thanks in advance for any help you can provide! Link to comment https://forums.phpfreaks.com/topic/136280-php-redirects-with-variables/ Share on other sites More sharing options...
trq Posted December 9, 2008 Share Posted December 9, 2008 <?php header("http://www.myothersite.com?s={$_GET['kw']}"); ?> Link to comment https://forums.phpfreaks.com/topic/136280-php-redirects-with-variables/#findComment-710943 Share on other sites More sharing options...
jprazen Posted December 10, 2008 Author Share Posted December 10, 2008 Thanks for the quick reply! I'm still getting the following error message: Warning: Cannot modify header information - headers already sent by (output started at /home/public_html/food/index.php:1) in /home/public_html/food/index.php on line 2 Thoughts? Link to comment https://forums.phpfreaks.com/topic/136280-php-redirects-with-variables/#findComment-710947 Share on other sites More sharing options...
jprazen Posted December 10, 2008 Author Share Posted December 10, 2008 Here's my "actual" code, if this helps: <?php header("http://www.lynxtrack.com/afclick.php?o=8103&b=mb7r2b7s&p=34832&l=1&s={$_GET['kw']}"); ?> Link to comment https://forums.phpfreaks.com/topic/136280-php-redirects-with-variables/#findComment-710948 Share on other sites More sharing options...
premiso Posted December 10, 2008 Share Posted December 10, 2008 View this http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Link to comment https://forums.phpfreaks.com/topic/136280-php-redirects-with-variables/#findComment-710951 Share on other sites More sharing options...
jprazen Posted December 10, 2008 Author Share Posted December 10, 2008 Hmmm... If I knew more about PHP that other post might have been more helpful. But as it is I still have no idea what is causing this error. The PHP code posted above is the only code in the file, so it's not that I'm trying to process something before using the header() function. And there's no whitespace or missing characters in my code. Please pardon my novice status here. Thoughts on specifically what I might do to make it work? Link to comment https://forums.phpfreaks.com/topic/136280-php-redirects-with-variables/#findComment-710961 Share on other sites More sharing options...
premiso Posted December 10, 2008 Share Posted December 10, 2008 header Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file. Tells you all you need to know. Link to comment https://forums.phpfreaks.com/topic/136280-php-redirects-with-variables/#findComment-711008 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.