API Player Info in PHP Function ?

For general discussion of the Poker Mavens software
Kent Briggs
Site Admin
Posts: 5878
Joined: Wed Mar 19, 2008 8:47 pm

Re: API Player Info in PHP Function ?

Post by Kent Briggs »

I had forgotten that php functions cannot see variables declared outside of themselves unless you declare them as "global". So just put this as the first line of your function and that should fix the issue:

global $pw, $account, $url, $params;

Otherwise it treats these variables as being local and they will all be empty strings.
PokerFreak
Posts: 19
Joined: Sun Feb 13, 2011 7:05 am

Re: API Player Info in PHP Function ?

Post by PokerFreak »

Working. Thank you very much sir.
PokerFreak
Posts: 19
Joined: Sun Feb 13, 2011 7:05 am

Re: API Player Info in PHP Function ?

Post by PokerFreak »

For a wierd reason, when the account and password is written on a previous page that redirects to the page where the user info is shown, the function works. But when someone tries to input info(Decrement Balance), the api isn't working and the user info ain't showing again.

That's the code of the entire page.

Code: Select all

<? session_start();
if ($_SESSION['myuser']=="")
{
header("Location: auth.php?flag=not");
exit;
}
?>
<html>
<?php include "API.php";
$pass = $_POST['pass'];
$account = $_POST['account'];
$balance = $_POST['balance'];
 ?>
<?php 
function playerInfo() {
global $pw, $account, $url, $params;
$params = "Password=$pw&Command=AccountsGet&Player=$account";
$api = Poker_API($url,$params,true);
echo "Username: " . $api["Player"] . "</br>Balance: " . $api["Balance"]  . " ";
}
?>
<head>
<div align="left">
<h3><a href="12.php">Main</a></h3></div>
<center><img src="spades.jpg" alt="logo" width="150" height="150" /></center>
</head>
<body>
<br/><br/><br/><br/><br/><br/><br/><br/>
<?php


$params = "Password=$pw&Command=AccountsGet&Player=$account";
$api = Poker_API($url,$params,true);
if($api['PW'] != $pass) {
header("Location: cashout.php?flag=wrong");
}
if(isset($_POST['submit'])){
$params = "Password=$pw&Command=AccountsDecBalance&Player=$account&Amount=$balance&Negative=Zero";
$api = Poker_API($url,$params,true);
}
playerInfo();
?>
</br></br></br>

<form method="post" name="auth" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<center>
<table width="400" border="0" cellspacing="4" cellpadding="0">
  
  
  <tr>
  
  <td width="50" align="right">Enter Balance </td>
    <td><input name="balance" type="text" id="balance"></td>
	</tr>
  <tr>
    <td width="150" align="right">&nbsp;</td>
    <td>
    <input type="submit" name="submit" value="Submit"></left></td>
  </tr>
</center>
</table>
</form>

</body>
</html>
Your help is really appreciated.
Thank You.
Kent Briggs
Site Admin
Posts: 5878
Joined: Wed Mar 19, 2008 8:47 pm

Re: API Player Info in PHP Function ?

Post by Kent Briggs »

PokerFreak wrote:For a wierd reason, when the account and password is written on a previous page that redirects to the page where the user info is shown, the function works. But when someone tries to input info(Decrement Balance), the api isn't working and the user info ain't showing again.
I can't really debug your code for you but I'd suggest you sprinkle plenty of echo commands around to see which sections are being executed and what values the variables hold at that point. One thing I do see at a quick glance is that you have header() command that appears after you've output an bunch of <br/> tags. As I recall, nothing can be displayed before a header() command.
Post Reply