我正在尝试创建一个脚本,将信息从一个域发送到另一个域并将数据保存到数据库,但是我从域1检索数据,但无法保存到数据库。
以下是域名1的脚本:
// Get Domain Name:
$domain = $_SERVER['HTTP_HOST'];
// Get User IP Address:
$user = $_SERVER["REMOTE_ADDR"];
// Connect to Source:
$url = 'http://www.domain2.com/source.php';
$fields = array(
'id'=>'1',
'user'=>$user,
'domain'=>$domain,
);
//url-ify the data for the POST
$fields_string = '?';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
以下是将数据保存到域2上的数据库的脚本:
// Get domain and user details:
$domain=$_GET['domain'];
$user=$_GET['user'];
// Connection to MySQL Database.
include ('_includes/_dbconnection.php');
include ('_includes/_dbopen.php');
// Insert Data to MySQL Database
$sql="INSERT INTO traffic (url, cip)VALUES('$_POST[domain]', '$_POST[user]')";
$result=mysql_query($sql);
if($result){
echo $domain;
echo $user;
}
else {
echo 'Not Input';
}
答案 0 :(得分:1)
您正在使用curl发布表单并尝试使用$_GET
尝试使用$_POST
或$_REQUEST
$domain=$_POST['domain'];
$user=$_POST['user'];
// Connection to MySQL Database.
include ('_includes/_dbconnection.php');
include ('_includes/_dbopen.php');
// Insert Data to MySQL Database
$sql="INSERT INTO traffic (url, cip)VALUES('$domain', '$user')";
$result=mysql_query($sql);
if($result){
echo $domain;
echo $user;
}else {
echo 'Not Input';
}