PHP Tips & Tutorials

PHP: Checkbox Array in Form Handling – Multiple Checkbox Values in an Array

Checkboxes is probably one of the most frequently used form controls which come handy in dealing with one to many relationships. The multiple selective nature of HTML form checkboxes require a convenient way for PHP to process multiple checkbox values, ideally in a single array. By default, each and every HTML input control including checkboxes …

PHP: Checkbox Array in Form Handling – Multiple Checkbox Values in an Array Read More »

PHP: Escape String Literals for SQL, mysqli::real_escape_string and PDO to Prevent SQL Injection Attacks

To successfully run a query with text data containing single quotes ‘ as well as other SQL reserved punctuations, AND to prevent SQL injections, you will always want to escape the text values before using them in a SQL query. In PHP 4.0, we are stuck with mysql_real_escape_string. With PHP 5.0, mysqli:prepare and mysqli::real_escape_string are …

PHP: Escape String Literals for SQL, mysqli::real_escape_string and PDO to Prevent SQL Injection Attacks Read More »

PHP: Prevent SQL Injection Attacks

SQL injection is a typical code injection attack that exploits weaknesses of application in the database layer. SQL injection vulnerability is created when one scripting or programming language is embedded in or used as input in another with failure to verify the legality or filter for potential dangerous codes. SQL injections are possible when input …

PHP: Prevent SQL Injection Attacks Read More »

Top 25 Most Dangerous Web Programming Errors, Loopholes and Bad Habits

As Web becomes one of the most fundamental means of communication and information delivery nowadays, and as its usage reaches population level in regards to that when the televisions prevailed, the protection of it has never been so critical. SANS institute in association with US government and various other weighty contributors, most of whom IT …

Top 25 Most Dangerous Web Programming Errors, Loopholes and Bad Habits Read More »

PHP: File Upload Script (HTML Form + PHP Handler Class)

It’s sometimes cumbersome to handle uploaded files — checking if it is really uploaded, moving and renaming. Why not writing all these chores into a class and make our own file upload script? First we are going to create a simple class to handle uploaded files and move them to some place we designate for …

PHP: File Upload Script (HTML Form + PHP Handler Class) Read More »

PHP: Resize Image and Store to File

While there are a lot of methods for you to resize images with php, we will be using extension gd this time. Make sure you or your hosting company has installed it in the php distribution by running <?php if (extension_loaded(‘gd’)) { // return true if the extension’s loaded. echo ‘Installed.’; } else { if …

PHP: Resize Image and Store to File Read More »

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax …

Scratching your head for a mystic error in your SQL query? No matter how you look into it, it just seems right and should by the God’s name work as you have wished. But it doesn’t and keeps pumping out annoying SQL syntax errors. Don’t panic, I have a few tips on this that might …

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax … Read More »

PHP Array Length Function to Get Length of Arrays

PHP Arrays are collections of items identified and ordered by index. Array length is just the number of elements it contains. For an array: <?php $greetings = array( ‘Good morning!’, ‘Good afternoon!’, ‘Good evening!’ ); ?> The length of array in PHP code above is simply the number of strings contained in it, in this …

PHP Array Length Function to Get Length of Arrays Read More »

How to pass variable values in URL from page to page with PHP?

You can see dynamic URLs everywhere on the web with busy interactive sites. Variables and their values are passed from one page to another in this way. Or more precisely, a page served in PHP (a single file php script) can accept external input in the form of a dynamic URL such as http://www.asite.com/[email protected]&subject=hi&body=bye. In …

How to pass variable values in URL from page to page with PHP? Read More »

How to build a php query string without question mark

As a result of the spreading SEO awareness and how Google works, it is always recommended to use as less dynamic URLs as possible for your site. If one must, try using as less variables in the dynamic URL as possible. A dynamic URL is one with a question mark that passes dynamic variables to …

How to build a php query string without question mark Read More »

Pretend your scraper script as a browser when scraping in PHP

It’s easy to make a simple scraper script in PHP but it’s also easy for data-centric sites to detect and keep out suspiciously continued page accesses done in large amounts and a small period of time. There are usually 2 ways for a site to detect possible scraping activities. One is to make sure the …

Pretend your scraper script as a browser when scraping in PHP Read More »

Warning: session_start(): Cannot send session cookie – headers already sent

It is known that you have to make sure nothing’s already sent to output to perform a successful http header modification. As such, in PHP, you will keep an eye on possible white spaces before the use of header() function to modify delivery headers. For example, <?php header(‘…’); ?> this tiny snippet would fail if …

Warning: session_start(): Cannot send session cookie – headers already sent Read More »

Scroll to Top