Skip to main content

Posts

PHP: Recording Page Hits

Wanted to create something that was easy to use, maintain and grow. It's extremely basic as it is. It stores the page visited and if the user is logged in, their id; if the user is not logged in, it currently stores "0" as the user id. Later, this class might expand to store the user's browsing history by recording their IP address and the pages that they visit. You'll first need to create 2 tables within your database: pages and statistics. You'll need 3 but I'll show you how to create two. The third one is users that you should probably already have if your users are logging in at all. Note: I'll show you how to create the ReportError class in my next post. The pages stores the URI for each page. You don't want to store the page within the statistics table, just the id. This is for optimization and to minimize repetitiveness. The next table is the statistics table. This table contains the id's referencing other tables and the times ...

PHP: Main Controller Tweaks

I wrote about the main controller a few days ago. Looking at it now, I've decided to make one tweak that was necessary and one that's purely for performance (and to keep consistent). To review the previous version, visit: http://dinocajic.blogspot.com/2015/07/php-main-controller.html The main change done is to the processHeaders() method. When logging in or out, it's required that the SESSION and COOKIE creation and deletion is done before any information is submitted. This is what the processHeaders() method looked like before: And this is what the modified processHeaders() method looks like. As you can clearly see, the logout, the SESSION based login and the COOKIE based login are all processed through this method.

My thoughts on Climate Change

There have been so many studies done on humans' effect on climate change that the burden of proof shifts from the people trying to prove that it's real to the people that negate it. For accurate information regarding climate change, visit: http://climate.nasa.gov Some stats for you: Carbon dioxide levels in the air are at their highest in 650,000 years Carbon dioxide (CO2) is an important heat-trapping (greenhouse) gas, which is released through human activities such as deforestation and burning fossil fuels, as well as natural processes such as respiration and volcanic eruptions.  As of June 2015, we're at 400.47 ppm (concentration of mid-tropospheric carbon dioxide in parts per million). The 10 warmest years in the 134-year record all have occurred since 2000, with the exception of 1998. The year 2014 ranks as the warmest on record. Sea level rise is caused primarily by two factors related to global warming: the added water from melting land ice and the ex...

Breaking down Stress: How it forms and what it does

You might have noticed by now that I like to break down everything to it's simplest forms. Today, I'm tackling stress. The following document contains a series of paragraphs that I believe best helps explain the phenomenon. "Stress is simply a reaction to a stimulus that disturbs our physical or mental equilibrium. In other words, it's an omnipresent part of life. A stressful event can trigger the “fight-or-flight” response, causing hormones such as adrenaline and cortisol to surge through the body. A little bit of stress, known as “acute stress,” can be exciting—it keeps us active and alert. But long-term, or “chronic stress,” can have detrimental effects on health. You may not be able to control the stressors in your world, but you can alter your reaction to them. Cortisol is a steroid hormone, belonging to a broader class of steroids called glucocorticoids, produced by the adrenal gland and secreted during a stress response. Its primary function is to redistribute...

Microsoft Word Mail Merge

Mail Merge is extremely simple in Word 2010 however it seems that because I don't use it as often, I always have to dig around and find out how to use it. Here are the step-by-step instructions on how to easily do mail merge. 1. Create an Excel Sheet with headers in the top row (i.e. Name | Address | Street | ST | Zip) 2. Populate the Excel sheet with the content. Save upon completion. 3. Open Word 2010 4. Click the  Mailings  tab. 5. Click  Start Mail Merge  and select  Labels . 6. Select  Label Vendor  (i.e. Avery) and select  Product Number  (i.e. 5160 Easy Peel Address Labels). Click  OK . 7. Click on the  Select Recipients  and select  Use Existing List . 8. Browse and find your Excel Sheet and Click  OK . Make sure that  First row of data contains column headers  is checked. 9. Make sure that your cursor is in the first label ...

PHP: The Main Controller

Last time I wrote about using the index.php page as the gateway to the main controller: http://dinocajic.blogspot.com/2015/07/php-using-indexphp-as-your-main.html Since it's a secure habit to place all of your code outside of the visible directory (outside of the www or public_html folder), I've created a class that index.php directs all of the information to and that class is the one that actually processes everything. Breakdown of the Main class All files included in the beginning All required classes instantiated In the __construct(), the redirect is called to push all domains to a specific domain name Due to the amount of times certain hacks are attempted on the server, I've decided to place some of the common ones in the preventHack() method and prevent them before any other code is called. The available pages that the website contains are populated into an array Headers are processed. i.e. Logs the user in if $_COOKIE's are set Previous page is record...

PHP: Using index.php as your main controller

For a normal sized website you can use one page as your point of entry and retrieval of all of your pages. In the following example, I've created a class called IndexController that tests whether we're on a test server or not (to display errors or not) and then calls the class that will process the ?page $_GET variable.