0
我有一些问题与PHP检测http://包含和非http:/ /包含从数据库的链接和引用用户基于他们在这里是代码;PHP不转发重定向
$url = $_GET['short'];
$route_url = mysql_result(mysql_query('SELECT original_url FROM ' . DB_TABLE . ' WHERE short_url = "' . mysql_real_escape_string($url) . '"'));
mysql_query('UPDATE ' . DB_TABLE . ' SET refferals = refferals + 1 WHERE short_url = "' . mysql_real_escape_string($url) . '"');
if(preg_match("/^[a-zA-Z]+[:\/\/]+[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&=\?\-_]+$/i", $route_url)) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $route_url);
} else {
$protocol = "http://";
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $protocol.$route_url);
}
mysql_close();
exit;
可以对一些告诉我什么,我做错了,如何解决它,这样既HTTP://和非HTTP://(google.com)与重定向
你得到什么错误?你是什么意思非HTTP? –
这可能有助于http://stackoverflow.com/questions/14698781/how-can-i-change-the-scheme-of-a-url-with-preg-match – Rob
@InGodITrust非http意味着如果链接在数据库只是google.com它将通过位置路由。在我的情况下,非http://包含链接会被路由到mydomain.com/google.com,这是问题所在。如果链接确实有http://google.com在分贝它将工作,但如果没有它将失败 – 10010010001011101111