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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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