Aldilno Jinjalo
Aldilno Jinjalo

Reputation: 31

How to trace the originated uri of an obtained $_GET object from a remote page?

Thousands of ?queries are listed in hundreds of html pages. When one of these queries is clicked and passed to a specific page:-

<?php 
      $obtained= $_GET['query']; 

How to trace the URI of where it came from and paste it here? :-

      file_get_contents(../folder_of_pages_contain_queries/originated_page.html);
?>

Upvotes: 1

Views: 257

Answers (1)

Sutandiono
Sutandiono

Reputation: 1750

Use $_SERVER['HTTP_REFERER'] in your second page to figure out where the request came from.

If you want to paste the contents in the second page, you can try:

if (isset ($_SERVER['HTTP_REFERER']) && ! empty ($_SERVER['HTTP_REFERER']))
{
    $contents = file_get_contents ($_SERVER['HTTP_REFERER']);
}

Here is an example:

file1.html:

Link 1: <a href="test.php?query=link1">link 1</a>
Link 2: <a href="test.php?query=link2">link 2</a>
Link 3: <a href="test.php?query=link3">link 3</a>

file2.html:

Link 1: <a href="test.php?query=link1">link 1</a>
Link 2: <a href="test.php?query=link2">link 2</a>
Link 3: <a href="test.php?query=link3">link 3</a>

test.php:

$query = $_GET['query'];
$referer = $_SERVER['HTTP_REFERER'];

Depending on your test cases:

  1. If user clicks on link 2 from file1.html, then the value of $query will be "link2", and $referer will be "file1.html".
  2. If user clicks on link 3 from file2.html, then the value of $query will be "link3", and $referer will be "file2.html".

Upvotes: 1

Related Questions