jquery+php获取和设置Cookies代码

 更新时间:2016年11月25日 15:53  点击:2376

// 浏览页面次数

 代码如下 复制代码

$visited = (int)$_cookie['pagevisits'] + 1;

setcookie( 'pagevisits',    // cookie名
     $visited,     // cookie值
   time()+7*24*60*60   // 过期时间
          ); 

?>

<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>使用jquery+php获取和设置cookies</title>

<link rel="stylesheet" type="text/css教程" href="styles.css" />

<script type="text/网页特效" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery.cookie.js">

jquery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toutcstring)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new date();
                date.settime(date.gettime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toutcstring(); // use expires attribute, max-age is not supported by ie
        }

        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeuricomponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookievalue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jquery.trim(cookies[i]);
                // does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookievalue = decodeuricomponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookievalue;
    }
};
</script>
<script type="text/javascript">

$(document).ready(function(){
 
 var cookie = $.cookie('democookie');
 
 if(cookie) $('.jq-text').text(cookie).show();
 
        
 $('.fields a').click(function(e){
  var text = $('#inputbox').val();
  
  // 设置cookie的值
  $.cookie('democookie',text,{expires: 7});
  
  $('.jq-text').text(text).slidedown('slow');
  
  e.preventdefault();
 });
 
 $('#form1').submit(function(e){ e.preventdefault(); })
})

</script>

</head>

<body>
<h1>使用jquery+php获取和设置cookies</h1>

<div class="section">
 <div class="counter"><?php echo $visited?></div>
    <p>你访问此页面的次数</p>
</div>


<div class="section">
 
    <div class="jq-text"></div>

 <form action="" method="get" id="form1">
     <div class="fields">
         <input type="text" id="inputbox" />
            <a href="">保存</a>
        </div>
    </form>
    <p>你可以在输入框输入任意值,当你重新打开页面时,值依旧存在。</p>
</div>

</body>
</html>


源码下载
http://down.111cn.net/down/code/jquery/2010/0909/20704.html

验证由26个英文字母组成的字符串:^[a-za-z]+$
验证由26个大写英文字母组成的字符串:^[a-z]+$
验证由26个小写英文字母组成的字符串:^[a-z]+$
验证由数字和26个英文字母组成的字符串:^[a-za-z0-9]+$
验证由数字、26个英文字母或者下划线组成的字符串:^w+$
验证用户密码:^[a-za-z]w{5,17}$ 正确格式为:以字母开头,长度在6-18之间,只能包含字符、数字和下划线。
验证是否含有 ^%&',;=?$" 等字符:[^%&',;=?$"]+
验证汉字:^[u4e00-u9fa5],{0,}$
验证email地址:^w+[-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$
验证interneturl:^http://([w-]+.)+[w-]+(/[w-./?%&=]*)?$ ;^[a-za-z]+://(w+(-w+)*)(.(w+(-w+)*))*(?s*)?$
验证电话号码:^((d{3,4})|d{3,4}-)?d{7,8}$:--正确格式为:xxxx-xxxxxxx,xxxx-xxxxxxxx,xxx-xxxxxxx,xxx-xxxxxxxx,xxxxxxx,xxxxxxxx。
验证身份证号(15位或18位数字):^d{15}|d{}18$
验证一年的12个月:^(0?[1-9]|1[0-2])$ 正确格式为:"01"-"09"和"1""12"
验证一个月的31天:^((0?[1-9])|((1|2)[0-9])|30|31)$    正确格式为:01、09和1、31。

 我碰到的问题是发布内容没有问题,但是编辑文档,修改软件是就出现空白页面,经过查找,只要如下修改就ok了。
 找到dede/(就是你的后台登录目录,如果没修改默认是dede目录),找到文件archives_do.php教程文件,搜索header,在33行可以看到

 代码如下 复制代码
 header("location:{$gurl}?aid=$aid");


 我们把这里修改成js调用如

 代码如下 复制代码
 echo "<script language='网页特效'>window.location.href='{$gurl}?aid={$aid}'</script> ";


 
 至于什么原因不用能header函数呢,下面我们来看看关于header的属性。header()前,如果前面输出了空格、空行、任何字符,都会导致header()跳转失效....
由于catalog_do.php调用过的php文件太多了,可能你以前用启事本修改过文件,所以就出问题了。

 本站原创文章转载注明来源于http://www.111cn.net/phper/php.html

function whois_hichina($domain) {
preg_match("|<pre>(.+?)</pre>|is", @file_get_contents('http://whois.hichina.com/cgi-bin/whois?domain='.$domain.''), $whois);

$whois[0] = str_replace('友情提示:按注册局要求,过期域名可能会处于注册商自动续费期阶段,您在此查询所看到的域名到期日仅供参考<br />请您<a href="http://www.net.cn/has_client/userlogon/user_logon1.asp教程" target="_blank" class="link_gl">进入会员区</a>查看该域名的实际到期时间,并请及时进行续费,谢谢!', '', ($whois[0]));//过滤掉此段文字


return $whois[0]);

}

//新网 whois (非新网提供,只是根据新网自身网站的url修改实现)
function whois_xinnet($domain) {
preg_match("|<div class="lytableinfowrap">(.+?)</div>|is", @file_get_contents('http://www.xinnet.cn/modules/agent/serv/pages/domain_whois.jsp教程?domainnamewhois='.$domain.'&nocode=nocode'), $whois);

return $whois[0];
}
}

 代码如下 复制代码
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>创建、复制、移动、删除文件</title>
<style type="text/css教程">
<!--
body {
margin-left: 00px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style></head>
<body>
<table width="350" border="1" cellpadding="0" cellspacing="0">
<tr>
<td><table width="350" height="80" border="0" cellpadding="0" cellspacing="0" background="images/326ssss.gif">
<form name="form1" method="post" action="index.php教程">
<tr>
<td width="95" height="39"> </td>
<td width="171" rowspan="2" align="left" valign="middle"> <input name="fopens" type="text" id="copy2" size="22"></td>
<td width="84" rowspan="2" valign="middle"><input name="submit4" type="submit" id="submit4" value="提交"></td>
</tr>
<tr>
<td height="41"> </td>
</tr>
</form>
</table></td>
</tr>
<tr>
<td><table width="350" height="80" border="0" cellpadding="0" cellspacing="0" background="images/326s.gif">
<form name="form1" method="post" action="index.php">
<tr>
<td width="111" height="39"> </td>
<td width="155" valign="bottom"><input name="copys" type="text" id="copys2" size="20">
</td>
<td width="84" rowspan="2" valign="middle"><input type="submit" name="submit" value="提交"></td>
</tr>
<tr>
<td height="41"> </td>
<td valign="top"><input name="copy2" type="text" id="copy22" size="20"></td>
</tr>
</form>
</table></td>
</tr>
<tr>
<td><table width="350" height="80" border="0" cellpadding="0" cellspacing="0" background="images/326ss.gif">
<form name="form1" method="post" action="index.php">
<tr>
<td width="111" height="39"> </td>
<td width="115" valign="bottom"><input name="moves" type="text" id="moves3" size="20">
</td>
<td width="84" rowspan="2"><input type="submit" name="submit2" value="提交"></td>
</tr>
<tr>
<td height="41"> </td>
<td valign="top"><input name="moves2" type="text" id="moves22" size="20"></td>
</tr>
</form>
</table></td>
</tr>
<tr>
<td><table width="350" height="80" border="0" cellpadding="0" cellspacing="0" background="images/326sss.gif">
<form name="form1" method="post" action="index.php">
<tr>
<td width="104"> </td>
<td width="236"><input name="delete" type="text" id="delete2">
<input type="submit" name="submit3" value="提交"></td>
</tr>
</form>
</table></td>
</tr>
</table>
</body>
</html>

php代码

 代码如下 复制代码

<?php session_start();
if($submit=="提交"){
$copy=$_post[copys];
$copys2=$_post[copy2];
if(copy($copy,$copys2)==true){echo "复制成功!!";}else{echo "失败!!";};
}
if($submit2=="提交"){
$moves=$_post[moves];
$moves2=$_post[moves2];
if(rename($moves,$moves2)==true){echo "移动成功!!";}else{echo "失败!!";};
}

if($submit3=="提交"){
$delete=$_post[delete];
if(unlink($delete)==true){echo "删除成功!!";}else{echo "失败!!";};
}
if($submit4=="提交"){
$fopens=$_post[fopens];
if(fopen($fopens,"w")==true){echo "创建成功!!";}else{echo "失败!!";};
}

?>

[!--infotagslink--]

相关文章

  • jquery实现加载更多"转圈圈"效果(示例代码)

    这篇文章主要介绍了jquery实现加载更多"转圈圈"效果,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-11-10
  • PHP成员变量获取对比(类成员变量)

    下面本文章来给大家介绍在php中成员变量的一些对比了,文章举了四个例子在这例子中分别对不同成员变量进行测试与获取操作,下面一起来看看。 有如下4个代码示例,你认...2016-11-25
  • php 获取用户IP与IE信息程序

    php 获取用户IP与IE信息程序 function onlineip() { global $_SERVER; if(getenv('HTTP_CLIENT_IP')) { $onlineip = getenv('HTTP_CLIENT_IP');...2016-11-25
  • 自己动手写的jquery分页控件(非常简单实用)

    最近接了一个项目,其中有需求要用到jquery分页控件,上网也找到了需要分页控件,各种写法各种用法,都是很复杂,最终决定自己动手写一个jquery分页控件,全当是练练手了。写的不好,还请见谅,本分页控件在chrome测试过,其他的兼容性...2015-10-30
  • php获取一个文件夹的mtime的程序

    php获取一个文件夹的mtime的程序了,这个就是时间问题了,对于这个问题我们来看小编整理的几个例子,具体的操作例子如下所示。 php很容易获取到一个文件夹的mtime,可以...2016-11-25
  • jQuery+jRange实现滑动选取数值范围特效

    有时我们在页面上需要选择数值范围,如购物时选取价格区间,购买主机时自主选取CPU,内存大小配置等,使用直观的滑块条直接选取想要的数值大小即可,无需手动输入数值,操作简单又方便。HTML首先载入jQuery库文件以及jRange相关...2015-03-15
  • 如何获取网站icon有哪些可行的方法

    获取网站icon,常用最简单的方法就是通过website/favicon.ico来获取,不过由于很多网站都是在页面里面设置favicon,所以此方法很多情况都不可用。 更好的办法是通过google提供的服务来实现:http://www.google.com/s2/favi...2014-06-07
  • jQuery实现非常实用漂亮的select下拉菜单选择效果

    本文实例讲述了jQuery实现非常实用漂亮的select下拉菜单选择效果。分享给大家供大家参考,具体如下:先来看如下运行效果截图:在线演示地址如下:http://demo.jb51.net/js/2015/js-select-chose-style-menu-codes/具体代码如...2015-11-08
  • jquery实现的伪分页效果代码

    本文实例讲述了jquery实现的伪分页效果代码。分享给大家供大家参考,具体如下:这里介绍的jquery伪分页效果,在火狐下表现完美,IE全系列下有些问题,引入了jQuery1.7.2插件,代码里有丰富的注释,相信对学习jQuery有不小的帮助,期...2015-10-30
  • jQuery页面加载初始化常用的三种方法

    当页面打开时我们需要执行一些操作,这个时候如果我们选择使用jquery的话,需要重写他的3中方法,自我感觉没什么区 别,看个人喜好了,第二种感觉比较简单明了: 第一种: 复制代码 代码如下: <script type="text/javas...2014-06-07
  • jQuery 2.0.3 源码分析之core(一)整体架构

    拜读一个开源框架,最想学到的就是设计的思想和实现的技巧。废话不多说,jquery这么多年了分析都写烂了,老早以前就拜读过,不过这几年都是做移动端,一直御用zepto, 最近抽出点时间把jquery又给扫一遍我也不会照本宣科的翻译...2014-05-31
  • Jquery Ajax Error 调试错误的技巧

    JQuery使我们在开发Ajax应用程序的时候提高了效率,减少了许多兼容性问题,我们在Ajax项目中,遇到ajax异步获取数据出错怎么办,我们可以通过捕捉error事件来获取出错的信息。在没给大家介绍正文之前先给分享Jquery中AJAX参...2015-11-24
  • jquery如何获取元素的滚动条高度等实现代码

    主要功能:获取浏览器显示区域(可视区域)的高度 : $(window).height(); 获取浏览器显示区域(可视区域)的宽度 :$(window).width(); 获取页面的文档高度 $(document).height(); 获取页面的文档宽度 :$(document).width();...2015-10-21
  • jQuery实现切换页面过渡动画效果

    直接为大家介绍制作过程,希望大家可以喜欢。HTML结构该页面切换特效的HTML结构使用一个<main>元素来作为页面的包裹元素,div.cd-cover-layer用于制作页面切换时的遮罩层,div.cd-loading-bar是进行ajax加载时的loading进...2015-10-30
  • jquery获取div距离窗口和父级dv的距离示例

    jquery中jquery.offset().top / left用于获取div距离窗口的距离,jquery.position().top / left 用于获取距离父级div的距离(必须是绝对定位的div)。 (1)先介绍jquery.offset().top / left css: 复制代码 代码如下: *{ mar...2013-10-13
  • jQuery实现鼠标滑过链接控制图片的滑动展开与隐藏效果

    本文实例讲述了jQuery实现鼠标滑过链接控制图片的滑动展开与隐藏效果。分享给大家供大家参考,具体如下:这里演示jQuery实现鼠标移动到链接上,滑动展开/隐藏图片效果,鼠标放在“上一页”“下一页”上,立即浮现出所对应的图...2015-10-30
  • jQuery+PHP发布的内容进行无刷新分页(Fckeditor)

    这篇文章将使用jQuery,并结合PHP,将Fckeditor发布的内容进行分页,并且实现无刷新切换页面。 本文假设你是WEB开发人员,掌握了jQuery和PHP相关知识,并且熟知Fckeditor的配置和使用。...2015-10-23
  • jQuery Mobile开发中日期插件Mobiscroll使用说明

    这篇文章主要介绍了jQuery Mobile开发中日期插件Mobiscroll使用说明,需要的朋友可以参考下...2016-03-03
  • jQuery实现带玻璃流光质感的手风琴特效

    jQuery实现带玻璃流光质感的手风琴特效是一款基于jQuery+CSS3实现的带玻璃流光质感的手风琴特效,分享给大家,具体如下效果图:具体代码如下:html代码: <section class="strips"> <article class="strips__strip"> <di...2015-11-24
  • Jquery 获取指定标签的对象及属性的设置与移除

    1、先讲讲JQuery的概念,JQuery首先是由一个 America 的叫什么 John Resig的人创建的,后来又很多的JS高手也加入了这个团队。其实 JQuery是一个JavaScript的类库,这个类库集合了很多功能方法,利用类库你可以用简单的一些代...2014-05-31