我正在尝试创建一个脚本,将信息从 1 个域发送到另一个域并将数据保存到数据库,但是我从域 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';
}