I've just start to learn some php, and I'm trying to make a simple php script. All it will do is ask a person for a link, and then it will convert it in a hyper link.
How people can use my website:
The first way is they can
localhost/link-to-hyperlink.php
https://google.com
Second way they can is they can:
Go to localhost/link-to-hyperlink.php?url=https://google.com
My Problem
Both my things work, but when someone submits a url like this https://google.com/something.php?name=bob&age=12&fav-nums=200;300;400
my program doesn't work properly. It makes the hyper link https://google.com/something.php?name=bob
, not the entire URL.
Also happens on partially encoded urls like: localhost/link-to-hyperlink.php?url=https://google.com?something.php?names=bob%3Bmike%3Bsam&age=30%3B23%3B22&fav-nums=200%3B300%3B400
.
It only happens when someone decides to use the second way to convert the link. I printed the $_GET array and you can see that it makes multiple indexes in the $_GET. I would like to facilitate their mis-use.
The array look liks this:
Array
(
[url] => https://google.com/something.php?name=bob
[age] => 12
[fav-nums] => 200;300;400
)
My program: link-to-hyperlink.php
<?php
if(isset($_GET['url']) == false) {
$answer = "Enter a URL<br>";
} else {
$answer = '<a target="_blank" href="' . $_GET['url'] . '">Your Hyperlink</a><br>';
}
?>
<html>
<head>
<title>Link To Hyerplink Converter</title>
</head>
<body>
<pre>
The array structure was:
<?php print_r($_GET); ?>
</pre>
<br>
<?php echo $answer; ?>
<form action="link-to-hyperlink.php" method="GET">
Your URL:<br>
<input type="text" name="url"><br>
<input type="submit" value="submit">
</form>
</body>
</html>