Search:
Main Menu
Login | RSS |

Quick PHP Code Tips and Examples

PHP Programming Tips, Tutorials and Source Code Examples for newbie

Session Error on PHP 4.4.x ? Try $_SESSION

March 11th, 2007 by Jon Moffet

If you encounter session error on PHP 4.4.x, especially when you're porting scripts written from earlier PHP release (i.e PHP 4.1.x, 4.2.x) when handling sessions, chances are that you are using the deprecated session_register() function.

Solution: Replace session_register function with $_SESSION variable instead.

This will make your scripts upward-compatible with PHP installations that disabled register globals and eliminate those weird session errors message

reference: http://www.php.net/session_register

Tags: , ,

Posted in Uncategorized | No Comments »

DOM-XML extension not working in PHP 5?

March 10th, 2007 by Jon Moffet

If you're porting your PHP4 scripts that uses DOM-XML for xml-parsing to PHP5, then you might have stumbled into this particular problem, PHP5 has no DOM-XML extension.

This is because PHP 5 has a new integrated DOM functions which replaces PHP4 dom-xml equivalent.

However you don't need to do a complete rewrite in order to make your DOM-XML PHP 4 scripts work with PHP 5. All you need to do is to include a fix from http://alexandre.alapetite.net website.

First, download domxml.phps, then include it in your php scripts

PHP:
  1. require('domxml.phps');
  2.  
  3. // the rest of your script that uses dom-xml goes here...

After that your PHP4 script is able to work normally in PHP5 environment :)

Tags: , , , , ,

Posted in Uncategorized | No Comments »

PHP Snippets : Email Validation Source Code

March 8th, 2007 by Jon Moffet

Here's a simple function to validate email in your PHP scripts.

To use it just call isValidateAddress("email@example.com"). The function returns 'true' if the email is valid and 'false' otherwise.

PHP:
  1. <?php function isValidAddress( $email, $check = false )
  2. {
  3.   ##############################
  4.   # PHP Email Address Validator
  5.   # (C) Derrick Pallas
  6.  
  7.   # Authors: Derrick Pallas
  8.   # Website: http://derrick.pallas.us/email-validator/
  9.   # License: Academic Free License 3.0
  10.   # Version: 2006-12-01a
  11.  
  12.   if (!ereg(''
  13.       . '^'
  14.       . '[-!#$%&\'*+/0-9=?A-Z^_a-z{|}~]'
  15.       . '(\\.?[-!#$%&\'*+/0-9=?A-Z^_a-z{|}~])*'
  16.       . '@'
  17.       . '[a-zA-Z](-?[a-zA-Z0-9])*'
  18.       . '(\\.[a-zA-Z](-?[a-zA-Z0-9])*)+'
  19.       . '$'
  20.       , $email
  21.       )    ) return false;
  22.   list( $local, $domain ) = split( "@", $email, 2 );
  23.   if ( strlen($local)> 64 || strlen($domain)> 255 ) return false;
  24.   if ( $check && !gethostbynamel( $domain ) ) return false;
  25.   return true;
  26.  
  27.   # END
  28.   ######
  29. }

Tags: , , , , ,

Posted in Uncategorized | No Comments »

Redstone - Simple and Compact Java XML-RPC library

March 7th, 2007 by Jon Moffet

Yesterday I had to look for a simple Java XML-RPC library in a simple proof of concept application.

Plainly speaking, I'm going to demonstrate XML-RPC concept to a bunch of friends who is unfamiliar with programming languages other than Java (but they are not 1337 programmers either!)

I'm looking for a simple library which isn't bloated with functionality and easy to use. After much surfing, I found Redstone XML-RPC Library.
Read the rest of this entry »

Posted in Uncategorized | 1 Comment »

PHP Code to check and verify Splog (Spam Blog)

March 6th, 2007 by Jon Moffet

Spam blog or splog is a nuisance, it is a blog which consists of content largely taken from other website without any modification. The primary motivation for creating splog is for getting a top searching placement and getting profit from Pay-Per-Click advertisement.

If not monitored closely, Spam blog can be harmful to content searching where it pollutes search engine with copycat content or articles which has no value at all.

Luckily there is a service which lets you identify spam blog, antisplog.net which contains database of well known spam blogs.

Antisplog provide a simple api which you can use to check whether the given website url is a splog or otherwise, this can be use to integrate AntiSplog functionality right into your own web application in order to weed out spam blog listing in your website.

Here's the sample code to check spam blog using AntiSplog api :
Read the rest of this entry »

Posted in Uncategorized | 1 Comment »

« Previous Entries Next Entries »