1
Im使用PHP curl保存網站名稱的網頁名稱上的用戶剛剛點擊和IP地址在我的數據庫,但問題捲曲發送2請求自動一個正確的數據和其他一個剛剛改變頁面名稱爲index.php,我想中止第二個請求,意思是當curl執行一次然後沒有請求通過curl直到另一個點擊同一頁面,希望我的描述能幫助你找到我的錯誤,這是我的代碼。PHP curl自動發送兩個請求
**This IS My Curl Code**
$wb_nm = $_SERVER[HTTP_HOST];
$pg_nm = $_SERVER[PHP_SELF];
$usr_ip = $_SERVER[REMOTE_ADDR];
$pg_nm_ultr = trim($pg_nm , '/');
$n_url = "localhost/curl/new_page.php";
$data = array(
"varhost" => $wb_nm,
"varpage" => $pg_nm_ultr,
"varip" => $usr_ip
);
$post = curl_init();
curl_setopt($post, CURLOPT_URL, $n_url);
curl_setopt($post, CURLOPT_POSTFIELDS, $data);
curl_setopt($post, CURLOPT_RETURNTRANSFER, false);
$result = curl_exec($post);
curl_close($post);
?>
**And This Is new_page.php**
if(isset($_POST['varhost']) && isset($_POST['varpage']) && isset($_POST['varip']))
{
$web_name = $_POST['varhost'];
$page_name_ulter = $_POST['varpage'];
$user_ip = $_POST['varip'];
define("DB_HOSTNAME", "localhost");
define("DB_USER", "root");
define("DB_PASS", "");
define("DB_DB", "pan");
$connection = mysqli_connect(DB_HOSTNAME, DB_USER, DB_PASS, DB_DB);
if(isset($connection)){
$query = "SELECT * FROM tbl_agencies WHERE weblink = '".$web_name."'";
$result = mysqli_query($connection , $query);
if($result){
while($row = mysqli_fetch_array($result)){
if(isset($row))
{
$D_id = $row['domain_id'];
$D_name = $row['website'];
if($D_id == 0)
{
return false;
}
}
else
{
}
break;
}
}
}
$date_date = date('Y-m-d');
$time_stamp = date("H:i:s");
$query_Code = "INSERT INTO user_details (website_domain_id , website_domain_name , page_clicked , user_IP , access_date , access_time) VALUES ('".$D_id."','".$D_name."' , '".$page_name_ulter."' , '".$user_ip."' , '".$date_date."' , '".$time_stamp."')";
$result_Code = mysqli_query($connection , $query_Code);
if($result_Code)
{
mysqli_close($connection);
}
}
?>
對不起兄弟,這招是行不通的 即使我改變了我捲曲的代碼非常多,這是我的代碼現在 <?php /* USER_DETAILS CURL CODE */ $ wb_nm = $ _SERVER [HTTP_HOST]; $ pg_nm = $ _SERVER [PHP_SELF]; $ usr_ip = $ _SERVER [REMOTE_ADDR]; $ pg_nm_ultr = trim($ pg_nm,'/'); $ n_url =「localhost/curl/new_page.php」; $ data = array( 「varhost」=> $ wb_nm, 「varpage」=> $ pg_nm_ultr, 「varip」=> $ usr_ip ); $ post = curl_init(); curl_setopt($ post,CURLOPT_URL,$ n_url); curl_setopt($ post,CURLOPT_POSTFIELDS,$ data); curl_setopt($ post,CURLOPT_RETURNTRANSFER,false); $ result = curl_exec($ post); curl_close($ post); ?> –