Feedback Form
Leads to Insight

Blog

Getting the current full URL in PHP

24
Mar
2010

Sometimes, you might want to get the current full URL in PHP. Here is how you do that.

Add the following code to a page:

function selfURL(){
if(!isset($_SERVER['REQUEST_URI'])){
$serverrequri = $_SERVER['PHP_SELF'];
}else{
$serverrequri =    $_SERVER['REQUEST_URI'];
}
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
return $protocol."://".$_SERVER['SERVER_NAME'].$port.$serverrequri;
}
function strleft($s1, $s2) {
return substr($s1, 0, strpos($s1, $s2));
}

You can now get the full URL using the line:

print(selfURL());

NOTE: This function works with Apache + IIS

Innovations Development Group

11
Mar
2010

A wordpress based corporate website to showcase the image and work IDG is doing for its clients.

Technology Used:

PHP, MySQL, WordPress

Schoolwale

10
Mar
2010

A web design and development initiative for membership based website for schools, students, parents, teachers all over India. It is custom social networking website bringing related users closer.

Technology Used:

PHP, MySQL, Custom CMS, Membership, Payment Gateway Integration, Social Networking

Embrace Activewear

10
Mar
2010

A web design and development initiative for selling band and bags under its own brand name.

Technology Used:

PHP, MySQL, Custom CMS, Shopping Cart, Payment Gateway Integration

Alcoholics Anonymous

10
Mar
2010

A web design and development initiative for Alocholics Anonymous Meetings in Australia. This site provides its users meeting information, donations and sells relevant literature.

Technology Used:

PHP, MySQL, Custom CMS

Special Order Flowers

10
Mar
2010

A web design and development initiative for selling flower bouquet online. This site collects RFQ and send flowers to the customers.

Technology Used:

PHP, MySQL, Custom CMS