Forum Moderators: coopster

Message Too Old, No Replies

header('Location: *variable*'); question

How do I redirect to a variable URL

         

Karma

3:20 pm on Apr 20, 2009 (gmt 0)

10+ Year Member



Hi

Probably a really simple question/answer:

I'd like to redirect to a URL that is stored in a variable named $newurl, but I'm having problems doing so:

<?php

$newurl = "http://www.mydomain.tld/";
header('Location: $newurl');

?>

Anyone?

whoisgregg

3:57 pm on Apr 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Variables are not parsed when they are inside single quotes. So, you can either use variable concatenation or use double quotes. Personally I prefer the first choice:

header('Location: '.$newurl); // variable concatenation
header("Location: $newurl"); // variables are parsed inside double quotes