help in php

For general discussion of the Poker Mavens software

help in php

Postby DocterWho » Tue Jul 29, 2008 2:36 am

hi,

i'm trying to make a php function but keep getting an :
* Zero Sized Reply

Squid did not receive any data for this request

here's my code :
-----------
function addchips($user,$amount)
{
mysql_connect( "localhost", "host_mavens", "*******" );
mysql_select_db( "host_mavens" );
$sql = mysql_query( "SELECT * FROM link where user='".$user."'");
$data = mysql_fetch_array( $sql );
$check1 = $data['poker'];
$check1a = $data['user']; // uit database

if ( $check1 =='' )
{ echo $user." heeft nog geen pokeraccount contact : ".$user."<br>"; }
if ( $check1a == $user )
{ echo " adding : ".$amount." to ".$check1." account of : ".$user."<br>";
$url ="http://87.66.13.38:8087/control?Password=******&Command=IncBalance&Player=".$check1."&Amount=".$amount;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
}
-------------------
when changing the last part of the code to :

----
{ echo " adding : ".$amount." to ".$check1." account of : ".$user."<br>";
$url ="http://87.66.13.38:8087/control?Password=170673caps&Command=IncBalance&Player=".$check1."&Amount=".$amount;

echo $url;



}

----
i get response :
http://87.66.13.38:8087/control?Passwor ... Amount=400

so the $url is correct when i copy and paste it in my browser i get :
Result=Ok

----
Can someone tell me how i can solve this ?
DocterWho
 
Posts: 4
Joined: Tue Jul 29, 2008 2:21 am

Re: help in php

Postby Kent Briggs » Tue Jul 29, 2008 9:59 am

DocterWho wrote: $url ="http://87.66.13.38:8087/control?Password=******&Command=IncBalance&Player=".$check1."&Amount=".$amount;
curl_setopt($ch, CURLOPT_POST, 1);


I think it's because you are building a command line via GET but are sending the data via POST. I recently created this PHP function for the help file in the upcoming version 2.10. It will call the API and then return the entire response in a single associative array:

Code: Select all
 
function Poker_API($url,$params)
  {
    $curl = curl_init($url);
    curl_setopt($curl,CURLOPT_POST,true);
    curl_setopt($curl,CURLOPT_POSTFIELDS,$params);
    curl_setopt($curl,CURLOPT_TIMEOUT,10);
    curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
    $response = curl_exec($curl);
    curl_close($curl);
    $api = Array();
    if (empty($response))
    {
      $api[Result] = "Error";
      $api[Error] = "Connection failed";
    }
    else 
    {
      // Break response at CRLF's into an array of Parameter=Value items.

      $paramlist = Explode("\r\n",$response);

      // Iterate through the array and create an new associative array
      // so that the parameter name is the key.

      foreach ($paramlist As $param)
      {
        $namevalue = Explode("=",$param,2);
        $api[$namevalue[0]] = $namevalue[1];
      }
    }
    return $api;
  }


Prior to version 2.10, set it up like this:

Code: Select all
$url ="http://87.66.13.38:8087/control";
$params = "Password=xxxxxx&Command=IncBalance&Player=" . $check1 . "&Amount=" . $amount;


Since version 2.10, set it up like this:

Code: Select all
$url ="http://87.66.13.38:8087/api";
$params = "Password=xxxxxx&Command=AccountsIncBalance&Player=" . $check1 . "&Amount=" . $amount;


And then call it like this and get the response in an associative array:

Code: Select all
$api = Poker_API($url,$params);
if ($api[Results] == "Ok") echo "Success"; else echo "Error: " . $api[Error];
Kent Briggs - [email protected]
Briggs Softworks - http://www.briggsoft.com
Kent Briggs
Site Admin
 
Posts: 3931
Joined: Wed Mar 19, 2008 8:47 pm

Re: help in php

Postby Kent Briggs » Thu Jul 31, 2008 7:20 pm

It looks like the last \r\n in the response is getting split off into a blank parameter at the end and causing a notice to be displayed in some versions of PHP. So the whitespace should be trimmed off with the trim() function. Here's a corrected function:

Code: Select all
function Poker_API($url,$params)
{
  $curl = curl_init($url);
  curl_setopt($curl,CURLOPT_POST,true);
  curl_setopt($curl,CURLOPT_POSTFIELDS,$params);
  curl_setopt($curl,CURLOPT_TIMEOUT,10);
  curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
  $response = trim(curl_exec($curl));
  curl_close($curl);
  $api = Array();
  if (empty($response))
  {
    $api[Result] = "Error";
    $api[Error] = "Connection failed";
  }
  else 
  {
    // Break response at CRLF's into an array of Parameter=Value items.

    $paramlist = Explode("\r\n",$response);

    // Iterate through the array and create an new associative array
    // so that the parameter name is the key.

    foreach ($paramlist As $param)
    {
      $namevalue = Explode("=",$param,2);
      $api[$namevalue[0]] = $namevalue[1];
    }
  }
  return $api;
}
Kent Briggs - [email protected]
Briggs Softworks - http://www.briggsoft.com
Kent Briggs
Site Admin
 
Posts: 3931
Joined: Wed Mar 19, 2008 8:47 pm


Return to General

Who is online

Users browsing this forum: No registered users and 14 guests

cron