Reputation: 163
With PHP, I have a script that searches for an email from a mysql_db then takes a username from the same row as the email in the db. What I want it to do is redirect using the username as a subdomain in the url
I've tried:
$username = //username taken from the db
$url = 'http://".$username."domain.com';
header('location: $url');
This just appends the variable "$url" to the end of my test url.
and I've tried:
header('http://".$username."domain.com');
This outputs in the adress bar:
http://%22.%24account_name.%22.domain.com
How can use this search result variable and redirect to the subdomain I am looking for?
Upvotes: 0
Views: 116
Reputation: 6147
This will work
$username = //username taken from the db
$url = "http://$username.domain.com";
header("Location: $url");
Upvotes: 0
Reputation: 140230
Simply use double quotes
$url = "http://{$username}.domain.com";
header("Location: {$url}");
Upvotes: 1
Reputation: 219824
You have syntax errors galore.
Version 1 corrected (variables in single quotes are treated as literal strings):
$username = //username taken from the db
$url = 'http://".$username."domain.com';
header('location: ' . $url);
Version 2 corrected (Your syntax and quote usage are both wrong):
header("Location: http://".$username."domain.com");
Upvotes: 2