EffakT
04-12-2012, 12:33 AM
Well, I had this working perfectly until they stopped using a mysql database and started using a flatfile.
What it should do:
Grab data from the flatfile, trim the unwanted parts and set it in an array.
With the received data display as an image.
I am very confused about how I would do this.
My current code:
signature.php:
<?php
//GET AND TRIM
$fileName="accounts.txt";
$fileHandle = fopen($fileName,"r");
$filecontents = fread($fileHandle,filesize($fileName));
$exploded = explode(" ",$filecontents);
$name="";
$balance="";
$accounts=array();
$num=0;
for($i=0;$i<count($exploded);$i++)
{
$line = explode("\t",$exploded[$i]);
for($a=0;$a<count($line);$a++)
{
if(trim($line[$a])=="player")
{
}elseif($line[$a]=="money")
{
}elseif($line[$a]=="type")
{
}elseif(trim($line[$a])=="{")
{
}else
{
$subline = explode("\r",$line[$a]);
for($e=0;$e<count($subline);$e++)
{
if(trim($subline[$e])=="}")
{
}
elseif(is_numeric(trim($subline[$e])))
{
$balance=trim($subline[$e]);
}
else
{
$name=trim($subline[$e]);
}
if($name!=""&&$balance!="")
{
$temp=array($name=>$balance);
$accounts[$num]=$temp;
$num++;
$name="";
$balance="";
}
}
}
}
}
//Image Generation
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
$font = "minecraft.ttf";
$user="";
if(isset($_GET['u']))
{
if(!empty($_GET['u']))
{
$user = $_GET['u'];
}
}
if(isset($_GET['i']))
{
if(!empty($_GET['i']))
{
$img = $_GET['i'];
}
else{$img='1';}
}
else{$img='1';}
if(isset($_POST['u'],$_POST['i']))
{
if(!empty($_POST['u']))
{
$user=$_POST['u'];
}
if(!empty($_POST['i']))
{
$img = $_POST['i'];
}
}
if(in_array($user, $accounts))
{
//Info Grabs
$money = get_balance($user);
//End Info Grabs
}
else
{
die("That is an invalid player.");
}
//Display Image
$user = ucfirst($user);
$image = imagecreatefrompng("images/".$img.".png");
$color = imagecolorallocate($image, 255,255,255);
if ($_GET['i'] >= '8')
{
ImageTTFText ($image, "8", 0, 100, 13, $color, $font,"Name:");
ImageTTFText ($image, "8", 0, 138, 13, $color, $font,$user);
ImageTTFText ($image, "8", 0, 240, 13, $color,$font,"Money:");
ImageTTFText ($image, "8", 0, 285, 13, $color,$font,"$".$money);
}
else
{
ImageTTFText ($image, "7", 0, 246, 10, $color, $font,"Spartan Universe");
ImageTTFText ($image, "12", 0, 130, 50, $color, $font,"Name:");
ImageTTFText ($image, "12", 0, 130, 96, $color,$font,"Money:");
ImageTTFText ($image, "12", 0, 185, 50, $color, $font,$user);
ImageTTFText ($image, "12", 0, 198, 96, $color,$font,"$".$money);
}
//End Image Display
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
?>
accounts.txt:
arkangel011 {
type player
money 23.47
}
chemicalbacon {
type player
money 203.89
}
What I would like to know is how would I go about getting the information form the array created called accounts?
What it should do:
Grab data from the flatfile, trim the unwanted parts and set it in an array.
With the received data display as an image.
I am very confused about how I would do this.
My current code:
signature.php:
<?php
//GET AND TRIM
$fileName="accounts.txt";
$fileHandle = fopen($fileName,"r");
$filecontents = fread($fileHandle,filesize($fileName));
$exploded = explode(" ",$filecontents);
$name="";
$balance="";
$accounts=array();
$num=0;
for($i=0;$i<count($exploded);$i++)
{
$line = explode("\t",$exploded[$i]);
for($a=0;$a<count($line);$a++)
{
if(trim($line[$a])=="player")
{
}elseif($line[$a]=="money")
{
}elseif($line[$a]=="type")
{
}elseif(trim($line[$a])=="{")
{
}else
{
$subline = explode("\r",$line[$a]);
for($e=0;$e<count($subline);$e++)
{
if(trim($subline[$e])=="}")
{
}
elseif(is_numeric(trim($subline[$e])))
{
$balance=trim($subline[$e]);
}
else
{
$name=trim($subline[$e]);
}
if($name!=""&&$balance!="")
{
$temp=array($name=>$balance);
$accounts[$num]=$temp;
$num++;
$name="";
$balance="";
}
}
}
}
}
//Image Generation
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
$font = "minecraft.ttf";
$user="";
if(isset($_GET['u']))
{
if(!empty($_GET['u']))
{
$user = $_GET['u'];
}
}
if(isset($_GET['i']))
{
if(!empty($_GET['i']))
{
$img = $_GET['i'];
}
else{$img='1';}
}
else{$img='1';}
if(isset($_POST['u'],$_POST['i']))
{
if(!empty($_POST['u']))
{
$user=$_POST['u'];
}
if(!empty($_POST['i']))
{
$img = $_POST['i'];
}
}
if(in_array($user, $accounts))
{
//Info Grabs
$money = get_balance($user);
//End Info Grabs
}
else
{
die("That is an invalid player.");
}
//Display Image
$user = ucfirst($user);
$image = imagecreatefrompng("images/".$img.".png");
$color = imagecolorallocate($image, 255,255,255);
if ($_GET['i'] >= '8')
{
ImageTTFText ($image, "8", 0, 100, 13, $color, $font,"Name:");
ImageTTFText ($image, "8", 0, 138, 13, $color, $font,$user);
ImageTTFText ($image, "8", 0, 240, 13, $color,$font,"Money:");
ImageTTFText ($image, "8", 0, 285, 13, $color,$font,"$".$money);
}
else
{
ImageTTFText ($image, "7", 0, 246, 10, $color, $font,"Spartan Universe");
ImageTTFText ($image, "12", 0, 130, 50, $color, $font,"Name:");
ImageTTFText ($image, "12", 0, 130, 96, $color,$font,"Money:");
ImageTTFText ($image, "12", 0, 185, 50, $color, $font,$user);
ImageTTFText ($image, "12", 0, 198, 96, $color,$font,"$".$money);
}
//End Image Display
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
?>
accounts.txt:
arkangel011 {
type player
money 23.47
}
chemicalbacon {
type player
money 203.89
}
What I would like to know is how would I go about getting the information form the array created called accounts?