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/

2 Comments

  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

    Reply

Leave a comment