Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Get the Current Page URL

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 37
    Comment on it

    To get the current page url please check the below php script.

    In the below script we define a function named as currentPageURL( ). Then we have created a variable named as $PageURL having value http. Now we are using the PHP superglobal varriable named as $_SERVER[SERVER_PORT]. This variable always return the current port of your server.


    Now we are checking if the port number of our server is 80 that indicates that we are using local server. then we can get the server name using variable $_SERVER[SERVER_NAME]and at the same time we can get page url using the variable $_SERVER[REQUEST_URI] and then we can assign easily this value to the defined $PageURL variable.


    So now whenever we hot the function then $PageURL returns name of server, port and url. so for displaying this we just call our function when we require.

    Here is the script -

    <?php
    
     function currentPageURL()
    
     {
    
     $PageURL = 'http';
    
     if ($_SERVER["HTTPS"] == "on")
    
     {
    
     $PageURL .= "s";
    
     }
    
     $PageURL .= "://";
    
     if ($_SERVER["SERVER_PORT"] != "80")
    
     {
    
      $PageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    
     }
    
     else
    
     {
    
      $PageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    
     }
    
     return $PageURL;
    
    }
    
    ?>
    

    Call the above function like below.

    <?php
    
    echo currentPageURL();
    
    ?>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: