Base Url Custom Function in PHP

Hello,
i have created a custom function for printing the base url (url up to the current file from the server name).
here you can try .

 

public function base_url(){
$this->base_url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
return 'http://'.$this->base_url;
}

 

Usage:

<a href="<?php echo 'base_url();' ?>"> this is base url </a>

 

Prints:
(if your site running in server)
http://www.your-domain-name.com/

(if your site running in localhost)
localhost/your-project-folder-name/

Advertisements

2 thoughts on “Base Url Custom Function in PHP

  1. I read a lot of interesting posts here. Probably
    you spend a lot of time writing, i know how to save
    you a lot of time, there is an online tool that creates unique,
    SEO friendly articles in minutes, just search
    in google – laranitas free content source

    Like

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