Home > other >  Cannot get the second param in url php
Cannot get the second param in url php

Time:10-26

I'm trying to get the parameters c and t of the following url:

http://www.sitename.com/index.php?c=hJjB0wf/f4o&t=4m52Jkm81j8

doing $_GET['c'] and $_GET['t'] but when i echo the two variables it happens something like this:

c=hJjB0wf/f4o%26t=4m52Jkm81j8
t is undefined

what is the problem?

CodePudding user response:

You don't get the value because the URL is not correct. Before there should be a & like this, you will get the value of t. Update your URL

http://www.sitename.com/index.php?c=hJjB0wf/f4o&t=4m52Jkm81j8

CodePudding user response:

That's because in your url are not t param. In url &t are urlencoded of &t http://www.sitename.com/index.php?c=hJjB0wf/f4o&t=4m52Jkm81j8.

All you can do is something like

$url = "http://www.sitename.com/index.php?c=hJjB0wf/f4o&t=4m52Jkm81j8";

$fixed = urldecode($url); // fix & -> &

$urlParts = parse_url($fixed);

$params = [];

parse_str($urlParts['query'], $params);

print_R($params);
Array
(
    [c] => hJjB0wf/f4o
    [t] => 4m52Jkm81j8
)


  • Related