1. returns the file extension.
Function getformat ($ file)
{
$ Ext = strrchr ($ file ,".");
$ Format = strtolower ($ ext );
Return $ format;
}
2. format the variable
<?
$ Num = 1;
Printf ("% 04d", $ num );
?>
3. php redirection webpage
// For example, redirect to www.cgsir.com (note that html content is not included before redirection)
Header ("location: http://www.jb51.net ");
Or
Echo "<meta http-equiv = 'refresh' content = '0; url = http://www.jb51.net.com '> ";
4. restrict the size of uploaded files
// $ Limit_size indicates the maximum file size.
$ Limit_size = 50000;
$ File_size = $ HTTP_POST_FILES ['ufile'] ['SIZE'];
If ($ file_size> = $ limit_size ){
Echo "the size of your file exceeds the limit <BR> ";
Echo "your file size is =". $ file_size;
Echo "K ";
Echo "<BR> the file size is limited to = 50000 k ";
}
Else {
// The Directory to which the object is uploaded, that is, copying the object from the temporary directory to the target directory.
If (copy ($ HTTP_POST_FILES ['ufile'] ['tmp _ name'], $ path ))
{
Echo "uploaded <BR/> ";
Echo " ";
}
5. Common php Algorithm for string encryption:
5.1 $ db_password = md5 ($ random_password );
5.2 $ db_password = sh1 ($ random_password );
6. log out
// Log out
Session_start ();
Include_once ('des/header. php ');
If (isset ($ _ SESSION ['user _ id'])
{
Unset ($ _ SESSION ['user _ id']);
Session_destroy ();
Echo '<div align = "center"> ';
Echo '<span class = "STYLE1"> exited successfully! </Span> <br/> ';
Echo '<p> <span class = "STYLE1"> redirecting. Please wait... </span> </p> ';
Echo '<script language = "javascript"> ';
Echo 'function Jump ()';
Echo '{';
Echo 'parent. location. href = "index. php "';
Echo '}';
Echo 'document. onload = setTimeout ("Jump ()", 2*1000 )';
Echo '</script> ';
Echo '<span class = "STYLE1"> <a href = "index. php"> direct return </a> </span> <br/> ';
Echo '</div> ';
Exit (0 );
}
Else
{
Echo '<span class = "STYLE1"> you have not logged on! </Span> ';
}
Include_once ('includes/footer. php ');
?>