Jump to content

Problem with if Statement


advancedfuture

Recommended Posts

So here is my delimma. I setup wildcard subdomains on my server.

 

My subdomain format is county.state.mydomain.com

 

I'm matching the subdomains against my database, to ensure it is a valid combo, if it isn't it should redirect to the main page 'www'. Problem is my if statement is not working as it should... if I enter lets say... ilovebats.ca.mydomain.com it runs the query no problem, but doesn't execute the header statement in my IF statement... which leads me to beleive i malformed the if statement.

 

Any help would be appreciated.

 

<?php
//Get what subdomain we are on. strip the county and state variables
//from the URL, and if it is www, set it to Orange County, CA
include 'dbconnect.php';
$domain = explode('.',str_replace("mydomain.com"," ",$_SERVER['SERVER_NAME']));
$county = $domain[0];
$state = $domain[1];

//This variable is used for displaying the county without the slashes
$county_slash = str_replace("-"," ",$county);

//If we are on the root of the domain, set the variables to Orange County, CA
if ($county == "www")
{
$county = "Orange";
$state = "CA";
}

//Check to make sure subdomain is valid. If not redirect to www
else
{
$query = "SELECT * FROM `zip_code` WHERE county='$county' AND state_prefix='$state'";
$results = mysql_query($query);
if($results == 0)
{
	header('LOCATION: http://www.mydomain.com');
	exit;
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/183631-problem-with-if-statement/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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