Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Apr 2004
    Location
    Philadelphia
    Posts
    241
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Keep Same Variable ALWAYS

    Okay..I'm completely new at php, but I am trying to build my new site www.jacostuff.com with php scripts, now I want the main page to show the number of vistors i have... but it will always show one if the variable doesn't ALWAYS stay the same here's my script...
    <?php
    static $vistors = 0;
    $vistors++;
    echo "This site has had $vistors vistors";
    ?>
    I'm newb so please be gentle!

  • #2
    New Coder
    Join Date
    Dec 2003
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by As5a5sIn5
    Okay..I'm completely new at php, but I am trying to build my new site www.jacostuff.com with php scripts, now I want the main page to show the number of vistors i have... but it will always show one if the variable doesn't ALWAYS stay the same here's my script...

    I'm newb so please be gentle!
    Once the script is executed by ONE visitor then the value of $vistors will completely be lost and on your script you set the variable 0 so you will allways get 1.

    You need to save the number of whow many times the page has been opened!
    to do that there are two options.
    1. using a text file:
    PHP Code:
    $fp fopen("counter.txt","r"); 

    $count fread ($fpfilesize ("counter.txt"));

    fclose($fp);

    $count++;

    $fp fopen("counter.txt","a+");

    fputs($fp$count);

    fclose($fp);

    echo 
    "Hits: $count"
    2. using MySQL Database:USING GD AND MYSQL( GRAPHICAL COUNTER DISPLAY)
    Last edited by fimi; 05-27-2004 at 11:56 PM.
    |Tip: Use a template engine to separate your PHP code from HTML [Smarty]
    |Helpful: Follow the forum rules and posting guidelines, they apply to all of us [Rules] - [Posting Guidelines]
    |Me: [MSN][Y!][AIM][@] - fimi

  • #3
    Regular Coder
    Join Date
    Apr 2004
    Location
    Philadelphia
    Posts
    241
    Thanks
    2
    Thanked 5 Times in 5 Posts
    hmm thanks...ill try that...I have mySQl but I'm extremely new

  • #4
    Regular Coder
    Join Date
    Apr 2004
    Location
    Philadelphia
    Posts
    241
    Thanks
    2
    Thanked 5 Times in 5 Posts
    I mean ill use the text file thing

  • #5
    New Coder
    Join Date
    Dec 2003
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by As5a5sIn5
    I mean ill use the text file thing
    If you're on a linux server make sure you CHMOD the text file to 777.
    |Tip: Use a template engine to separate your PHP code from HTML [Smarty]
    |Helpful: Follow the forum rules and posting guidelines, they apply to all of us [Rules] - [Posting Guidelines]
    |Me: [MSN][Y!][AIM][@] - fimi

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by fimi
    If you're on a linux server make sure you CHMOD the text file to 777.

    That wouldn't be a good idea. You really don't want to give everybody read, write and execute permissions.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #7
    New Coder
    Join Date
    Dec 2003
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Spookster, the file needs to have write permission, i would look more into the Execute permission.

    What would you do to the permissions of the file?
    |Tip: Use a template engine to separate your PHP code from HTML [Smarty]
    |Helpful: Follow the forum rules and posting guidelines, they apply to all of us [Rules] - [Posting Guidelines]
    |Me: [MSN][Y!][AIM][@] - fimi

  • #8
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    just for reference, here is a step by step hit counter script

    http://web-bureau.com/modules/free-p...ter-script.php

  • #9
    Regular Coder
    Join Date
    Apr 2004
    Location
    Philadelphia
    Posts
    241
    Thanks
    2
    Thanked 5 Times in 5 Posts
    Thanks Lite Bearer...I read that and I think I understand most of it now...but yet another problem with this ( Sorry) After i use the code from that link...still how would i show the vistor amount..im guessing a variable....


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •