- Welcome to Geeksww.com
PHP Useful functions (Part 2) - The currentURL function
Developing websites, social applications, and scripts in PHP for more than 6 years now, I found a number of utility functions helpful in development. I am going to write a series of tutorials writing such functions and describing their use. Using these functions I have created a library of dynamically loadable classes but you are free to use them as you wish.
The currentURL Function:
I am going to discuss the currentURL function here. Here is the function header:
function currentURL()
As can be seen the function takes no arguments but only returns the URL of the web page.
Usage:
I use this function wherever I need the URL of the current page. One example is the social bookmark links.
Function Definition:
Here is the definition of the function,
function currentURL() { return "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; }
Note: this function does not give you the query string. It just gives you the URL. If you want the query string too then append the following variable in the URL.
$_SERVER['QUERY_STRING']
Did this tutorial help a little? How about buy me a cup of coffee?
Please feel free to use the comments form below if you have any questions or need more explanation on anything. I do not guarantee a response.
IMPORTANT: You must thoroughy test any instructions on a production-like test environment first before trying anything on production systems. And, make sure it is tested for security, privacy, and safety. See our terms here.
tags cloud
popular searches
free download for mysql database server 5.1.5, bison, gearman, source code, php, install cairo, java, laptop, mysql, linux, install mysql, mysql mysql, mysql initialization, tools, ubuntu
Similar Tutorials:
- Download all Aspersa MySQL tools/scripts through a single command
- Installing Gearman shared PECL extension for PHP on Debian/Ubuntu Linux
- Decoding XML String Values (PHP version)
- Simple Coding Style for PHP - Part 2/2
- Installing Symfony using PEAR
Tutorials in 'Web Development > PHP' (more):
- Generating prime nos in PHP using multiprocessing - Geaman with PHP client Part I
- PHP Useful functions (Part 1) - The inRange function
- Generating Unique IDs in PHP
- How to check PHP version number?
- Installing Symfony using PEAR
Comments (write a comment):
I've implemented the same currentURL() function to create a more advanced script @ http://www.2lessons.info/2012/09/facebook-type-extract-url-data-using.html Posted by: 2lessons on Sep 30, 2012
leave a comment