Monday, November 18, 2013
PHP URL Getting Methods
Monday, November 18, 2013 by Unknown
Hiiiii, while developing php projects, we sometimes encounter a problem to redirect your page to next page and redirecting it to the previous requesting page or anyother pages then you want the url of the page on which you want to redirect. Sometimes it is needed to to get the host names, server names etc. So, in this post I'll be telling you many url redirection method in this post.
CODE EXAMPLE BEGINS :
<?php
echo getcwd() . "</br>";
// Returns Full path in Root Directory
Example - /var/www/test/redirections_url
echo $_SERVER['PHP_SELF']. "</br>";
// Returns Full path in your WWW or Htdocs Directory
Example - /test/redirections_url/test.php
echo $_SERVER['DOCUMENT_ROOT']. "</br>";
// Returns Full path in Root Directory to your WWW or Htdocs Directory
Example - /var/www
echo $_SERVER["REQUEST_URI"]. "</br>";
// Returns Full path in your WWW or Htdocs Directory same as $_SERVER['PHP_SELF']
Example - /test/redirections_url/test.php
echo $_SERVER["SERVER_NAME"]. "</br>";
// Returns your Hostname or Server Name
Example - localhost
echo $_SERVER['HTTP_HOST']. "</br>";
// Returns your Hostname or Server Name
Example - localhost
echo $_SERVER['REMOTE_ADDR']. "</br>";
// Returns IP Address of the person accessing your page
echo dirname($_SERVER['PHP_SELF']). "</br>";
// Returns Full path in your WWW or Htdocs Directory to current file URL
Example - /test/redirections_url/
echo "Complete Path - ".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
// return Complete URL to parent folder of the requesting page
echo $_SERVER['HTTP_REFERER'];
// Returns the path to the requesting urls
?>
Hope you like this post……..Please Comment…………!!!!!!!!!
Tags: PHP
Subscribe to:
Post Comments (Atom)
0 Responses to “PHP URL Getting Methods”
Post a Comment