mirror of
https://github.com/hakasenyang/php-shortlink
synced 2026-08-22 07:03:08 +09:00
Update invalid URL check
This commit is contained in:
@@ -64,7 +64,17 @@ class ShortLink {
|
|||||||
*/
|
*/
|
||||||
public function Make($url, $text = NULL) {
|
public function Make($url, $text = NULL) {
|
||||||
if (!is_NULL($text) &&
|
if (!is_NULL($text) &&
|
||||||
(strlen($text) > 16 || strlen($text < 3))) return NULL;
|
(strlen($text) > 16 || strlen($text < 3))) return 1;
|
||||||
|
$parse = parse_url($url);
|
||||||
|
switch($parse['scheme'])
|
||||||
|
{
|
||||||
|
case 'http':
|
||||||
|
case 'https':
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
if (is_null($parse['host'])) return 2;
|
||||||
$select = $this->Select($text, $url);
|
$select = $this->Select($text, $url);
|
||||||
$url = htmlspecialchars($url);
|
$url = htmlspecialchars($url);
|
||||||
if ($text === NULL)
|
if ($text === NULL)
|
||||||
@@ -112,7 +122,9 @@ $short = new ShortLink();
|
|||||||
|
|
||||||
if ($_POST['url']) {
|
if ($_POST['url']) {
|
||||||
$data = $short->Make($_POST['url'], $_POST['str']);
|
$data = $short->Make($_POST['url'], $_POST['str']);
|
||||||
if (!is_null($_POST['str']) &&
|
if ($data === 1) die('Short');
|
||||||
|
else if ($data === 2) die('This is not a valid URL address.');
|
||||||
|
else if (!is_null($_POST['str']) &&
|
||||||
(strlen($_POST['str']) > 16 || strlen($_POST['str']) < 3)) die('Short URL must be between 3 and 16 characters long.');
|
(strlen($_POST['str']) > 16 || strlen($_POST['str']) < 3)) die('Short URL must be between 3 and 16 characters long.');
|
||||||
else if ($data['randstr'] !== $_POST['str'] &&
|
else if ($data['randstr'] !== $_POST['str'] &&
|
||||||
!is_null($_POST['str']) &&
|
!is_null($_POST['str']) &&
|
||||||
|
|||||||
Reference in New Issue
Block a user