Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$.post returns syntax error, unexpected '\'

Okay, so i'm writing some code to post something to PHP script and get back data. However, when i do so i get an "PHP Parse error: syntax error, unexpected '\' (T_NS_SEPARATOR) in /home/multipla/public_html/private/data2.php on line 32" error.

I've tried different things to remove this, either changing the posting code or changing small things in the PHP script. (I do not remember them all)

This is my post function:

$.ajax({
      type: "POST",
      url: "data2.php",
      data: { id: "1", name: "9903286" }
    }).done(function( msg ) {alert("Data: " + msg);
});

And this is my PHP file:

<?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;

?>

The PHP script works fine if i run it alone and put 1 and 9903286 instead of $id and $name. Also, line 32 is the "socket_write" line in the PHP script.

like image 422
NineNine Avatar asked Sep 10 '26 07:09

NineNine


1 Answers

Try POSTing to your script with a tool like this one: http://sourceforge.net/projects/htt/

What you need to do is see the raw data and headers you get back. There are also plugins for firefox and chrome for doing this.

Try this to replace your current connect/POST method:

$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);
like image 152
Patrick Avatar answered Sep 11 '26 19:09

Patrick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!