Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.