PHP 发送邮件
作者:w3pop.com 翻译/整理:w3pop.com 发布:2007-04-28 修改:2007-06-17 浏览:14208 :: ::
PHP Sessions
PHP allows you to send e-mails directly from a script.
PHP允许你通过脚本直接发送e-mail。
The PHP mail() Function
PHP mail()函数
The PHP mail() function is used to send emails from inside a script.
PHP mail()函数可以从脚本内发送email。
Syntax
语法
mail(to,subject,message,headers,parameters)
Parameter
参数Description
描述
to
Required. Specifies the receiver / receivers of the email
必要参数。指定email的接收者
subject
Required. Specifies the subject of the email. Note: This parameter cannot contain any newline characters
必要参数。指出email的主题。注意:这个参数包含的字符不能换行(只能显示一行)
message
Required. Defines the message to be sent. Each line should be separated with a LF (n). Lines should not exceed 70 characters
必要参数。定义发送的信息。每行都必须用(n)分隔开。每行不能超过70个字符
heade ......
//
dirname()
// Returns directory name component of path
basename()
// Returns filename component of path
pathinfo()
// Returns information about a file path;
// pathinfo() returns an associative array containing information about path .
parse_url()
// Parse a URL and return its components;
// This function parses a URL and returns an associative array
// containing any of the various components of the URL that are present.
realpath()
// Returns canonicalized absolute pathname;
// realpath() expands all symbolic links and resolves references to '/./', '/../' and
// extra '/' characters in the input path . and return the canonicalized absolute pathname.
http_build_query()
// Generate URL-encoded query string;
// Generates a URL-encoded query string
// from the associative (or indexed) array provided.
http_build_url()
// Build an URL
......
不是很赞同使用session 每一个php的页面在调用session的时候都必须先声明session。
例如:在php文件的最前面声明session;
<?php
session_start();//声明session
$_SESSION['id']=$_POST['id'];//赋值
?>
如果不这样声明的话,也免就无法获得已经定义好的session。 你可以用参数的形式进行传递啊 例如test.aspx?name=1&pass=2 即可 ......
对比起 Cookie,Session 是存储在服务器端的会话,相对安全,并且不像 Cookie 那样有存储长度限制,本文简单介绍 Session 的使用。
由于 Session 是以文本文件形式存储在服务器端的,所以不怕客户端修改 Session 内容。实际上在服务器端的 Session 文件,PHP 自动修改 Session 文件的权限,只保留了系统读和写权限,而且不能通过 ftp 修改,所以安全得多。
对于 Cookie 来说,假设我们要验证用户是否登陆,就必须在 Cookie 中保存用户名和密码(可能是 md5 加密后字符串),并在每次请求页面的时候进行验证。如果用户名和密码存储在数据库,每次都要执行一次数据库查询,给数据库造成多余的负担。因为我们并不能只做一次验证。为什么呢?因为客户端 Cookie 中的信息是有可能被修改的。假如你存储 $admin 变量来表示用户是否登陆,$admin 为 true 的时候表示登陆,为 false 的时候表示未登录,在第一次通过验证后将 $admin 等于 true 存储在 Cookie,下次就不用验证了,这样对么?错了,假如有人伪造一个值为 true 的 $admin 变量那不是就立即取的了管理权限么?非常的不安全。
而 Session 就不同了,Session 是存储在服务器端的,远程用户没办法修改 Session ......
index.php(实现输入验证码页面)代码如下: Code代码如下: <html>
<head>
<title>check code</title>
</head>
<body>
<form name=check method=post action=check.php>
<input type=hidden name=init value=1>
验证码:<input type=text name=code maxlength=4 style="width=50px;">
<!--得到验证码图片-->
<img src=image.php>
<p>
<input type=submit value="提交">
</form>
</body>
</html> image.php(验证码生成页面)代码如下: Code代码如下: <?php
session_start();
srand((double)microtime()*1000000);
$authnum=rand(1000,9999);
session_register("authnum");
header("content-type:image/png");
function creat_image( $width, $height, $authnum)
& ......
什么是SESSION? 按照WIKI的解释,SESSION是存在于两个通信设备间的交互信息,在某一时间建立,经过一定的时间后失效。常见的SESSION有:TCP SESSION、WEB SESSION(HTTP SESSION)、LOGIN SESSION等。 根据OSI模型中,会话实现的位置不同,SESSION主要分为几种,一种是应用层会话,包括WEB SESSION(HTTP SESSION)和telnet远程登录session;会话层实现的,包括Session Initiation Protocol(SIP)和Internet Phone Call;在传输层实现的有TCP SESSION。 本文主要讨论WEB SESSION,其一般有两种:客户端SESSION和服务器端SESSION,后一种最常见的属于Java Beans提供的。 SESSION是做什么的? 在计算机领域,特别是网络方面,SESSION使用的特别广泛,也可以称为是对话(Dialogue)、会话等,一般是指在两个通信设备间存储的状态,有时也发生在用户和计算机之间(Login SESSION)。 区别于无状态的通信,SESSION通常用来存储通信状态,因此通信的双方至少有一方需要存储SESSION的历史记录,从而实现两者间的通信。 SESSION(WEB SESSION)是怎么实现的? 浏览器和服务器之间进行HTTP通信时,通常会包含一个 HTTP Cookie 来标识状态,通常会有一个唯一的 SESSIONID ,SE ......