Reputation: 31
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
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:
link 2
from file1.html
, then the value of $query
will be "link2", and $referer
will be "file1.html".link 3
from file2.html
, then the value of $query
will be "link3", and $referer
will be "file2.html".Upvotes: 1