这篇文章主要介绍了Ajax 设置Access-Control-Allow-Origin实现跨域访问,非常不错,具有参考借鉴价值,需要的朋友可以参考下ajax跨域访问是一个老问题了,解决方法很多,比较常用的是JSONP方法,JSONP方法是一种非官方方法,而且这种方法只支持GET方式,不如POST方式安全。即使使用jQuery的jsonp方法,type设为POST,也会自动变为GET。官方问题说明:“script”: Evaluates the response as JavaScript and returns it as plain text. Disables caching by ...
php里允许别的域名跨域访问,先解释下跨域跨域,指的是浏览器不能执行其他网站的脚本。它是由浏览器的同源策略造成的,是浏览器对javascript施加的安全限制。所谓同源是指,域名,协议,端口均相同http://www.123.com/index.html 调用 http://www.123.com/server.php (非跨域)http://www.123.com/index.html 调用 http://www.456.com/server.php (主域名不同:123/456,跨域)http://abc.123.com/index.html 调用 http://def.123.co...
<?php /******************************************** * 使用方法: * * 1、将本段代码保存为 MkEncrypt.php * * 2、在要加密的页面前面引入这个 php 文件 * require_once('MkEncrypt.php'); * * 3、设置页面访问密码 * MkEncrypt('页面密码'); * ********************************************/ // 密码 Cookie 加密盐 if(!defined('MK_ENCR...
<?php // 存储数据的文件 $filename = 'data.dat'; // 指定页面编码 header('Content-type: text/html; charset=utf-8'); if(!file_exists($filename)) { die($filename . ' 数据文件不存在'); } // 读取整个数据文件 $data = file_get_contents($filename); // 按换行符分割成数组 $data = explode(PHP_EOL, $data); // 随机获取一行索引 $r...
/** * PHP 读取 exe\dll 文件版本号 * * @param $filename 目标文件 * @return 读取到的版本号 */ function getFileVersion($filename) { $fileversion = ''; $fpFile = @fopen($filename, "rb"); $strFileContent = @fread($fpFile, filesize($filename)); fclose($fpFile); if($strFileContent) ...
<?php function getParam($m,$n=''){ //获取get 或者 post请求的值,这里判断了字符串并清除所有特殊字符 return trim($m&&is_string($m)?isset($_POST[$m])?$_POST[$m]:(isset($_GET[$m])?$_GET[$m]:$n):$n); } ?>
<?php //随机小数 180it.com 搜集 function randomFloat($min = 0, $max = 1) { return '0.'.rand($min,$max); } ?>
<?php /** * 时间转化函数 180it.com 收集 * * @param $datetemp * @param $dstr * @return string */ function smartDate($datetemp, $dstr = 'Y-m-d H:i:s') { $op = ''; $sec = time() - $datetemp; $hover = floor($sec / 3600); if ($hover == 0) { $min = floor($sec / 60); if ($min == 0) { ...
<?php function generate_password( $length = 8 ) { $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $password = ""; for ( $i = 0; $i < $length; $i++ ) { $password .= $chars[ mt_rand(0, strlen($chars) - 1) ]; } return $password; } ?>
<?php function curl_request($url,$post='',$cookie='', $returnCookie=0,$ua='Mozilla/5.0 (compatible; sosospider/2.0; +http://www.soso.com/search/spider.html)',$referer='http://soso.com/'){ //curl模拟请求 //参数1:访问的URL,参数2:post数据(不填则为GET),参数3:提交的$cookies,参数4:是否返回$cookies,参数5:自定义UA,参数6:自定义来路 $cu...