GD library

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nathan.fulton@gmail.com

    #1

    GD library

    Hey all,

    I'm having issues with a script. When loaded, it should grab data from
    a database, add 1 to the visits counter and then display the count in
    the form of an image. The problem is this: when the script loads,
    instead of adding 1 count to the database, it ads anywhere from 2 to 4
    counts to the database. I was wondring is anyone knows whats going on
    or how to fix it. I have attached my code below.

    Thanks!

    -Nathan

    <?php
    [database connection here]

    $url = $_GET["url"];

    //get the # of hits
    $q = mysql($dbname, "SELECT * FROM counter WHERE url = '$url'");
    $num = mysql_num_rows( $q);
    if($num != "0")
    {
    $do = mysql_fetch_obj ect($q);
    $newcount = $do->count + 1;
    mysql($dbname, "UPDATE counter SET count = '$newcount' WHERE url =
    '$url'");
    mysql($dbname, "INSERT INTO counter_ip VALUES(0,'$url' ,'$ip')");

    $fontsize = "5";
    }
    else
    {
    $newcount = "user not found";
    //establish font size
    $fontsize = "3";
    }
    // create a 100*30 image
    $im = imagecreate(100 , 30);

    // white background and blue text
    $bg = imagecoloralloc ate($im, 255, 255, 255);
    $textcolor = imagecoloralloc ate($im, 0, 0, 255);

    // write the string at the top left
    imagestring($im , $fontsize, 0, 0, $newcount, $textcolor);

    // output the image
    header("Content-type: image/png");
    imagepng($im);
    ?>

  • Pedro Graca

    #2
    Re: GD library

    nathan.fulton@g mail.com wrote:
    I'm having issues with a script. When loaded, it should grab data from
    a database, add 1 to the visits counter and then display the count in
    the form of an image. The problem is this: when the script loads,
    instead of adding 1 count to the database, it ads anywhere from 2 to 4
    counts to the database. I was wondring is anyone knows whats going on
    or how to fix it. I have attached my code below.
    Hmmm ... I really don't like the idea that the image itself updates
    the database. I'd do the updating outside the image

    Where you have, in your HTML:
    <img src="image.php? url=http%3A%2F% 2Fwww.google.co m%2F">

    I'd do this instead:
    <?php log_and_count(' http://www.google.com/'); ?>
    <img src="image.php" >

    and, of course, remove the INSERT/UPDATE update stuff from the
    image code, leaving only the SELECT part.
    The `log_and_count( )` function would do the INSERT/UPDATE stuff.

    --
    I (almost) never check the dodgeit address.
    If you *really* need to mail me, use the address in the Reply-To
    header with a message in *plain* *text* *without* *attachments*.

    Comment

    • nathan.fulton@gmail.com

      #3
      Re: GD library

      works great. Thank's for the reply.

      On Oct 26, 6:17 pm, Pedro Graca <hex...@dodgeit .comwrote:
      nathan.ful...@g mail.com wrote:
      I'm having issues with a script. When loaded, it should grab data from
      a database, add 1 to the visits counter and then display the count in
      the form of an image. The problem is this: when the script loads,
      instead of adding 1 count to the database, it ads anywhere from 2 to 4
      counts to the database. I was wondring is anyone knows whats going on
      or how to fix it. I have attached my code below.Hmmm ... I really don't like the idea that the image itself updates
      the database. I'd do the updating outside the image
      >
      Where you have, in your HTML:
      <img src="image.php? url=http%3A%2F% 2Fwww.google.co m%2F">
      >
      I'd do this instead:
      <?php log_and_count(' http://www.google.com/');?>
      <img src="image.php" >
      >
      and, of course, remove the INSERT/UPDATE update stuff from the
      image code, leaving only the SELECT part.
      The `log_and_count( )` function would do the INSERT/UPDATE stuff.
      >
      --
      I (almost) never check the dodgeit address.
      If you *really* need to mail me, use the address in the Reply-To
      header with a message in *plain* *text* *without* *attachments*.

      Comment

      Working...