php 怎么跨域写cookie实现同步登陆代码

 更新时间:2016年11月25日 15:54  点击:2360

//加上

 代码如下 复制代码
header('p3p: cp="cura adma deva ps教程ao psdo our bus uni pur int dem sta pre com nav otc noi dsp cor"');

//方法二针对二级域名

 代码如下 复制代码
setcookie('loaddomain','http://'.$url,time()+3600*24,'/','.111cn.net');

//这样的话,所有111cn.net的二级域名都同时登陆了。

/*

 代码如下 复制代码
int preg_match_all ( string $pattern , string $subject , array &$matches [, int $flags [, int $offset ]] );

搜索所有匹配正则表达式的模式并提出给予他们在比赛中受的标志指定的顺序。第一场比赛后发现,随后的搜查是继续从最后一场比赛结束。

实例

 代码如下 复制代码
preg_match_all("|<[^>]+>(.*)</[^>]+>|u",
    "<b>example: </b><div align=left>this is a test</div>",
    $out, preg_pattern_order);
echo $out[0][0] . ", " . $out[0][1] . " ";
echo $out[1][0] . ", " . $out[1][1] . " ";

出输

 代码如下 复制代码

<b>example: </b>, <div align=left>this is a test</div>
example: , this is a test


preg_match_all("|<[^>]+>(.*)</[^>]+>|u",
    "<b>example: </b><div align="left">this is a test</div>",
    $out, preg_set_order);
echo $out[0][0] . ", " . $out[0][1] . " ";
echo $out[1][0] . ", " . $out[1][1] . " ";

 

int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags [, int $offset ]]] )
搜索主题的经常表达的方式给予配合


$subject = "abcdefwww.111cn.net";
$pattern = '/^def/';
preg_match($pattern, substr($subject,3), $matches, preg_offset_capture);
print_r($matches);


array
(
    [0] => array
        (
            [0] => def
            [1] => 0
        )

)


*/

date_default_timezone_set('prc');
/**
* 求取从某日起经过一定天数后的日期,
* 排除周六周日和节假日
* @param $start       开始日期
* @param $offset      经过天数
* @param $exception 例外的节假日
* @param $allow       允许的日期(预留参数)
* @return
*  examples:输入(2010-06-25,5,''),得到2010-07-02
*/
function getendday( $start='now', $offset=0, $exception='', $allow='' ){
    //先计算不排除周六周日及节假日的结果
    $starttime = strtotime($start);
    $endtime = $starttime + $offset * 24 * 3600;
    $end = date('y-m-d', $endtime);
    //然后计算周六周日引起的偏移
    $weekday = date('n', $starttime);//得到星期值:1-7
    $remain = $offset % 7;
    $newoffset = 2 * ($offset - $remain) / 7;//每一周需重新计算两天
    if( $remain > 0 ){//周余凑整
        $tmp = $weekday + $remain;
        if( $tmp >= 7 ){
            $newoffset += 2;
        }else if( $tmp == 6 ){
            $newoffset += 1;
        }
        //考虑当前为周六周日的情况
        if( $weekday == 6 ){
            $newoffset -= 1;
        }else if( $weekday == 7 ){
            $newoffset -= 2;
        }
    }
    //再计算节假日引起的偏移
    if( is_array($exception) ){//多个节假日
        foreach ($exception as $day){
            $tmp_time = strtotime($day);
            if( $tmp_time>$starttime && $tmp_time<=$endtime ){//在范围(a,b]内
                $weekday_t = date('n', $tmp_time);
                if($weekday_t <= 5){//防止节假日与周末重复
                    $newoffset += 1;
                }
            }
        }
    }else{//单个节假日
        if( $exception!='' ){
            $tmp_time = strtotime($exception);
            if( $tmp_time>$starttime && $tmp_time<=$endtime ){
                $weekday_t = date('n', $tmp_time);
                if($weekday_t <= 5){
                    $newoffset += 1;
                }
            }
        }
       
    }
    //根据偏移天数,递归做等价运算111cn.net
    if($newoffset > 0){
        #echo "[{$start} -> {$offset}] = [{$end} -> {$newoffset}]"."<br /> ";
        return getendday($end,$newoffset,$exception,$allow);
    }else{
        return $end;
    }
}
/**
* 暴力循环方法
*/
function getendday2( $start='now', $offset=0, $exception='', $allow='' ){
    $starttime = strtotime($start);
    $tmptime = $starttime + 24*3600;
   
    while( $offset > 0 ){
        $weekday = date('n', $tmptime);
        $tmpday = date('y-m-d', $tmptime);
        $bfd = false;//是否节假日
        if(is_array($exception)){
            $bfd = in_array($tmpday,$exception);
        }else{
            $bfd = ($exception==$tmpday);
        }
        if( $weekday<=5 && !$bfd){//不是周末和节假日
            $offset--;
            #echo "tmpday={$tmpday}"."<br />";
        }
        $tmptime += 24*3600;
    }
   
    return $tmpday;
}
$exception = array(
    '2010-01-01','2010-01-02','2010-01-03',
    '2010-04-03','2010-04-04','2010-04-05',
    '2010-05-01','2010-05-02','2010-05-03',
    '2010-06-14','2010-06-15','2010-06-16',
    '2010-09-22','2010-09-23','2010-09-24',
    '2010-10-01','2010-10-02','2010-10-03','2010-10-04',
    '2010-10-05','2010-10-06','2010-10-07',
   
);
//echo getendday('2010-08-27',3,'');
//echo getendday('2010-06-25',15,'2010-07-07');
$t1 = microtime();
echo getendday('2010-05-12',66,$exception)."<br />";
$t2 = microtime();echo "use ".($t2-$t1)." s <br />";
echo getendday2('2010-05-12',66,$exception)."<br />";
$t3 = microtime();echo "use ".($t3-$t2)." s <br />";

本程序是根据用户上传图片后再把上传的图片按比例生成缩略图
 代码如下 复制代码

<?
$w?$resizewidth=$w:$resizewidth=400;// 生成图片的宽度
$h?$resizeheight=$h:$resizeheight=400;// 生成图片的高度
function resizeimage($im,$maxwidth,$maxheight,$name){
    $width = imagesx($im);
    $height = imagesy($im);
    if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){
        if($maxwidth && $width > $maxwidth){
            $widthratio = $maxwidth/$width;
            $resizewidth=true;
        }
        if($maxheight && $height > $maxheight){
            $heightratio = $maxheight/$height;
            $resizeheight=true;
        }
        if($resizewidth && $resizeheight){
            if($widthratio < $heightratio){
                $ratio = $widthratio;
            }else{
                $ratio = $heightratio;
            }
        }elseif($resizewidth){
            $ratio = $widthratio;
        }elseif($resizeheight){
            $ratio = $heightratio;
        }
        $newwidth = $width * $ratio;
        $newheight = $height * $ratio;
        if(function_exists("imagecopyresampled")){
              $newim = imagecreatetruecolor($newwidth, $newheight);
              imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
        }else{
            $newim = imagecreate($newwidth, $newheight);
              imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
        }
        imagejpeg ($newim,$name);
        imagedestroy ($newim);
    }else{
        imagejpeg ($im,$name);
    }
}

if($_files['uploadfile']['size']){
    if($_files['uploadfile']['type'] == "image/pjpeg"){
        $im = imagecreatefromjpeg($_files['uploadfile']['tmp_name']);
    }elseif($_files['uploadfile']['type'] == "image/x-png"){
        $im = imagecreatefrompng($_files['uploadfile']['tmp_name']);
    }elseif($_files['uploadfile']['type'] == "image/gif"){
        $im = imagecreatefromgif($_files['uploadfile']['tmp_name']);
    }
    if($im){
        if(file_exists('bbs.jpg')){
            unlink('bbs.jpg');
        }
        resizeimage($im,$resizewidth,$resizeheight,'bbs.jpg');
        imagedestroy ($im);
  
    }
}
//$uploadfile="www.111cn.net.jpg";
?>

<?php教程
if($_files['file']){
 // ----------------------------------------------------------------------------------------------//
//
// 说明:文件上传   日期:2004-5-2
//
// ----------------------------------------------------------------------------------------------//

php简单实用文件上传代码
 // 上传设置
 $maxsize=10002400;            //最大允许上传的文件大小
 $alltype=array(".php",".php3");         //所有允许上传的文件类型
 $imgtype=array(".php",".php3");               //类型

 // 判断文件大小
 if($_files['file']['size']>$maxsize)  {
     echo "您上传的资料大于10000k";
     exit;
 }
 
 // 判断文件类型
 $type=strstr($_files['file']['name'],".");
 if(in_array($type,$alltype)){
     echo "不允许上传该类型的文件";
     exit;
 }
 include './uploaddir.php';
 $time=date("ymd-his",time());
 $fn=$time.$type;
 $destination=$updir."/".$fn;
 if(@move_uploaded_file($_files['file']['tmp_name'], $destination)){
         @chmod($destination, 0777);
   $fileurl=$updir."/".$destination;
         $fileurl="".$destination;
          
 }else{
    echo "上传失败!";
    echo "<script>location.href=history.back()</script>";
 }
// ----------------------------------------------------------------------------------------------//
}
if($back=="no"):
 echo "ok";
 exit;
endif;
?>

[!--infotagslink--]

相关文章

  • phpems SQL注入(cookies)分析研究

    PHPEMS(PHP Exam Management System)在线模拟考试系统基于PHP+Mysql开发,主要用于搭建模拟考试平台,支持多种题型和展现方式,是国内首款支持题冒题和自动评分与教师评分相...2016-11-25
  • JS使用cookie实现DIV提示框只显示一次的方法

    本文实例讲述了JS使用cookie实现DIV提示框只显示一次的方法。分享给大家供大家参考,具体如下:这里运用JavaScript的cookie技术,控制网页上的提示DIV只显示一次,也就是当用户是第一次打开网页的时候才显示,第二次自动隐藏起...2015-11-08
  • PHP中SSO Cookie登录分析和实现

    什么是SSO?单点登录SSO(Single Sign-On)是身份管理中的一部分。SSO的一种较为通俗的定义是:SSO是指访问同一服务器不同应用中的受保护资源的同一用户,只需要登录一次,即通过一个应用中的安全验证后,再访问其他应用中的受保护...2015-11-08
  • js实现跨域的4种实用方法原理分析

    什么是js跨域呐?js跨域是指通过js在不同的域之间进行数据传输或通信,比如用ajax向一个不同的域请求数据,或者通过js获取页面中不同域的框架中(iframe)的数据。只要协议、域名、端口有任何一个不同,都被当作是不同的域。要...2015-10-30
  • 浅析c# 线程同步

    这篇文章主要介绍了c# 线程同步的相关资料,帮助大家更好的理解和学习c#,感兴趣的朋友可以了解下...2020-08-29
  • PHP中SSO Cookie登录分析和实现

    什么是SSO?单点登录SSO(Single Sign-On)是身份管理中的一部分。SSO的一种较为通俗的定义是:SSO是指访问同一服务器不同应用中的受保护资源的同一用户,只需要登录一次,即通过一个应用中的安全验证后,再访问其他应用中的受保护...2015-11-08
  • MYSQL主从不同步延迟原理分析及解决方案

    1. MySQL数据库主从同步延迟原理。要说延时原理,得从mysql的数据库主从复制原理说起,mysql的主从复制都是单线程的操作,主库对所有DDL和DML产生binlog,binlog是顺序写,所以效率很高,slave的Slave_IO_Running线程到主库取日...2013-10-04
  • js实现跨域的4种实用方法原理分析

    什么是js跨域呐?js跨域是指通过js在不同的域之间进行数据传输或通信,比如用ajax向一个不同的域请求数据,或者通过js获取页面中不同域的框架中(iframe)的数据。只要协议、域名、端口有任何一个不同,都被当作是不同的域。要...2015-10-30
  • vue项目中js-cookie的使用存储token操作

    这篇文章主要介绍了vue项目中js-cookie的使用存储token操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-14
  • 什么是cookie?js手动创建和存储cookie

    什么是cookie? cookie 是存储于访问者的计算机中的变量。每当同一台计算机通过浏览器请求某个页面时,就会发送这个 cookie。你可以使用 JavaScript 来创建和取回 cookie 的值。 有关cookie的例子: 名字 cookie 当访...2014-05-31
  • jQuery Jsonp跨域模拟搜索引擎

    这篇文章主要介绍了jQuery Jsonp跨域模拟搜索引擎的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下...2017-06-24
  • 原生JS封装Ajax插件(同域、jsonp跨域)

    这篇文章主要为大家详细介绍了原生JS封装Ajax插件,为大家介绍不同域之间互相请求资源的跨域...2016-05-05
  • C#同步网络时间的方法实例详解

    这篇文章主要介绍了C#同步网络时间的方法,以实例形式较为详细的分析了C#获取网络时间与同步本机系统时间的相关技巧,非常具有实用价值,需要的朋友可以参考下...2020-06-25
  • 检测mysql同步状态实现代码(php/linux)

    本文章介绍两个实例来介绍mysql同步状态检测实现程序有需要的朋友可参考一下。 代码如下 复制代码 #!/bin/sh #check MySQL_Slave St...2016-11-25
  • python爬虫用request库处理cookie的实例讲解

    在本篇内容里小编给大家整理的是一篇关于python爬虫用request库处理cookie的实例讲解内容,有需要的朋友们可以学习参考下。...2021-02-21
  • 基于C#后台调用跨域MVC服务及带Cookie验证的实现

    本篇文章介绍了,基于C#后台调用跨域MVC服务及带Cookie验证的实现。需要的朋友参考下...2020-06-25
  • VSCode 云同步扩展设置Settings Sync插件

    这篇文章主要介绍了VSCode 云同步扩展设置Settings Sync插件,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-06-29
  • MySQL 5.5主从同步设置笔记分享

    先修改Master(10.1.123.197)的 my.cnf 配置在 [mysqld] 中新增以下内容:复制代码 代码如下:log-bin=mysql-binlog-bin-index=mysql-bin.indexserver-id = 1sync_binlog=1binlog_format=mixed然后指定要做同步的数据库,并...2014-05-31
  • C#多线程及同步示例简析

    这篇文章主要为大家详细介绍了C#多线程及同步示例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-06-25
  • JS跨域解决方案之使用CORS实现跨域

    正常使用AJAX会需要正常考虑跨域问题,所以伟大的程序员们又折腾出了一系列跨域问题的解决方案,如JSONP、flash、ifame、xhr2等等。本文给大家介绍JS跨域解决方案之使用CORS实现跨域,感兴趣的朋友参考下吧...2016-04-17