hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Programming Tutorials : Some Simple But Useful Snippets
Reply

Programming Tutorials How-Tos related to programming, databases, and the like.
Forum Jump

Some Simple But Useful Snippets

Reply Post New Thread In Programming Tutorials Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 07-27-2005, 03:36 PM
adaml adaml is offline
Web Hosting Guru
 
Join Date: Oct 2002
Location: York, United Kingdom
Posts: 260

Some Simple But Useful Snippets


This is just a small list of coding snippets, which can be used within HTML/PHP Documents.

There not the most exciting or magical snippets but there useful and can make a hell of a lot easier!

PHP Snippets

- Emails and Mail

Simple Mail
PHP Code:
mail($to$subject$message$headers); 
Validate Email Address
PHP Code:
function validate_email($str){
$str strtolower($str);
if(
ereg("^([^[:space:]]+)@(.+).(ad|ae|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|fi|fj|fk|fm|fo|fr|fx|ga|gb|gov|gd|ge|gf|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nato|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$",$str)){
return 
1;
} else {
return 
0;
}

- Date and Time

Simple Unix Timestamp Conversation
PHP Code:
$date_format date('G:i d-m-Y'$unix_time);

Will output :

21:28 27-07-2005 
Server Time
PHP Code:
$date_time date('l M d, Y @ g:i A');
echo (
$date_time); 
Localtime not Servertime
PHP Code:
$differencetolocaltime=+4;
$new_U=date("U")+$differencetolocaltime*3600;
$fulllocaldatetimedate("d-m-Y h:i:s A"$new_U); 
- Passwords and Encryption

128BIT MD5 Encryption
PHP Code:
function AuthenticMd5($username$password)
{
    
$one $username;$two $password;$thr $one $two;$fou $thr $one;$fiv $fou $one;
    
$six $thr $thr;$sev $one $two $thr $one;
    
$md1 md5$sev $two md5($one $fiv md5($sev strrev$sev))));
    
$md2 md5$md1 md5$one $thr $fou md5$sev $md1)));
    
$md3 md5$md2 md5($md1));
    
$md4 md5$md3 $md1 $md2 md5($sev));
    return 
$md2 $md1$md4 md5($md3 $md2);

32BIT MD5 Encryption
PHP Code:
$epass md5($password); 
HTPassword Generator
PHP Code:
function htpasswd($pass)

     
$pass crypt(trim($pass),base64_encode(CRYPT_STD_DES)); 
     return 
$pass


Base64 Encryption
PHP Code:
$epass base64_encode($password); 
Base64 Decryption
PHP Code:
$password base64_decode($epass); 


Let me know if anyone finds these useful and / or you want me to write some more out

As its a bit pointless me writing them out and spending time if know one will look at them

Reply With Quote


Sponsored Links
  #2  
Old 08-25-2005, 11:35 PM
mwalters mwalters is offline
Web Hosting Evangelist
 
Join Date: Jun 2003
Location: VA, USA
Posts: 504
Validation and encryption/decryption is *ALWAYS* helpful. Thanks for the snippets. I feel cheesy, I consider myself pretty decent at PHP, but I never quite 'get' all the ereg, etc validators, so I always appreciate it when someone else figures it out for me.

Reply With Quote
  #3  
Old 08-28-2005, 07:18 PM
adaml adaml is offline
Web Hosting Guru
 
Join Date: Oct 2002
Location: York, United Kingdom
Posts: 260
thanks! im glad someone finds them useful!

Reply With Quote
Sponsored Links
  #4  
Old 09-29-2005, 11:53 PM
michael.j.fox michael.j.fox is offline
New Member
 
Join Date: Sep 2005
Location: Oakland County, MI
Posts: 1
I've been looking for some sample code to validate email. I'll check this one out and see if I can figure it out. Thanks!

Reply With Quote
  #5  
Old 10-22-2005, 01:28 AM
CaseyG CaseyG is offline
Newbie
 
Join Date: Oct 2005
Posts: 6
Awesome, I was actually looking for something like this.

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
50dc5dbc-8dc0-461d-9a78-156b45a799de Listing 2013-03-05 18:24:38
50dc5dbc-7bf0-4b28-aaad-156e45a799de Listing 2013-03-05 18:26:46
Video Demo: Yola Website Building Software Whir Tv 2012-05-14 16:05:42
Namesco Provides Free Domains for Companies Made Simple Customers Web Hosting News 2012-01-31 13:36:44
Web Host Simple Hosting Partners with SpamExperts Web Hosting News 2011-09-09 17:02:09


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?