$_SERVER['HTTP_HOST'] as a variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JackTheKnife
Forum Newbie
Posts: 3
Joined: Sat Dec 19, 2009 8:08 am

$_SERVER['HTTP_HOST'] as a variable

Post by JackTheKnife »

What is different between:

$host = $_SERVER['HTTP_HOST'];

and

$host = "www.my-domain.com";

Somehow when I have to use first line then $_SESSION vars doesn't go through two different domains.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: $_SERVER['HTTP_HOST'] as a variable

Post by Jade »

You need to read this page in the php manual: http://www.php.net/manual/en/reserved.v ... server.php
JackTheKnife
Forum Newbie
Posts: 3
Joined: Sat Dec 19, 2009 8:08 am

Re: $_SERVER['HTTP_HOST'] as a variable

Post by JackTheKnife »

I know what $_SERVER['HTTP_HOST'] stands for, but why is not working properly when I have declared $host variable as $_SERVER['HTTP_HOST'] but it works when I have "hard coded"?

Once again, because looks like ppl are confused what I am asking about.

I have piece of code:

Code: Select all

//$host  = $_SERVER['HTTP_HOST']; //disabeld for testing

$host = "www.my-domain.com"; //dummy domain for testing 

$sql = "SELECT * FROM Items WHERE  LandingPageURL = '".$host."'";
               .......
$landingpage = $row["LandingPage"];
               ...........	

if ($landingpage==$host){
$_SESSION["pid"] = $product['id'];
$_SESSION["price"] = $product['price'];
               ...........

}

else {

echo "oops... wrong page";
}

Then I do POST form to the another site (domain) on this same server but all $_SESSION vars are empty when I have use $host = $_SERVER['HTTP_HOST'] instead of $host = "www.my-domain.com";
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: $_SERVER['HTTP_HOST'] as a variable

Post by Jade »

Sessions are unique to each domain. So if you're on abc.com and you have a session, then go to def.com the session information you had for abc.com is no longer available.
Post Reply