AyDee AyDee - 17 days ago 6
PHP Question

Get the current inputed value parameter (PHP)

How can I get the current inputed value of my parameter in url?
for example this is my url

"**www.example.com/register?redirect=**"


when I input a value in the redirect parameter for example is

https://www.google.com


how can I get that value of redirect?

Answer

The above comments are correct, but I wanted to take a second to explain why and provide some useful links.

$redirect = (isset($_GET['redirect'])) ? $_GET['redirect'] : false

Through this superglobal, you can access any parameter included in the URL. The values passed to you through this are urlencoded. YOu can read more about it here

What we did in the code above is this: - Check if the redirect param hasbeen filled (you could aso just use empty() below ) - Assign the redirect value to our $redirect variable if it is set, otherwise assign it false.

Using that, you can redirect the user there if it's set:

if($redirect) {
  header("Location: ".$redirect);
}

The downvote above isn't mine, but this isn't such a great question. I understand that you are new to the network, and everyone has to start somewhere. Please try to make sure you include code samples and do a bit of research yourself prior to your next question on SO.