好的,所以我正在编写一些代码来发布PHP脚本并获取数据。 但是,当我这样做时,我在第32行的/home/multipla/public_html/private/data2.php中出现“PHP Parse错误:语法错误,意外'\'(T_NS_SEPARATOR)”错误。
我尝试了不同的方法来删除它,无论是更改发布代码还是更改PHP脚本中的小东西。 (我不记得所有)
这是我的帖子功能:
$.ajax({
type: "POST",
url: "data2.php",
data: { id: "1", name: "9903286" }
}).done(function( msg ) {alert("Data: " + msg);
});
这是我的PHP文件:
<?php
$PORT = 4321;
$HOST = "THE IP (Removed cause ddos)";
$id = $_POST['id'];
$name = $_POST['name'];
$sock = socket_create(AF_INET, SOCK_STREAM, 0)
or die("error: could not create socket\n");
$succ = socket_connect($sock, $HOST, $PORT)
or die("error: could not connect to host\n");
$text = "BUY:".$id.":".$name;
socket_write($sock, $text."\n", strlen($text."\n") + 1) or die("error: failed to write to socket\n");
$reply = socket_read($sock, 10000) or die("error: failed to read from socket\n");
echo $reply;
&GT;
如果单独运行并将1和9903286放在$ id和$ name上,那么PHP脚本可以正常工作。 另外,第32行是PHP脚本中的“socket_write”行。
答案 0 :(得分:1)
尝试使用类似这样的工具POST到您的脚本:http://sourceforge.net/projects/htt/
您需要做的是查看您获得的原始数据和标题。这样做还有firefox和chrome的插件。
尝试使用此替换当前的connect / POST方法:
$connectionString = 'http://92.68.123.45';
$paramList = array(
'name' => 'Bob'
'phone' => 8161234567
);
$varString = http_build_query($paramList);
$opts = array(
'http' => array(
'method' => "POST",
'content' => $varString
)
);
$context = stream_context_create($opts));
$result = file_get_contents($connectionString, false, $context);