Jump to content

RPatton

Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by RPatton

  1. OK, I just tried it without the echo and it still doesn't work. :(

     

    Is my HTML code correct? Am I calling the PHP file properly? I can't shake the feeling that the problem lies in the way I am calling the PHP file. :facepalm:

     

    I created a test page to try and debug this and here is my entire basic HTML test page:

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <title>Hit Counter</title>
    </head>

    <body>
    <div class="visitor-count">Number of visitors since 12-10-2016:</div>
    <img alt="Hit counter" src="counter.php" />
    </body>

    </html>

  2. It is a path to a bunch of number images. I could be wrong (again I'm very new at this) but I don't think it is getting to the PHP file or I would be getting an error from the PHP.

     

    This is my PHP code and the paths are correct. Thanks for all your input.

     

    <?php
    session_start();
    $counter_name = "counter.txt";
    // Check if a text file exists. If not create one and initialize it to zero.
    if (!file_exists($counter_name)) {
    $f = fopen($counter_name, "w");
    fwrite($f,"0");
    fclose($f);
    }
    // Read the current value of the counter file
    $f = fopen($counter_name,"r");
    $counterVal = fread($f, filesize($counter_name));
    fclose($f);
    // Has visitor been counted in this session?
    // If not, increase counter value by one
    if(!isset($_SESSION['hasVisited'])){
    $_SESSION['hasVisited']="yes";
    $counterVal++;
    $f = fopen($counter_name, "w");
    fwrite($f, $counterVal);
    fclose($f);
    }
    $counterVal = str_pad($counterVal, 6, "0", STR_PAD_LEFT);
    $chars = preg_split('//', $counterVal);
    $im = imagecreatefrompng("../images/counter/canvas.png"); // Transparent canvas that my numbers will sit on top of
    $src1 = imagecreatefrompng("../images/counter/$chars[1].png");
    $src2 = imagecreatefrompng("../images/counter/$chars[2].png");
    $src3 = imagecreatefrompng("../images/counter/$chars[3].png");
    $src4 = imagecreatefrompng("../images/counter/$chars[4].png");
    $src5 = imagecreatefrompng("../images/counter/$chars[5].png");
    $src6 = imagecreatefrompng("../images/counter/$chars[6].png");
    imagecopymerge($im, $src1, 0, 0, 0, 0, 56, 75, 100);
    imagecopymerge($im, $src2, 60, 0, 0, 0, 56, 75, 100);
    imagecopymerge($im, $src3, 120, 0, 0, 0, 56, 75, 100);
    imagecopymerge($im, $src4, 180, 0, 0, 0, 56, 75, 100);
    imagecopymerge($im, $src5, 240, 0, 0, 0, 56, 75, 100);
    imagecopymerge($im, $src5, 300, 0, 0, 0, 56, 75, 100);
    // Output and free from memory
    header('Content-Type: image/png');
    echo imagepng($im);
    imagedestroy($im);
    ?>

  3. The path is correct, I have checked and double checked it.

     

    I don't know why I put it in that folder. It is just where my other PHP files are. :-)

     

    <div class="visitor-count">Number of visitors since 12-10-2016:</div>
    <img alt="Hit counter" src="../javascripts/counter.php" />

     

    Of this code, the only thing that displays when I run it is:

    Number of visitors since 12-10-2016:

    Hit counter

     

    I put this code (echo "This is a test!";) at the start of my PHP file just to see if if was even getting that far and it wasn't.

     

    I also tried putting the counter.php file in the same folder as the HTML file and not using a path just src="counter.php" and that didn't work either.

  4. I'm going to get this out of the way right up front, I am very new at this PHP stuff.

     

    After a lot of research I have developed a standalone PHP file that I want to call from a HTML page. It isn't getting past my HTML code so I think I've done something there. This is my HTML code:

     

    <div class="visitor-count">Number of visitors since 12-10-2016:</div>
    <img alt="Hit counter" src="../javascripts/counter.php" />

     

    Any help would be greatly appreciated.

     

    RPatton

×
×
  • Create New...