Main Menu
Login | RSS |

Quick PHP Code Tips and Examples

PHP Programming Tips, Tutorials and Source Code Examples for newbie

Detect Alphabet only string with ctype_alpha

June 5th, 2008 by Jon Moffet

There are times when you need a function that can detect strings which contains onlyalphabetic characters. While is_numeric can validate a given string contains numeric character, there are no is_* function variation exist which can do the same for alphabetic strings.

However, you can still test for alphabetic string using ctype_alpha() function. Example usage :

  1. if (ctype_alpha($testcase)) {
  2.         echo "The string $testcase consists of all letters.\n";
  3.     } else {
  4.         echo "The string $testcase does not consist of all letters.\n";
  5.     }
  6. }

Good luck, and happy coding.

Posted in Uncategorized | No Comments »

How to Truncate table in SQLite database

June 4th, 2008 by Jon Moffet

I found out that truncating SQLite database is a little bit different from its MySQL counterpart. Here's how to truncate SQLite database from command line

  1. sqlite your_database.db
  2. sqlite> DELETE FROM some_table;

after that, dont forget to execute VACUUM to compact the database :

  1. sqlite> VACUUM;

Posted in Uncategorized | 32 Comments »

Quick PHP Code is back!

April 30th, 2008 by Jon Moffet

Quick PHP Code is back! So appology for the delays caused due to some unavoidable circumstances. We are no back!

Posted in Uncategorized | No Comments »

How to solve file_get_contents and file() PHP errors

May 18th, 2007 by Jon Moffet

file_get_contents() is a function use to read an entire file to a string. It is occasionally use as a convenient function to retrieve web pages from remote servers in trivial PHP scripts.

However, some web servers has disabled the URL retrieving capabilities in file_get_contents() function for security reasons, this caused scripts written with this function throws out an error which can render the whole web application useless in that particular web server.

To remedy this, you can replace file_get_contents() function with PHP cURL calls. Here's how you can do this.


CURL solution

Although the cURL version seems to be a little bit longer, it is guaranteed to work across servers which place restriction on file_get_contents() and file() function. The use of libcurlemu ensures that the script can work even on a server which doesn't have the PHP CURL extension, which makes this a universal solution for retrieving remote web content from PHP application.

Tags: , , , , , ,

Posted in Uncategorized | 12 Comments »

SQL Injection Examples (Cheatsheet)

May 16th, 2007 by Jon Moffet

If you're writing web application that has access to database, then you should be aware that those application are susceptible to SQL Injection attacks which leave information stored in your database vulnerable from a malicious cracker.

This can led attacker to access private areas in your web application, steal sensitive information, erase your database or alter certain information in the database for his own gain. Therefore it is prudent to safeguard your web application by filtering unsafe input variables before inputting them into SQL statements.

How crackers perform SQL Injection
Here is a list of common SQL injection technique employed by malicious users across the internet.

Another good read that I suggest is SQL Injection by examples which provide great explanation of how SQL Injection attacks are performed.

Tags: , , , ,

Posted in Uncategorized | 228 Comments »

« Previous Entries