-1

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

Patrick
  • 781
  • 2
  • 5
  • 23
  • That querystring looks incomplete. It should say `value=1` or something similar at the end. – ADyson Jun 23 '20 at 06:51
  • are you using `.htaccess` for `page` path? – Illya Jun 23 '20 at 06:52
  • 1
    What if you go to `http://website.com/page?value=1` (as @ADyson suggest) and `print_r($_GET);` on your page? – Patrick Jun 23 '20 at 06:54
  • 1
    _"I cant get the $_GET variable to do anything"_ - What are you expecting the $_GET-variable "to do"? – M. Eriksson Jun 23 '20 at 06:57
  • If I do that with the value=1 and all it doesn't work thats kinda why I did it the way I posted it here, and it works. My question was more if it brings any huge security risks or something similar to the table that I am not aware of – Gid Odir Watson Jun 23 '20 at 06:59
  • 1
    We can't answer that because we can't see what you're doing with the data afterwards. But $_GET should definitely work anyway, from what you've described, and is more efficient than having to hunt for the parameter within the array returned by parse_url. (And that's no more or less secure than what you've shown. It's what you do with it afterwards that might have an impact on security.) – ADyson Jun 23 '20 at 07:03

1 Answers1

0

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.

ADyson
  • 57,178
  • 14
  • 51
  • 63
thirumal mani L
  • 164
  • 1
  • 5
  • Can you get `$_GET` variables without having `?` as a starting guideline? I didnt know that. – Patrick Jun 23 '20 at 07:33
  • 2
    @Patrick no, you can not, at least if there is no additional rewriting/routing in place. `http://website.com/?page=5` and `http://website.com/?page=5&id=1` respectively would be the _correct_ URLs to pass query string data to the root index file here. – CBroe Jun 23 '20 at 08:10
  • Instead of get method try post method . whether its possible from your side ? – thirumal mani L Jun 23 '20 at 10:07