Results 1 to 6 of 6
  1. #1
    Web Ho - Design B!tch ~Michelle's Avatar
    Join Date
    January 18th, 2005
    Location
    Michigan
    Posts
    2,040
    I want to use an Iframe on my pages to call a php counter script.

    I have created a page for the counter script and named it counter.php

    On my pages I inserted the following code:
    <Iframe src="/counter.php" width="1" height="1"></Iframe>


    It calls the counter.php just fine, but problem is the counter of course counts the counter.php hits and not the page I am calling it from.

    Is there a way to make it count the page that the Iframe is on?
    ~Michelle
    "All I ask is a chance to prove that money can't make me happy."
    "Work to become, not to acquire." -- Confucius

  2. #2
    Affiliate Manager
    Join Date
    January 18th, 2005
    Posts
    1,056
    Try to place it in an include on the page you want to count...

    <pre class="ip-ubbcode-code-pre">
    &lt;? include("counter.php"); ?&gt;
    </pre>

    Hope that helps.

  3. #3
    http and a telephoto
    Join Date
    January 18th, 2005
    Location
    NYC
    Posts
    17,708
    Yeah, what Chet said, I don't understand why you would want a counter in an iframe....
    Deborah Carney
    TeamLoxly.com BookGoodies.com ABCsPlus.com

  4. #4
    Member Speedy's Avatar
    Join Date
    January 18th, 2005
    Location
    Lancashire UK
    Posts
    165
    I too am not sure why you would want to do this but i presume that you cant run PHP on htm pages. If you display the counter.php in an IFRAME and use an LAYER to call it, It should work.

    Paste the code below into your page where you want the counter to apear.

    &lt;IFRAME FRAMEBORDER="0" WIDTH="50" HEIGHT="50" SRC="counter.php"&gt;&lt;/IFRAME&gt;
    &lt;LAYER WIDTH="2" HEIGHT="2" SRC="counter.php"&gt;&lt;/LAYER&gt;

    You will have to adjust the iframe size to suit your counter text depending on what your counter.php code is like. Some sample counter.php code if you need it:

    &lt;?PHP

    $log_file = "count.txt"; // file to log the hits to
    if(!($fp = fopen($log_file, "r"))) die ("Cannot open $log_file.");
    $counter = (int) fread($fp, 20);
    fclose($fp);

    $counter++; // increment the hits by 1 each time

    print "$counter"; // Print the hits

    $fp = fopen($log_file, "w");
    fwrite($fp, $counter);
    fclose($fp);
    ?&gt;

    (If you use the counter code above dont forget to create the count.txt file!)

    Steve
    --------------------------------------------------
    Life at the top is hard,
    But life at the bottom is harder ....

  5. #5
    ABW Ambassador FFoc's Avatar
    Join Date
    January 18th, 2005
    Posts
    1,015
    If you want to count the referring page (that is, the one it's inserted into), you need to look at the global variable $_SERVER['HTTP_REFERRER'] when the script is run, or use a GET variable on the referring page.
    “An adventure is an inconvenience rightly considered. An inconvenience is an adventure wrongly considered.” - G.K. Chesterton

  6. #6
    Web Ho - Design B!tch ~Michelle's Avatar
    Join Date
    January 18th, 2005
    Location
    Michigan
    Posts
    2,040
    Thanks guys.

    The reason I want to do this is because the whole site is built with .html

    I tried to use the .htaccess code to have it treat .html pages as php pages, but it caused a site error. (actually, uploading any .htaccess on this host causes the error, so I am assuming that they don't allow it)

    Anyways, this appears to be the easiest way to use the PHP stats I want.

    Off to give the suggestions a try.
    ~Michelle
    "All I ask is a chance to prove that money can't make me happy."
    "Work to become, not to acquire." -- Confucius

  7. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Why use an iFrame for my links?
    By CrusaderAD in forum Amazon
    Replies: 7
    Last Post: August 16th, 2011, 07:01 PM
  2. JavaScript Calling Php Script
    By Uncle Rico in forum Programming / Datafeeds / Tools
    Replies: 2
    Last Post: January 9th, 2008, 04:42 PM
  3. How to get HTML of an Iframe
    By Loebb in forum Programming / Datafeeds / Tools
    Replies: 1
    Last Post: March 13th, 2003, 10:14 AM

Posting Permissions

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