Monroe Monroe - 7 months ago 8
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:

http://localhost/PhpProject2/product_page.php?rest_id=3/area=Enfield.

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

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


I have so far done this:

if(isset($_GET['rest_id'])){
if(isset($_GET['rest_city'])){

$_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>window.open('product_page.php?rest_id=' . $GET['rest_id'] . '/area='put get here'','_self')</script>";


How or what is the best practice?

Answer

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

http://localhost/PhpProject2/product_page.php?rest_id=3&area=Enfield

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..

<?php
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;
header($url);
?>

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"????