Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8298313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:43:36+00:00 2026-06-08T15:43:36+00:00

I am facing a curious situation. I am using CakePHP 2.0 (locally), XAMPP and

  • 0

I am facing a curious situation. I am using CakePHP 2.0 (locally), XAMPP and I wanted to add a simple hit counter in my homepage so I added the following code (very very simple)

<?php
$filename = 'hitcount.txt';
$handle = fopen($filename, 'r');
$hits = trim(fgets($handle)) + 1;
fclose($handle);

$handle = fopen($filename, 'w');
fwrite($handle, $hits);
fclose($handle);

echo $hits;

There is a text file named hitcount.txt which contains the number of hits (everytime I visit the page it should increase the number of hits). It works. The problem appeared when I tried to access the hitcount.txt file. It was empty but the echo of $hits returned the exact result! I deleted the file and it still shows me the expected result! I used a different browser, the same. I deleted CakePHP’s cache, no change. I used the same piece of code in another page and it did not complain with some error, returning the expected result.

How is it possible for Cakephp to “see” a file that does not exist? Has it anything to do with Apache?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T15:43:38+00:00Added an answer on June 8, 2026 at 3:43 pm

    You probably view the file at the wrong location as CakePHP’s. My guess is CakePHP’s referring to the file at app/webroot/hitcount.txt.

    You might want to define a full path for hitcount.txt so you can be sure that you and CakePHP are both referring to the same location.

    <?php
    $filename = TMP.'hitcount.txt';
    

    This would locate the file at `app/tmp/hitcount.txt’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Guyz facing problems with creating a push notification service (for android) using Google C2DM
Im facing the following problem: I want to integrate the mercurial hash into my
Am facing a problem, while creating components through TOM API using .NET/COM Interop. Actual
Facing problem for generating SQL Server Query In the Following query dynamic conditions are
Im facing a problem using the UIImagepicker. If i use the camera on my
I am facing a problem of adding overlays. I want to add button which
Facing problem with every fetch i want to make using EF Query model.Place here
I´m facing this problem: I have a Button that works like a WrapPanel using
Facing an interesting issue when I am using WCF Web API with Hammock and
Im facing an issue how to correctly package my enterprise (EAR) application with simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.