links.php直接享受有以下代碼:PHP防止PHP頁面
$ipaddress = $_SERVER["REMOTE_ADDR"];
<p><a href="track.php?page=http://www.google.co.uk" target="_blank">google.co.uk</a></p>
<p><a href="track.php?page=http://www.bbc.co.uk" target="_blank">bbc.co.uk</a></p>
<p><a href="track.php?page=http://www.cnn.com" target="_blank">cnn.com</a></p>
<p><a href="track.php?page=http://www.yahoo.co.uk" target="_blank">yahoo.co.uk</a></p>
track.php捕捉鏈接點擊:
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("mydb1") or die(mysql_error());
$redirect = mysql_real_escape_string($_GET['page']);
$ipaddress = $_SERVER["REMOTE_ADDR"];
$page_insert = mysql_query("INSERT INTO link_track (myurl, myip1, mydate) VALUES ('$redirect', '$ipaddress', now())") or die(mysql_error());
header("Location: $redirect");
反正有防止有人直接訪問track.php。
您的幫助將不勝感激,謝謝。
我的另一個問題道歉: 如果我想去掉http://www.
部分從網址我可以修改我的track.php代碼如下:
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("mydb1") or die(mysql_error());
$redirect = mysql_real_escape_string($_GET['page']);
$redirect2 = parse_url($redirect, PHP_URL_HOST);
$redirect2 = preg_replace('/^(www\.)/i', '', $redirect2);
$ipaddress = $_SERVER["REMOTE_ADDR"];
$page_insert = mysql_query("INSERT INTO link_track (myurl, myip1, mydate) VALUES ('$redirect2', '$ipaddress', now())") or die(mysql_error());
header("Location: $redirect");
號有一切的方式。你可以混淆它。但是你不能阻止它。 –
http://stackoverflow.com/questions/1408538/what-checks-to-use-to-prevent-direct-access-to-pages-using-php?rq=1 – matino
http://stackoverflow.com/questions/1044643/php-prevent-direct-access-to page –