FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


help - trouble getting operators to work with fwrite





mahirh
hello
i was trying to make a dynamic sig with hit counter from flat file , i searched for tutorials and a flat file hit counter looked like never before attempted so , i just tried it but it has problem with operators which is important for stat counters
my code
Code:
<?php
header('Content-Type: image/png');



$filename = "/xampp/htdocs/stat.png/count.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);

$woor="$contents";

function LoadPNG($imgname)
{

    $im = @imagecreatefrompng($imgname);


    if(!$im)
    {

        $im  = imagecreatetruecolor(150, 30);
        $bgc = imagecolorallocate($im, 255, 255, 255);
        $tc  = imagecolorallocate($im, 0, 0, 0);

        imagefilledrectangle($im, 0, 0, 150, 30, $bgc);


        imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
    }

    return $im;
}

//header('Content-Type: image/png');
$money1 = "$woor";
$money2 = 1;
$money = $money1 + $money2;
// echo $money will output "123.1";
$numb = "$contents++";
$formatted = sprintf("$numb");
$img = LoadPNG('sig.png');
$textcolor = imagecolorallocate($img, 0, 0, 0);
imagestring($img, 3, 127, 62,"Mahirh!!",$textcolor);
imagestring($img, 3,200, 62,"$woor people saw this",$textcolor);
imagepng($img);

$fp = fopen("count.txt", "w");
fwrite($fp, "$numb");
fclose($fp);
?>

and the outcome after this was executed twice is

and the text in count.txt was
Code:
1++++

please help me solve this
because it should show
Nemesis234
Code:
$numb = "$contents++";


>>

Code:
$numb = $contents++;
Fire Boar
You're using a lot of unnecessary speech marks. Also that script is a fair bit more complicated than it needs to be. Consider instead (assuming this php file exists in the same directory as the directory called stat.png and the file sig.png)...

Code:
<?php
function LoadPNG($imgname)
{
  $im = @imagecreatefrompng($imgname);

  if(!$im)
  {
    $im  = imagecreatetruecolor(150, 30);
    $bgc = imagecolorallocate($im, 255, 255, 255);
    $tc  = imagecolorallocate($im, 0, 0, 0);
    imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
    imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
  }

  return $im;
}

header('Content-Type: image/png');

// Retrieve and update the counter.
$count = file_get_contents('stat.png/count.txt') + 1;
file_put_contents('stat.png/count.txt', $count);

// Load the image.
$img = LoadPNG('sig.png');
$textcolor = imagecolorallocate($img, 0, 0, 0);
imagestring($img, 3, 127, 62, "Mahirh!!", $textcolor);
imagestring($img, 3, 200, 62,"$count people saw this", $textcolor);
imagepng($img);
Related topics
website works from work but not from home????
Need help with images
having trouble scoring on frihost?
Drupal image help
DNS
How would a three-state boolean logic system work?
Apache mod_rewrite
A rant on God, religion and morality
CSS backgrounds in tables
PHP5 MySQL Config on XP
Expert XP help needed
Q: 2nd law of thermodynamics & creationists
What if your faith isn't normal
A question to atheists
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.