PHP manage user dependent pages – Apache create virtual host

Posted: September 18, 2012 in PHP
Tags: , ,

For testing purpose add host entry in windows.

Open C:\Windows\System32\drivers\etc\hosts fiel and add below code at bottom of file.

127.0.0.1 myprofile.com
127.0.0.1 john.myprofile.com
127.0.0.1 lisa.myprofile.com
127.0.0.1 mathew.myprofile.com

 

Add below code in apache httpd.conf file.

DocumentRoot "d:/wamp/www/"
<VirtualHost 127.0.0.1>
ServerName www.myprofile.com
DocumentRoot d:/wamp/www/inhouse-demo/myprofile/
</VirtualHost>

 

Once all done restart wamp & clear browser cache.

Now when you open http://myprofile.com it will redirect to your project home page.

Same way with http://john.myprofile.com and http://mathew.myprofile.com.

Now you can add below php code on top of your php file.

$domain = $_SERVER['HTTP_HOST'];
$subdomain = substr($domain, 0, strpos($domain, '.'));

Now use subdomain variable and check in database for user dependent data.

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s