Email verification using tokens – CakePHP

Web & Code 16 Comments

I recently wrote a code for an email verification system using cakephp. Well, before you use it there are few things. This is written by a cake noob so may not be the best there is. I have not written it as a general stand alone piece of code. So its need modifications for use. And I am a sucker when it comes to commenting and formatting my code so please dont mind. My thanks to Edward and the CakePhP Google Groups. And finally cake rocks!!!


Database Table

A basic user table with the following columns

id - primary key and auto increment
activate *

*columns with which we are concerned with

Controller code

class UsersController extends AppController {
var $name = 'Users';
var $helpers = array('Html', 'Form');
var $components = array('Email');
function register() {
if (!empty($this->data)) {
$this->User->data = $this->data;
//Create Token using form data and random number to ensure its unique and cannot be replicated
if ( $this->User->validates()) {
//Save all form data including the tokenhash
$ms='Click on the link below to complete registration ';
//create mail body
$this->Email->from = 'yourName <email>';
$this->Email->subject = 'Confirm Registration for Niwiki - reg.';
//send mail
$this->Session->setFlash('Please Check your email for validation Link');

Read the rest of this entry »

Simple RSS reader based on PHP

Web & Code No Comments

There are many RSS parsers, readers and 3rd party scripts which do the work of reading a rss feed and displaying it on an external web page. When I ran into this problem recently, I decided to write for myself a plain simple code which could do the job without much of a hassle.

$startitem = false;
$tag = "";
$title = "";
$description = "";
$link = "";
function startElement($parser, $name, $attrs) {
	global $startitem, $tag, $title, $description, $link;
	if ($startitem) {
		$tag = $name;
	} elseif ($name == "ITEM") {
		$startitem = true;
function endElement($parser, $name) {
	global $startitem, $tag, $title, $description, $link;
	if ($name == "ITEM") {
	printf("<dt><a href='%s'>%s</a></dt>",
		$title = "";
		$description = "";
		$link = "";
		$startitem = false;
function characterData($parser, $data) {
	global $startitem, $tag, $title, $description, $link;
	if ($startitem) {
	switch ($tag) {
		case "TITLE":
		$title .= $data;
		$description .= $data;
		case "LINK":
		$link .= $data;
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("YOUR RSS LINK HERE","r")
	or die("Error reading RSS data.");
while ($data = fread($fp, 4096))
	xml_parse($xml_parser, $data, feof($fp))
		or die(sprintf("XML error: %s at line %d",

P.S. The code is not entirely my own. I have referred Kevin Yank’s Tutorial . If you want to understand how the whole thing works, I suggest that you read through it.

© 2009, Nikhil Hullur | Entries RSS Comments RSS