PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, January 18, 2022

[FIXED] How do I capture the whole URL using PHP?

 January 18, 2022     html, php, url     No comments   

Issue

I would like to the whole of the URL including the _GET variable names and values, for example www.mywebsite.com/store.php?department=MENS

The code I have used below only gives me the URL without the _GET variable part.

$url = $_SERVER['SERVER_NAME']; 
$page = $_SERVER['PHP_SELF'];
$page = $_POST['url'];
echo "http://".$url.$page; 

All I would like is to be able to copy that URL exactly how it is.


Solution

try this function

  public function getURL()
     {
        $protocol = @$_SERVER['HTTPS'] == 'on' ? 'https' : 'http';

        return  $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
     }

taken from [this article I wrote][1]

use it like

echo getURL();

see if works for you [1]: http://jaspreetchahal.org/how-do-you-get-current-browser-url-with-php/



Answered By - Jaspreet Chahal
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing