PHP Tips & Tutorials

PHP: Get the File Uploading Limit – Max File Size Allowed to Upload

PHP file upload max size is determined by 3 configuration values in php.ini, namely upload_max_filesize, post_max_size and memory_limit. You can get the maximum file size allowed in uploading by this snippet: $max_upload = (int)(ini_get(‘upload_max_filesize’)); $max_post = (int)(ini_get(‘post_max_size’)); $memory_limit = (int)(ini_get(‘memory_limit’)); $upload_mb = min($max_upload, $max_post, $memory_limit); Wherein $upload_mb is the maximum file size allowed for upload …

PHP: Get the File Uploading Limit – Max File Size Allowed to Upload Read More »

PHP: Display Current Year to Automatically Update Copyright Years

I guess most of the websites out there are using plain strings for the years of footer copyright because many of them are still showing 2009 right now. If you have quite a few websites as I do, it’d be kind of intimidating to manually update the copyright years for all of them. So why …

PHP: Display Current Year to Automatically Update Copyright Years Read More »

PHP: Allow Specific HTML Tags in Text Input Controls of HTML Forms, <textarea>, <input type=”text” />

Textarea and text input are common html form controls that accept text input. They can be a security challenge as they allow the user to enter anything they want. If you just go about using whatever data the user has entered, your application is anything but secure. Some sort of filtering / white-listing must be …

PHP: Allow Specific HTML Tags in Text Input Controls of HTML Forms, <textarea>, <input type=”text” /> Read More »

PHP: Why you should use dirname(__FILE__).‘/include.php’ instead of just ‘include.php’

When you need to include or require a php file that is in the same directory as the currently running one, most people come up with this simple line in the current script: include(‘include.php’); While this approach doesn’t present obvious breaches, it is slightly inefficient than the following way: include(dirname(__FILE__).’/include.php’); You will type a little …

PHP: Why you should use dirname(__FILE__).‘/include.php’ instead of just ‘include.php’ Read More »

PHP: Subject String Length Limit of Regular Expression Matching Functions

Here’s a quick tip for those who have encountered this very same problem that all regular expression functions of PHP such as preg_match() and preg_replace() stop working when the input string (subject string to be searched or matched) is too long or large. If you believe your regular expressions should work but didn’t and the …

PHP: Subject String Length Limit of Regular Expression Matching Functions Read More »

Best way to hide and cloak your affiliate links?

One may first think of using JavaScript to do this by dynamically changing the windows status bar URL, but unfortunately this trick doesn’t work across Firefox browsers. The truth is the visitor or clicker will eventually find out that they’ve been referred to the affiliate merchant by you from the ultimate landing URL — sometimes …

Best way to hide and cloak your affiliate links? Read More »

How to redirect the visitor to another page or website?

This is one of the most common tasks in website development and also one of the most frequently asked question according to some of the keyword research tools. Well, you have 3 ways to achieve a web page redirection. Use PHP header() function to modify and send a HTTP Location header: header("Location: /thankyou.html"); // redirect …

How to redirect the visitor to another page or website? Read More »

PHP, JavaScript: Stop and prevent others from framing your site or web page

Though it does increase traffic and the pageviews, it doesn’t feel quite good with someone who’s loading your website or page as a part of theirs in the form of a <frame> or <iframe>, leeching your content as part of theirs. To prevent them from loading your pages this way, and make the visitor browser …

PHP, JavaScript: Stop and prevent others from framing your site or web page Read More »

PHP: Session ID changes automatically at every request / page load

Ideally the initial session id will remain the same throughout a session unless the developer has explicitly asked PHP to change it by the session_regenerate_id() function or the session_id() function. However, there’s a slight chance that you may encounter this problem of automatic changing session ID upon every new request when you are developing things …

PHP: Session ID changes automatically at every request / page load Read More »

One Simple Way to Encrypt, Obfuscate, Hide or Protect Your PHP Code

This way is so simple that anyone who’s a beginner in PHP can use it immediately to obfuscate and hide the original PHP code. Generally, it’d make it much harder for someone to find a specific phrase in your code as it’s encrypted, though in a rather simple way using 4 PHP functions: gzinflate(), gzdeflate(), …

One Simple Way to Encrypt, Obfuscate, Hide or Protect Your PHP Code Read More »

A few suggestions of good practices for accelerating PHP development

The slow and steady may win, but the fast and steady dominate. The old saying of faster not always being better may go well in other fields, but not in the IT world of today. Faster is absolutely better. You should by all means try to improve yours or your team’s programming proficiency and accelerate …

A few suggestions of good practices for accelerating PHP development Read More »

Work Around Zend Studio 5.5 PHP Class / Object / Method Auto-complete Problem

Don’t know if it’s a glitch of Zend itself but I frequently encounter this problem on Windows with Zend Studio when writing PHP. Function / object methods names auto-completion saves a lot of time by suggesting candidates and a quick flyover tooltip with the synopsis, however sometimes it doesn’t work with newly created functions and …

Work Around Zend Studio 5.5 PHP Class / Object / Method Auto-complete Problem Read More »

Best PHP Books for Learning PHP Development and Programming (with MySQL)

PHP is by far the most popular and easiest to use web programming language in the world. If your goal is to enter PHP programming and development as a novice beginner and start from the very basics, these books are reviewed the best by actual readers. Some of the books contain chapters dealing with MySQL, …

Best PHP Books for Learning PHP Development and Programming (with MySQL) Read More »

PHP, MySQL: Calculate Number of Days between 2 Dates or Number of Hours, Minutes and Seconds

This is a rather common task in both PHP and MySQL, that is, to calculate and get the days distance (number of days) between 2 given dates. In PHP, to get the number of days between now and a future date / a past date: $days = abs(strtotime(“2011-11-20”) – strtotime(date(“Y-m-d”))) / (60 * 60 * …

PHP, MySQL: Calculate Number of Days between 2 Dates or Number of Hours, Minutes and Seconds Read More »

MySQL, PHP: Display MySQL table fields and data

While this may seem simple, but it’s more complicated than it may appear because you have to first decide which data (rows, fields, etc.) to be extracted or selected and in what way the data from the MySQL table are presented. But to simply read from a MySQL table for the fields and data: SELECT …

MySQL, PHP: Display MySQL table fields and data Read More »

Scroll to Top