Forum Moderators: coopster

Message Too Old, No Replies

Noob Alert: I want to put a variable in my header redirect.

         

wariental

3:41 am on Mar 14, 2009 (gmt 0)

10+ Year Member



Hi guys. I want to create something really simple here.

I have a URL that looks like this

example.com/example/?w=keyword

Now... example.com/example/ only contains an index.php file with a header redirect. I want the header to grab ?w and append it to the end of the url.

Something like this (obviously this doesn't work because I am a PHP super noob)

<?php
$page = $_GET['w'];
$url = 'http://www.example.com/test/example.html&sub=$page';
header( 'Location: $url' ) ;
?>

Basically I want the header to redirect to

http://www.example.com/test/example.html&sub=keyword

Keyword being the variable.

I tried searching around but quickly got lost in 10x more complex looking problems.

Hope someone can help me here.

Thank you!

eelixduppy

4:50 am on Mar 14, 2009 (gmt 0)



The only reason it doesn't work is because you are using single quotes. Try double quotes or string concatenation.

$url = "http://www.example.com/test/example.html&sub=$page";

More information on php strings here: [php.net...]

g1smd

10:24 pm on Mar 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your redirect is a 302 redirect. You will probably need to change that to be a 301 redirect:

header("Location: " . $url,TRUE,301);

eeek

10:09 pm on Mar 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your redirect is a 302 redirect. You will probably need to change that to be a 301 redirect:

Why?