Monroe Monroe - 1 year ago 37
PHP Question

Make a $_GET into variable or place into URL

How do you place a $_GET['****']; into a string or make it into a variable.
For Example i have this url:


I want to get the area and rest_id from the url. in order to redirect another page to this exact page.

echo"<script>'product_page.php?rest_id= 'put get here'/area='put get here'','_self')</script>";

I have so far done this:


$_GET['rest_id'] = $rest_id;

This obviously does not work, so my question is how do i make the 2 $_GET into a variable or call the $_GET into the re-direct string.

What i have tired so far

echo"<script>'product_page.php?rest_id=' . $GET['rest_id'] . '/area='put get here'','_self')</script>";

How or what is the best practice?

Answer Source

ok, first things first. in your URL you have to separate the parameters using an ampersand "&", like this


Also, you have to assign the $_GET value to a variable, not the other way around, like this

$rest_id = $_GET['rest_id'];

so if you create a PHP file named product_page.php and use the url i gave you, and your PHP code looks like this, it should work..

if (isset($_GET['rest_id'])){
    $rest_id = $_GET['rest_id'];

if (isset($_GET['rest_id'])){
    $area = $_GET['area'];

$url = 'other_page.php?rest_id=' . $rest_id . '&area=' . $area;

The question here is why do you want to redirect from this page to the other, and not send the parameters directly to the "other_page.php"????