开发者

PHP - dynamic page via subdomain

开发者 https://www.devze.com 2022-12-27 08:12 出处:网络
im creating profile pages based on a subdomains using the wildcard DNS setting. Problem being, if the subdomain is incorrect, I want it to redirect to the same page but without the subdomain infront

im creating profile pages based on a subdomains using the wildcard DNS setting.

Problem being, if the subdomain is incorrect, I want it to redirect to the same page but without the subdomain infront ie;

if ( preg_match('/^(www\.)?([^.]+)\.domainname\.co.uk$/', $_SERVER['HTTP_HOST'], $match)) {

$DISPLAY_NAME = $match[2];
$query = "SELECT * FROM `" . ACCOUNT_TABLE . "` WHERE DISPLAY_NAME = '$DISPLAY_NAME' AND ACCOUNT_TYPE = 'premium_account'";
$q = mysql_query( $query, $CON ) or die( "_error_" . mysql_error() );

if( mysql_num_rows( $q ) != 0 ) {



}else{

    mysql_close( $CON );
    header("location: http://www.domainname.co.uk");
    exit;

}

}

I get a browser error: Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

I think its because开发者_如何学运维 when using header("location: http://www.domainname.co.uk"); it still puts the sub domain infront i.e. ; header("location: http://www.sub.domainname.co.uk");

Does anyone know how to sort this and/or what is the problem.

Regards,

Phil


This happens when a webpage redirects you in an endless loop. So probably the page you are referring too is also sparking a referral (or firefox thinks it is).

Mozilla knowledge base explains what you can do about this error.


Figured this one out. It was due to the browser caching.

header("Expires: Mon, 01 Jul 2003 00:00:00 GMT"); // Past date
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Consitnuously modified
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Pragma: no-cache"); // NO CACHE
header("location: http://www.domainname.co.uk");

did the trick.

0

精彩评论

暂无评论...
验证码 换一张
取 消