Tips for common PHP Functions

Source: Internet
Author: User

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 ');
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.