DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Yubnub "shortcut" Command Source

11.02.2005
| 3767 views |
  • submit to reddit
        
<?php

// CREATE TABLE `yubmail` (
// `id` int(11) NOT NULL auto_increment,
// `mail_alias` varchar(250) NOT NULL default '',
// `email` varchar(250) NOT NULL default '',
// `modifed1` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
// `paid` enum('Y','N') default 'N',
// PRIMARY KEY (`id`),
// UNIQUE KEY `mail_alias` (`mail_alias`)
// ) ENGINE=MyISAM


 $this = ' ';
   function after ($this, $alias)
   {
       if (!is_bool(strpos($alias, $this)))
       return substr($alias, strpos($alias,$this)+strlen($this));
   };

   function before ($this, $alias)
   {
       return substr($alias, 0, strpos($alias, $this));
   };
$mail_alias = before ($this, $alias);
$email = after ($this, $alias); 

if (!$link = mysql_connect('mysql', 'username', 'password')) {
   echo 'Could not connect to mysql';
   exit;
}

if (!mysql_select_db('yub', $link)) {
   echo 'Could not select database';
   exit;
}

$sql_query = mysql_query("INSERT INTO yubmail(mail_alias, email) VALUES ('$mail_alias', '$email')") ;

if (!$sql_query) {
   die('Try again with different shortcut');
}
echo "alias created called <b><i>$mail_alias</i></b> directing to <b>$email</b>";
?>