Is it safe to read a value from an URL with parse_url?

440 Views Asked by At

For some reason I can't get the $_GET variable to do anything so I used a work around by just modifying the URL with a string at the end with a ? and reading that into my code with the parse_url function and now I wanted to ask if that is a stupid fix in any way and if I should not do that.

example on how I did it

$url = "http://website.com/page?value";

$token = parse_url($url, PHP_URL_QUERY);

So In the end I just get the value inside $token

1

There are 1 best solutions below

3
thirumal mani L On

You need to change the url like this: http://website.com/page=5

Then get the value using below format:

echo "page value" . $_GET['page'];

if you want to pass more than one variable: http://website.com/page=5&id=1

echo "page value" .  $_GET['page'] .''.$_GET['id'] ; 

I hope this answer will be helpful for you.