Parse_url () when one of the parameters is url

I call a php script http://site.com/process.phpthat takes url as one of its parameters.for=

http://site.com/process.php?for=http://www.anotherwebsite.com

Then I will do it and try parse_url(), but parse_url () throws a parsing error.

$uri = $_SERVER['REQUEST_URI']; // /process.php?for=http://www.anotherwebsite.com
parse_url($uri);

How can I encode a parameter foreither on the sending side (in the URL) or on the receiving side (php), so that I parse_url()understand that this is just a parameter that looks like a url?

+3
source share
2 answers

Well, first you have to urlencode()parameter for=, then in process.phpyou can just do

$url = $_GET["for"];
$url = urldecode($url); // http://www.anotherwebsite.com

Here are the functions: http://php.net/manual/en/function.urlencode.php http://php.net/manual/en/function.urldecode.php

+2

URL get, urlencode

$full_url = 'http://site.com/process.php?for=' . urlencode('http://www.anotherwebsite.com');

, , URL-, .


urlencode, urldecode. , $_GET .

+3

Source: https://habr.com/ru/post/1791472/


All Articles