43
网 网 网 网 网 网 网 Website design and d evelopments

网 站 设 计 与 建 设 Website design and developments

Embed Size (px)

DESCRIPTION

网 站 设 计 与 建 设 Website design and developments. 第三部分 网站设计技术. 第 14 章 Metadata, Cookies 与 Web 设计. 概 述. Metadata Cookies. 14.1 Metadata. Metadata: 元数据 描述数据的数据 描述网页的内容,由页面内容可用的但不必为用户显示的概要信息组成。 失效日期 作者名字 搜索引擎关键字 搜索引擎网页大纲的描述信息. 1. 标记. … .. …… . - PowerPoint PPT Presentation

Citation preview

Page 1: 网 站 设 计 与 建 设 Website design and developments

网 站 设 计 与 建 设Website design and developments

Page 2: 网 站 设 计 与 建 设 Website design and developments

第 14 章 Metadata, Cookies 与Web 设计

第三部分 网站设计技术

Page 3: 网 站 设 计 与 建 设 Website design and developments

MetadataCookies

概 述

Page 4: 网 站 设 计 与 建 设 Website design and developments

14.1 Metadata Metadata: 元数据

描述数据的数据 描述网页的内容,由页面内容可用的但不必为用户显示的概要信息组成。 失效日期 作者名字 搜索引擎关键字 搜索引擎网页大纲的描述信息

Page 5: 网 站 设 计 与 建 设 Website design and developments

1.<Meta> 标记 <head> ….. </head> <body> …… </body>

<meta ... ><meta ... >

Page 6: 网 站 设 计 与 建 设 Website design and developments

META 属性 Name http-equiv content

:创建或者改变文档的概要信息 <META NAME=“nameValue” CONTENT=“contentValue”> <META HTTP-EQUIP=“nameValue” CONTENT=“contentValue”>

Page 7: 网 站 设 计 与 建 设 Website design and developments

2.http-equiv 属性 加入到 http 头中

Page 8: 网 站 设 计 与 建 设 Website design and developments

2.http-equiv 属性 加入到 http 头中

Please refrePlease refreash on 11/2ash on 11/20/2002 at 8:0/2002 at 8:21:5721:57

……..

HTTPHTTP 头头

Page 9: 网 站 设 计 与 建 设 Website design and developments

HTTP 头 (header) 是服务器以 HTTP 传 HTML 资料到浏览器前所送出的字串,在标头 与 HTML 文件之间尚需空一行分隔。

传统的标头一定包含下面三种标头之一,并只能出现一次。    Content-Type: xxxx/yyyy    Location: xxxx:yyyy/zzzz    Status: nnn xxxxxx

Page 10: 网 站 设 计 与 建 设 Website design and developments
Page 11: 网 站 设 计 与 建 设 Website design and developments

字符集选择 content-type

<meta http-equiv=“content-type” content=“text/html; GB2312”>

在指定时间后 , 页面跳转 refresh

<meta http-equiv=“refresh” content=“20; URL=www.sina.com.cn”>

控制浏览器的页 cache pragma

<meta http-equiv=“pragma” content=“no-cache”>

网页有效期 expires

<meta http-equiv=“expires” content=“Fri, 8,Aug,2008 08:23:41 GMT”>

Page 12: 网 站 设 计 与 建 设 Website design and developments

PHP 设置 <meta> 内容 Header() 函数<?php

header("refresh:3;url=http://axgle.za.net");

print(' 正在加载,请稍等 ...<br> 三秒后自动跳转 ~~~');

?>

Page 13: 网 站 设 计 与 建 设 Website design and developments

3.NAME 属性:用于不响应 HTTP 头的信息类型,信息值不被加入到 HTTP 头中,但仍然保留在 HTML 文档中。

Page 14: 网 站 设 计 与 建 设 Website design and developments

网页作者 author<meta name=“author" content=“lyunc"> 关键字 keywords<meta name=“keywords” content=“xml,car">

META 标记符允许大多数搜索引擎并不是所有搜索引擎通过该标记符找到该网站 -keywords 关键词。

一个关键字 <=1000 字符,忽略 255 字符后的内容

选择和网站相关的关键字使用关键字的单数、复数以及其他变体不要使用冠词、介词和连结词等

Page 15: 网 站 设 计 与 建 设 Website design and developments

HTTP-EQUIP 、 CONTENT 属性值

Page 16: 网 站 设 计 与 建 设 Website design and developments

14.2 cookies

小文本文件 服务器在 HTTP 响应头中发送给用户浏览器 维持客户端与服务器端的状态 保存在客户端的一个目录中

C:\Documents and Settings\Administrator\CookiesC:\Documents and Settings\Administrator\Cookies

Page 17: 网 站 设 计 与 建 设 Website design and developments
Page 18: 网 站 设 计 与 建 设 Website design and developments
Page 19: 网 站 设 计 与 建 设 Website design and developments
Page 20: 网 站 设 计 与 建 设 Website design and developments
Page 21: 网 站 设 计 与 建 设 Website design and developments

可以用 setcookie() 函数来设置 cookie bool setcookie ( string name , string value , int expi

re , string path , string domain , bool secure , bool httponly)     name:     cookie 变量名 value:     cookie 变量的值 expire:   有效期结束的时间 ,     path:     有效目录 ,     domain: 有效域名 , 顶级域唯一 secure:   如果值为 1, 则 cookie 只能在 https 连接上有效 , 如果为默认值 0, 则 http 和 https 都可以 .

Page 22: 网 站 设 计 与 建 设 Website design and developments

<?php$value = 'something from somewhere';setcookie("TestCookie", $value); /* 简单 cookie设置 */setcookie("TestCookie", $value, time()+3600); /* 有效期1个小时 */setcookie("TestCookie", $value, time()+3600, "/~rasmus/", ".example.com", 1); /* 有效目录 /~rasmus,有效域名example.com及其所有子域名 */?>

Page 23: 网 站 设 计 与 建 设 Website design and developments

使用 header() 设置 cookie;header("Set-Cookie: name=$value;path=$path[;domain=xxx.com;...]]");后面的参数和上面列出 setcookie 函数的参数一样 .$value = 'something from somewhere';header("Set-Cookie:name=$value");

Page 24: 网 站 设 计 与 建 设 Website design and developments

Cookie 的读取 : 直接用 php 内置超级全局变量 $_COOKIE

就可以读取浏览器端的 cookie.上面例子中设置了 cookie"TestCookie", 现在我们来读取 :

print $_COOKIE['TestCookie'];

Page 25: 网 站 设 计 与 建 设 Website design and developments

删除 cookie只需把有效时间设为小于当前时间 , 和把值设置为空 .

setcookie("name","",time()-1);

用 header() 类似 .

Page 26: 网 站 设 计 与 建 设 Website design and developments

允许和禁止 Cookies(IE6)

Page 27: 网 站 设 计 与 建 设 Website design and developments

允许和禁止 Cookies( 续 )

Page 28: 网 站 设 计 与 建 设 Website design and developments

Session 机制

http 协议是一种无状态的连接 , 要想跟踪用户的行为就必须有一个能工作于不同于页面的变量,在 PHP 中可以用 cookie 和 session两种办法实现。

cookie 机制采用的是在客户端保持状态的方案,

session 机制采用的是在服务器端保持状态的方案。

Page 29: 网 站 设 计 与 建 设 Website design and developments

在 PHP 中, session 可以有两种办法实现,用 cookie ,即把 sessionID 保存在 cookie 文件中;把 sessionID附带在 URL 上进行传递

URL重写 ---- 把 session id 直接附加在 URL路径的后面。 <a href="submit.php<?=sessionID;?>">

提交表单 </a>

Page 30: 网 站 设 计 与 建 设 Website design and developments

表单隐藏字段 ----- 服务器会自动修改表单,添加一个隐藏字段,以便在表单提交时能够把 session id 传递回服务器。

<form name=“testform” action=“/xxx”>

<input type=“hidden”name=“jsessionid” value=“ByOK3vjFD75aPnrF7C2HmdnV6QZcEbzWoWiBYEnLerjQ99zWpBng!-145788764”>

<input type=“text”>

……

</form>

Page 31: 网 站 设 计 与 建 设 Website design and developments

Header() 重定向 标头 (header) 是服务器以 HTTP 传 HTML 资料到浏

览器前所送出的字串,在标头 与 HTML 文件之间尚需空一行分隔。

传统的标头一定包含下面三种标头之一,并只能出现一次。    Content-Type: xxxx/yyyy    Location: xxxx:yyyy/zzzz    Status: nnn xxxxxx

Page 32: 网 站 设 计 与 建 设 Website design and developments

使浏览器重定向到 PHP 的官方网站。     

Header("Location: http://www.php.net";);    exit;    >?

Page 33: 网 站 设 计 与 建 设 Website design and developments

<?php if(xxx) { Header("Location: http://www.php.net"); } else { Header("Location: http://www.php2.net"); } ?>

Page 34: 网 站 设 计 与 建 设 Website design and developments

<?php header("refresh:3;url=http://axgle.za.net"); print(' 正在加载,请稍等 ...<br> 三秒后自

动跳转 ~~~'); ?>

Page 35: 网 站 设 计 与 建 设 Website design and developments

要使用者每次都能得到最新的资料,而不是 Proxy 或 cache 中的资料,可以使用下列的标头

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") .

"GMT"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache");

Page 36: 网 站 设 计 与 建 设 Website design and developments

让使用者的浏览器出现找不到档案的信息。 header("Status: 404 Not Found");

让使用者下载档案。 header("Content-type: application/x-gzip"); header("Content-Disposition: attachment; filename= 文件名 \"); header("Content-Description: PHP3 Generated Data");    ?>

Page 37: 网 站 设 计 与 建 设 Website design and developments

删除 CookiesC:\Documents and Settings\C:\Documents and Settings\ Administrator\CookiesAdministrator\Cookieshttp://www.3721.comhttp://www.3721.com

Page 38: 网 站 设 计 与 建 设 Website design and developments

删除 Cookies( 续 )

Page 39: 网 站 设 计 与 建 设 Website design and developments

删除 Cookies( 续 )

Page 40: 网 站 设 计 与 建 设 Website design and developments

删除 Cookies( 续 )

Page 41: 网 站 设 计 与 建 设 Website design and developments

删除 Cookies( 续 )

Page 42: 网 站 设 计 与 建 设 Website design and developments

IE 工具栏中的 3721“清理”按钮

Page 43: 网 站 设 计 与 建 设 Website design and developments

IE 工具栏中的 3721“清理”按钮 ( 续 )