DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

UK-US Data Bridge: Join TechnologyAdvice and OneTrust as they discuss the UK extension to the EU-US Data Privacy Framework (DPF).

Migrate, Modernize and Build Java Web Apps on Azure: This live workshop will cover methods to enhance Java application development workflow.

Kubernetes in the Enterprise: The latest expert insights on scaling, serverless, Kubernetes-powered AI, cluster security, FinOps, and more.

A Guide to Continuous Integration and Deployment: Learn the fundamentals and understand the use of CI/CD in your apps.

Avatar

Michael Bernat [Deactivated] [Suspended]

TPM at Amazon

Seattle, US

Joined Dec 2006

About

I am a 23-year-old living in Blacksburg, Virginia (Virginia Tech). I have been working with the web since I learned HTML in 7th grade and have been having a lot of fun with it ever since. I work for a local design and development company called New City Media as a PHP programmer and database developer. My work-load consists of mainly writing PHP code, designing database tables in MySQL 4/5 or MSSQL 2005, general tech support for our hosting, DNS, and database servers and also the occasional tech support call for a client.

Stats

Reputation: 62
Pageviews: 116.3K
Articles: 1
Comments: 54
  • Articles
  • Comments

Articles

article thumbnail
How to Create a Simple PHP Text Counter
After learning the basics of PHP's basic file system functions, the first thing you'll want to do is put it to use. One of the easiest and flashiest things you can create is a page counting script. I'll show you how to create a page hit script that is easy to create and even easier to implement. This is the entire script. Let's go through it line by line. $filename = "counter.txt"; This assigns the filename to a variable to be used throughout the rest of the script. In this case I used counter.txt. The first thing to do after implementing this script is to create counter.txt on your server in the same directory as this script and chmod is to 777 so that PHP may write to the file later on. Here is a great tutorial on how to chmod files: http://support.discusware.com/center/resources/howto/chmod.html $count = file_get_contents($filename); This line stores in entire contents of counter.txt into the variable $count. In this case there is only a number inside counter.txt so $count holds that number. if ($count == null) $count = 0; If the file is empty we need to make a case for that or problems will come up later. If $count does not contain anything than we go ahead and set $count to 0. echo $count; This will display the number inside the text file. $count++; This adds 1 to the current $count. $handle = fopen($filename, "w+"); The next thing to do is to open the file for writing and to truncate it (erase its contents), that's why I choose w+. Please see my article on file system basics for an explanation on other modes. fopen() requires that we assign a resource handle to be referenced in the future. fwrite($handle, $count); This line writes the variable $count to our file represented by $handle. fclose($handle); This is the final line of the script where we do some cleanup. This closes the file we opened earlier. It isn't essential to the script what its always nice to cover all bases. Now that you understand how the script works it's time to implement it. This assumes you name the script above counter.php. Wherever you put this in your page is where the script will echo the page hit count. It's as easy as that.
October 24, 2011
· 15,224 Views · 0 Likes

Comments

The Ideal Burndown Chart

Jul 20, 2019 · Reinout Korbee

Did I miss your ideal burndown chart or are you saying it's the one where the team doesn't complete their sprint?? Agree with Chris. It's tracking progress on DAILY estimates. If you're blowing daily commitments day after day then your burndown chart should reflect that.

Interface in PHP

Oct 31, 2011 · Avinash Zala

An interface and coding standard are completely different.
PHP Data Types - Octal Notation

Jun 28, 2011 · mitchp

Cool! I had no idea you guys were still using my articles :D
Startups: Get Scrum'd For Free For a Year

Nov 17, 2009 · Robert Dempsey

I've seen and heard about the features in Scrum'd and can offer this opinion: If you're just getting started with Agile or a seasoned vet, Scrum'd can definitely make your life easier.
Most Used HTML Tags in 50 Popular Web Sites

Oct 19, 2009 · house

Thanks.. I was hoping there would be a twist at the end but apparently not.
Checklist For Better Forms

Sep 11, 2009 · Mert TOL

Good stuff
A Hidden Gem in HTML

Sep 08, 2009 · Yan Fortin

I can't believe this is astonishing as many people as it has. As far as I know this has not been confirmed by anyone on their side. And you can clearly see the smaller mountain to the right of Fiji is nowhere to be found in the original image. And the 3rd mountain on the right doesn't fit at all. It all seems like a mediocre coincidence that it fits as much as it does.
How to become a rock star developer?

Sep 01, 2009 · Gregory Mostizky

wtf is this
Top 10 Most Usable Content Management Systems

Aug 28, 2009 · Aayush Shastri

Another Top ## article from Glenn at nuttuts.
Simple PHP URL Routing Controller

Jul 05, 2009 · David Gonzalez

It's like a singleton gone wild
A serious PHP design flaw - watch out!

May 20, 2009 · Csaba Okrona

I think the first example has a typo: $a[$b] = 'whatever'; should be $arr[$b] = 'whatever'; But I agree, PHP's type juggling can be a headache.
How to write fast code

Mar 24, 2009 · Kris Brixon

I'm curious to know how many people DON'T think that way. I was taught that programs run like a car driving down a highway. Your speed stays the same so the only thing effecting how fast you arrive at your destination is the length of the road. It's the little things :)
Do Not Micro-Optimize

Mar 11, 2009 · Stefan Koopmanschap

Articles like this one also make me angry. When writing a for loop do you perform the total item count before the for decoration or in it? It has no affect on the functionality of your script/application but it's a huge difference in overhead. Simply realizing that performing the count and storing the value before the loop begins is trivial. I appreciate articles like the original mentioned here but it seems like people take them way too seriously. I don't believe they're saying go back through all your code and fix these changes. Rather, in the future use this method and save yourself a couple cpu cycles. I can certainly understand why writing all class methods as static could be a bad idea. But the author, and so many others, are taking it for absolute/face-value. A static method is faster, yes. Should you use it everywhere, no. Simply having the knowledge that static methods are slightly faster than normal ones gives a developer something to consider when choosing between the two options. Blanket statements like 'x is the root of all evil' are even more evil.
The 5 Most Under-Used HTML Tags

Feb 25, 2009 · Mr B Loid

Good list. The last one of these I saw was full of deprecated tags... I think font was one of them
5 Ways to Instantly Write Better CSS

Feb 16, 2009 · Mr B Loid

What's with the giant images on nettuts articles these days? ,
Solving Soduku puzzle with only MySQL

Feb 11, 2009 · Juozas Kaziukenas

Pretty cool. Reminds me of rule-based programming.
Anti-pattern - Wikipedia

Feb 05, 2009 · Thierry Lefort

In the future, please check with MTaylor and nyhuhuu before submitting a story to see if they have seen it before. -Thanks :p
Are You Making These 10 PHP Mistakes?

Feb 04, 2009 · Stefan Koopmanschap

I took too long to edit my comment. I realized I misunderstood what the author was trying to say about encrypting session values. I don't think he understands how sessions work. Anyway, I had a whole thing typed up about how many of the points were misleading, poorly explained, or flat-out false but Terry Chay does a nice job explaining in his comment on the site.
Are You Making These 10 PHP Mistakes?

Feb 04, 2009 · Stefan Koopmanschap

Why would you store a user's password in a session variable? Honest question.. I can't seem to come up with a reason where it would come in handy to have the password readily available.
Design Patterns - The Singleton

Feb 02, 2009 · Michael Bernat

@newton_dave Apologies for the horribly constructed sentence. I think what I was trying to convey was the degree of it's effectiveness often comes under fire. I stand by the closing statement. I haven't seen a convincing argument that showed that singletons don't have their place. One of my key points was to be mindful of the situation you're using it in. If you abide by that and use the pattern in situations where you're not trying to force it than I think it is very effective. Thanks for the input.
Ten tips for bug tracking success

Jan 25, 2009 · Ka Wai

It pains me to remember all bug reports that were essentially 'It doesnt work'.
Eclipse PHP upgrade tackles object-oriented programming

Jan 22, 2009 · Mr B Loid

Am I missing something obvious? Eclipse PDT 2.0 came out on December 29th. http://www.eclipse.org/pdt/
Delete a Record with animation fade-out effect using jQuery and Ajax.

Jan 20, 2009 · Mukunda rao

The effect is cool, but some of the code is lacking as described in the comments on the site. To add to said comments, there needs to be something in addition to the record id in the post/get action to stop people from just inserting random numbers and deleting everything in the table.
Testing Your Code to Test Yourself

Jan 16, 2009 · Alvin Ashcraft

Well said. I've found that realizing how to write testable code in itself can make a huge difference in quality.
ZipTie: First Week Assessment

Jan 16, 2009 · Larry Holcher

Thanks for the comments everyone :)

@Arek

I certainly don't recommend coding in a bad style. In fact I don't think I did that. However, doing things like simplifying conditional statements by putting them in a function simply isn't necessary. The point I was trying to make was to not get caught up in making beautiful, understandable, code from the very beginning. This is NOT to say that you should give a rat's ass about comments, readability, and absolutely not functionality. If you are a lazy coder, refactoring is not for you because you have bigger problems to deal with.

@Tracy

I would agree with you that refactoring is definitely a more serious degree of 'cleaning up your code'. However, I'm not so sure that enhancements or additions qualifies as refactoring. Correcting possible bugs or creating extra cases for something also, imho, falls outside of refactoring.

@Ronald

I'm not sure if you are defending or attacking my words. Either way, read my above comments to Arek. I guess I have to get used to people interpreting my statements as being absolute.. I'm more of a middle of the road kinda guy.

The topic I did not touch on but should have, in this small, quick post, is the importance of unit-testing. As we all should know by now is that when we go back and touch code, in any respect, you risk breaking some part of your site. Hopefully it's obvious, but what if you broke a fringe case? Unit-testing is critical.

Code Refactoring - Freaking Awesome

Jan 16, 2009 · Michael Bernat

Thanks for the comments everyone :)

@Arek

I certainly don't recommend coding in a bad style. In fact I don't think I did that. However, doing things like simplifying conditional statements by putting them in a function simply isn't necessary. The point I was trying to make was to not get caught up in making beautiful, understandable, code from the very beginning. This is NOT to say that you should give a rat's ass about comments, readability, and absolutely not functionality. If you are a lazy coder, refactoring is not for you because you have bigger problems to deal with.

@Tracy

I would agree with you that refactoring is definitely a more serious degree of 'cleaning up your code'. However, I'm not so sure that enhancements or additions qualifies as refactoring. Correcting possible bugs or creating extra cases for something also, imho, falls outside of refactoring.

@Ronald

I'm not sure if you are defending or attacking my words. Either way, read my above comments to Arek. I guess I have to get used to people interpreting my statements as being absolute.. I'm more of a middle of the road kinda guy.

The topic I did not touch on but should have, in this small, quick post, is the importance of unit-testing. As we all should know by now is that when we go back and touch code, in any respect, you risk breaking some part of your site. Hopefully it's obvious, but what if you broke a fringe case? Unit-testing is critical.

CakePHP 4 - Saving and Validating Data

Jan 14, 2009 · Brandon Cannaday

I didn't look at it that hard once I realized it was the previous version of cakephp. However, after taking a second look, all the validation-related lines in the controller are no longer necessary as they are taken care of in the save() method. The html and session helpers are included automatically and do not need to be defined. I'm pretty sure neither of those small issues will break if you upgrade to 1.2. I was just trying to give a possible solution if anyone ran into problems with this tutorial while using the latest stable release. The article is still a pretty good intro and I would recommend it, with the disclaimer.
CakePHP 4 - Saving and Validating Data

Jan 13, 2009 · Brandon Cannaday

That is a pretty old version of cakePHP, the styles have been vastly upgraded. Edit: The author left a comment on the first article in the series saying that he downloaded the 'stable' release back in October.. which was released atleast a year before that. For anyone reading this, 1.2 stable has been released and IBM said it was enterprise ready many months ago. I scanned over the article but beware of deprecated functionality used.
Choosing a PHP framework to work with

Jan 07, 2009 · Veera Sundar

This would be better at stackoverflow.com
PHP is not my thing

Dec 26, 2008 · saqib ku

Read the rfc spec on namespaces before criticizing it.
Stunning 128 free icons by wefunction

Dec 18, 2008 · Adrian MG

Author's link: http://wefunction.com/2008/07/function-free-icon-set/
MVC - Fat Models and Skinny Controllers

Dec 08, 2008 · Mike Bernat

If you were responding to me: I'm absolutely not saying that PHP, et all, MVC frameworks are superior than all others. I'm not saying one way or the other. I'm just touching on the fact that they all seem to follow the same flavor of MVC which does not follow a purist's interpretation of the pattern. I was writing to this flavor that seems to be the fad now a days.
Grinds my gears; PHP < version 5

Oct 15, 2008 · Dougal Matthews

Looks like I got my knuckles lined up for nothing. Good point though, I didn't realized php5 had been out that long.
12 PHP optimization tips

Jul 28, 2008 · Adam McKerlie

Citation Needed
Egoless Programming - Developing Without the Attitude

Jul 16, 2008 · Michael Bernat

I actually address this later on in the article. It is difficult to adopt the 'ego-filled' culture unless everyone is on board. However you are right in the sense that if you can pull it off you will see a huge jump in the quality and productivity of your workers. There is no right way.. but when in doubt, egoless will keep you out of trouble.
How To Create A Keypress Navigation Using jQuery

Jul 07, 2008 · Rolf Strijdhorst

Why do 75% of the jquery tutorials I see perform some kind of usability nightmare but in a cool way? I'm not going to vote this down cause you did a fine job explaining how you achieved this neat effect but whenever you switch out the main content of a page 95% of people on the internet will expect the back button to go back to the page they were just on.. or in this case the content they were just viewing. ,
The Ternary Operator

Jun 24, 2008 · Michael Bernat

To each his own. It's very easy to get carried away and lose the readability bonus you get with ternary operators. If you have to think for a second if this is easy to read or not.. you're probably better off with a good ole' if-then statement.
New PHP dedicated job site

Jun 18, 2008 · Manuel Lemos

Great new feature to a long list of existing ones.. but does anyone really get turned off by their design?
Firefox 3 is here, but should web developers switch?

Jun 18, 2008 · Daniel Saxil-Nielsen

I've been using FF3 since the first beta compatible with firebug. I've seen no reason not to get it.. aside from the horror stories on *nix. All the other essential developer extensions are working fine with me.
MySQL - InnoDB vs MyISAM

Jun 15, 2008 · Michael Bernat

From MySQL manual: You can combine transaction-safe and non-transaction-safe tables in the same statements to get the best of both worlds. However, although MySQL supports several transaction-safe storage engines, for best results, you should not mix different storage engines within a transaction with autocommit disabled. Like i said in the article.. you need both if you're going to have a log table and an articles table with full-text searching.. just be careful when you're running a join query on both which in the real world happens once in a blue moon. Look around the web and you fill find tons of sites who utilize both tables and are able to enjoy both benefits.
Funny comment about php

Jun 13, 2008 · christiaan baes

Lame
You know your programming lang sucks when you have this

Jun 09, 2008 · admin

What's the problem? The variable names could be a little better.. but that works. Variable juggling is God's gift to man - embrace it.
20 top add-ons that are ready for Firefox 3

May 27, 2008 · Tony Thomas

I've been looking for something like Speed Dial for a long time.. glad one of these Top Firefox Extension lists actually is showing something new.
XAMPP is The Best Choice for Programmers

May 27, 2008 · admin

WAMP server does everything I need very quickly and easily
PHP Sucks, But It Doesn't Matter

May 21, 2008 · Mr B Loid

Can someone explain why having a lot of functions beginning with the letter A is evidence of a bad programming language?
How to make multiple updates using a single query in MySQL

Apr 21, 2008 · Indiana Jones

That is a horrific idea. Title should be: "Update 2 records by updating everything else with itself". Kudos for thinking outside the box but what made you think this would save time?
checking username availability using jquery’s fading effect

Apr 11, 2008 · Roshan Bhattarai

Anything fading is pretty anti-usability in my book. It looks pretty but as far as being functional.. it's rock bottom.
HTML 5 Web Page

Feb 03, 2008 · Shaun Anderson

From the looks of it.. they're just replacing with and things like that. Is this really an improvement? I don't know very much about html 5 but from the looks of this article that seems to be the case.
DZone Suggestion, More Comments

Jan 28, 2008 · Steven Harris

Agreed!
Defending PHP

Jan 24, 2008 · Jim Wilson

PHP's strength and weakness is that it is flexible. Done. The only reason rag on php is because a lot of people write poor code. It's not php's fault that you didn't check for sql injection.
Defending PHP

Jan 24, 2008 · Jim Wilson

One is case sensitive.. am I missing something?
7 PHP functions that saved my life

Jan 20, 2008 · Phil Thompson

My god this was awful.. From the foreach() section: "One of my first projects, as a proper web developer (at an agency) ... [was] a nightmare getting the data out until I discovered foreach()" "It’s my favourite loop by far… in fact it’s pretty much the only loop I ever use." That entire section should pretty much bar you from any future coding in any language.
I hate PHP - evacuate all of your hate against PHP

Nov 29, 2007 · Dan Sim

You're a bad programmer.
PHP messiness: zero isn’t false, or is it?

Sep 21, 2007 · Mr B Loid

This is bold, highlighted, and red on every array function listed on php.net's manual.

User has been successfully modified

Failed to modify user

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: