Home > Backend Development > PHP Tutorial > Tips on common functions in PHP_PHP tutorial

Tips on common functions in PHP_PHP tutorial

WBOY
Release: 2016-07-21 15:50:23
Original
799 people have browsed it

1. Return the file extension
function getformat($file)
{
$ext=strrchr($file,".");
$format=strtolower($ext);
return $format;
}

2. Format variable
$num = 1;
printf("%04d", $num);
?>

3.php redirect webpage
// For example, redirect to www.cgsir.com (note that there should be no html content before redirection)
header("location: http://www.jb51.net");
or
echo "";

4. Limit the uploaded file size
//$limit_size is the maximum file size limit
$limit_size=50000;
$file_size=$HTTP_POST_FILES['ufile'] ['size'];
if($file_size >= $limit_size) {
echo "Your file exceeds the limit size
";
echo "Your file size is = ".$file_size;
echo " K";
echo "
File size limit = 50000 k";
}
else {
// What directory to upload to, That is, copy from the temporary directory to the target directory
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "Upload successful
";
echo "";
}

5.php is commonly used to encrypt strings Algorithm:
5.1 $db_password = md5($random_password);
5.2 $db_password = sh1($random_password);

6. Log out
// Log out
session_start ();
include_once('includes/header.php');
if (isset($_SESSION['user_id']))
{
unset($_SESSION['user_id']) ;
session_destroy();

echo '

';
echo 'Exited successfully!
';
echo '

Redirecting, please wait...

';
echo '
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template