Reading GET Variable Values Without Knowing The Variable Name / Key

I recently ran into an issue where I needed the values from GET variables, but I did not know what the variables name was. The problem was related to the Facebook API. The API used PHP to get the current URL, but the current URL was rewritten using Apaches Mod Rewrite, making it an invalid URL (technically). To overcome this I needed a way to regenerate the URL of the page without knowing how many GET variables there were going to be and what they would be called. After a bit of messing around this is what I came up with.

E.G. You have a rewritten URL that looks like the following
http://example.net/page/123/345.html

This URL works with Apache, but it is not a proper URL that another website can understand without having the information to map the variable names.  The code snippet below will take a URL that you have rewritten using mod rewrite or any other method and output it as a URL with the GET variables present.

You will need to replace the name of the URL to the url of your website. If you run this on any page it will generate the full URL of your page.

http://example.net/page/123/345.html   =>   http://example.net/page.php?var1=123&var2=345

$filename = $_SERVER['PHP_SELF'];
$url = $filename;
if(isset($_GET))
{
  $url = $url."?";
  $counter = 0;
  foreach($_GET as $var => $value)
  {
    if($counter != 0)
    {
      $url = $url."&";
    }
    $url = $url."&".$var."=".$value;
    $counter ++;
  }
}
$currentUrl = "http://example.net".$url;

Related Articles

Related Questions

Who’s Using Customer Managed Keys for Disk Encryption in Azure?

Hey everyone! I'm looking to hear from anyone using Customer Managed Keys (CMKs) for encrypting OS and data disks in Azure VMs. What has...

How Can I Analyze OneDrive Storage Usage with PowerShell and Microsoft Graph?

Hey everyone! I've got a 9 TB OneDrive, and I'm trying to figure out which files are taking up the most space. For instance,...

Which CPU is better for gaming and multitasking: 7700x or 14600k?

I'm stuck choosing between the 7700x priced at $215 and the 14600k which is going for $179 and comes with a free 1TB SSD....

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Latest Tools

Online Hash Generator – String to Hash Converter

Need to quickly generate a hash from a string? Whether you're verifying file integrity, securing data, or just experimenting with cryptographic tools, this simple...

Convert CSV To HTML Table

Need to quickly turn CSV data into an HTML table? Whether you're copying data from Excel, Google Sheets, or another spreadsheet, this tool makes...

Student Group Randomizer

Creating fair and balanced groups in the classroom can be time-consuming — especially when you're trying to avoid repetition, manage different skill levels, or...

Random Group Generator

Need to split a list of people, items, or ideas into random groups? Our free Random Group Generator makes it quick and easy. Whether...

Flip Text Upside Down – Free Online Tool

Ever wanted to flip your text upside down just for fun or to grab someone’s attention in a creative way? This free online Upside...

Raffle Ticket Generator

If you're running a fundraiser, charity draw, or local event and need raffle tickets fast, this free online tool lets you generate and print...

Latest Posts

Latest Questions