How can I parse_url in PHP when there is a url in a string variable?

I'm admittedly new to PHP, so I need help.

I am creating an independent affiliate program for my site and I have the opportunity for an affiliate to add SubID to their tracking link. Without control over what was entered, I tested various scenarios and found an error entering the full URL (for example, http://example.com ").

In my PHP, I can grab a variable from a string without any problems. My problem occurs when I get the link url and parse it (since I need to parse the link url to get the grid host for other purposes). Code below:

$refURL = getenv("HTTP_REFERER");

$parseRefURL = parse_url($refURL);

WORKS when an incoming link (for example):

http://example.com/?ref=REFERRER'S-ID&sid=www.test.com

ERROR on incoming link (note the addition of "http: //" after "sid ="):

http://example.com/?ref=REFERRER'S-ID&sid=http://www.test.com

Here is a warning:

Warning: parse_url (/? Ref = REFERRER'S-ID & sid = http://www.test.com ) [function.parse-url]: Unable to parse URL in / home 4 / 'directory' / public_html / hosterdoodle / header.php on line 28`

Any ideas on how to save the parse-url drop function when someone can decide to place the url in a variable? (I actually tested this problem to such an extent that it will throw an error with the same value as ": /" in the variable)

+3
source share
2 answers

The following part of the code:

$url = "http://example.com/?ref=REFERRER'S-ID&sid=http://www.test.com";
$data = parse_url($url);
var_dump($data);

(PHP 5.3.2) :

array
  'scheme' => string 'http' (length=4)
  'host' => string 'example.com' (length=11)
  'path' => string '/' (length=1)
  'query' => string 'ref=REFERRER'S-ID&sid=http://www.test.com' (length=41)


, URL- parse_url?

:

$url = "/?ref=REFERRER'S-ID&sid=http://www.test.com";
$data = parse_url($url);

, :

Warning: parse_url(/?ref=REFERRER'S-ID&sid=http://www.test.com) 
[function.parse-url]: Unable to parse URL

URL-...

+4

$refURL, str_replace, http://?

0

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


All Articles