SESSION的作用很多,最多用的就是站点内页面间变量传递。在页面开始我们要session_start();开启SESSION; 然后就可以使用SESSION变量了,比如说要赋值就是:$_SESSION['item']="item1";要得到值就是$item1=$_SESSION['item'];,很简单吧。这里我们可能会使用到一些函数,比如说判断是不是某SESSION变量为空,可以这么写:empty($_SESSION['inum'])返回true or false。
好了,今天说到这里,明天说一下如果用PHP上传文件和发邮件。
Day 10
Learning purpose: Learn to use PHP to upload files and send emails
The file upload form must add enctype="multipart/form-data" and Look at the code below:
$f=&$HTTP_POST_FILES['file']; $dest_dir='uploads';//Set the upload directory $dest=$ dest_dir.'/'.date("ymd")."_".$f['name'];//I set the file name here plus the date plus the file name to avoid duplication $r=move_uploaded_file($f ['tmp_name'],$dest); chmod($dest, 0755);//Set the attributes of the uploaded file
The name of the uploaded file is date("ymd")."_ ".$f['name'] can be used when inserting into the database later. PHP actually moves the file you uploaded from the temporary directory to the specified directory. move_uploaded_file($f['tmp_name'],$dest); This is the key
As for sending emails, it is even simpler. You can use the mail() function
However, mail() requires server support, and SMTP server needs to be configured under WINDOWS , Generally speaking, any external LINUX space will work. It seems that uploading files and sending emails is much simpler than ASP. You only need to call functions. ASP also needs to use different components of the server such as FSO, JMAIL and so on.
That’s it for learning PHP in ten days. My three major series of articles all use “Learning in Ten Days” as their names. What I want to tell you is that getting started with ASP, PHP, and ASP.NET can all take ten days. But mastery is by no means ten days, and everyone still needs to study it by themselves. Learning purpose: Learn to use PHP to upload files and send emails
The upload file form must add enctype="multipart/form-data" and Look at the code below:
$f=&$HTTP_POST_FILES['file']; $dest_dir='uploads';//Set the upload directory $ dest=$dest_dir.'/'.date("ymd")."_".$f['name'];//I set the file name here with the date plus the file name to avoid duplication $r=move_uploaded_file ($f['tmp_name'],$dest); chmod($dest, 0755);//Set the attributes of the uploaded file
The name of the uploaded file is date("ymd") ."_".$f['name'] can be used when inserting into the database later. PHP actually moves the file you uploaded from the temporary directory to the specified directory. move_uploaded_file($f['tmp_name'],$dest); This is the key
As for sending emails, it is even simpler. You can use the mail() function
However, mail() requires server support, and SMTP server needs to be configured under WINDOWS , Generally speaking, any external LINUX space will work. It seems that uploading files and sending emails is much simpler than ASP. You only need to call functions. ASP also needs to use different components of the server such as FSO, JMAIL and so on.
That’s it for learning PHP in ten days. My three major series of articles all use “Learning in Ten Days” as their names. What I want to tell you is that getting started with ASP, PHP, and ASP.NET can all take ten days. But mastery is by no means ten days, and everyone still needs to study it by themselves.
http://www.bkjia.com/PHPjc/314611.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314611.htmlTechArticleDay 7 Learning Objective: Learn how to use SESSION. SESSION has many functions. The most commonly used one is the variables between pages within the site. transfer. At the beginning of the page we need session_start(); to open SESSION; then...
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn