Jump to content

PHP Redirects With Variables


jprazen

Recommended Posts

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

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?

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.