Issue
Let’s say my url is mywebsite.com/login?code=xxxxxxxxxx..
I have used isset($_GET[‘code’]) method to retrieve the data.
I’d like to know any other ways to fetch the url data(value of code)
Solution
PHP have few functions to work around url parameters but $_GET is most common and easiest to work around / read
$code = isset($_REQUEST['code']) ? $_REQUEST['code'] : '';
Nothe that "FILTER_SANITIZE_STRING" is deprecated since php 8.1
$code = filter_input(INPUT_GET, 'code', FILTER_SANITIZE_STRING);
$actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$query = parse_url($actual_link, PHP_URL_QUERY);
parse_str($query, $params);
$code = isset($params['code']) ? $params['code'] : '';
Answered By - Damian ChudobiĆski
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.