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

When Do AWS Credits Start Applying in an Organization?

I recently set up an AWS Organization, and one of my accounts has been part of it since last month. My question is: if...

Why is my new computer running so slow?

I purchased a prebuilt computer from ibuypower in 2022, and while it wasn't slow at first, it's now incredibly sluggish when doing simple tasks...

Could Email Be a Reliable Method for Data Transport in Censored Areas?

I'm living in a country where authorities actively try to block VPN usage. Recently, I thought of a backup method for organizing app operations...

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

OpenAI Token Calculator

This tool is a simple OpenAI token calculator, web-based utility designed to help you quickly estimate the number of tokens in your text when...

List Sorting Tool

Welcome to our innovative list ordering and management tool. This next-level platform enables you to sort a list of items in ascending or descending...

Sudoku Solver

Welcome to our free online Sudoku solving tool, an interactive platform for puzzle enthusiasts seeking a break from a Sudoku conundrum. This advanced platform...

Apply Image Filters To Image

Digital imagery in the modern world is all about reinforcing emotions and stories behind each photo we take. To amplify this storytelling, we are...

Add Watermark To Image

As the world is increasingly consumed by digital media, protecting your original images is paramount. We are thrilled to introduce you to our innovative...

CSV To Xml Converter

Welcome to our CSV to XML converter tool, a convenient and user-friendly solution for all your data conversion needs. This versatile tool on our...

Latest Posts

Latest Questions