相信好多朋友在使用jQuery进行Ajax请求接口的时候会出现 No 'Access-Control-Allow-Origin' header is present on the requested resource 然后请求失败,下面我们来简单的解决这个问题。直接上代码 $(function(){ $.ajax( { type:'get', url : 'http://你的域名/test.php', dataType : 'jsonp', //这里是重点,dataType 一定为 'jsonp' ...
第一种:正则表达式<?php function or_url($url){ $preg = "/http[s]?:\/\/[\w.]+[\w\/]*[\w.]*\??[\w=&\+\%]*/is"; if(preg_match($preg,$url)){ echo '正确的 url 地址'; }else{ echo '不是合法的 url 地址'; } } 第二种:使用内置函数 filter_var () 推荐<?php function or_url($url){ if (fi...
百度收录判断API接口源码<?php /* Plugin Name:百度收录判断 Version:1.0 Description:判断网址是否被百度收录 */ $sl_url = (isset($_GET['url']))?$_GET['url']:$_POST['url']; if(empty($sl_url)) echo '查询网址不能为空'; $data = BD_curl('https://www.baidu.com/s?wd='.urlencode($sl_url)); if(!isset($data)) showjson(array('code'=>202...
百度收录量API查询PHP源码<?php /* Plugin Name:百度收录量 Version:1.0 Description:根据域名返回百度收录量 */ $domain = (isset($_GET['domain']))?$_GET['domain']:$_POST['domain']; if(empty($domain)) echo '查询域名不能为空'; $count = baiduSL ($domain); if(!isset($count)) showjson(array('code'=>200502,'msg'=>'查询失败,请重试!'));...
//PHP设置跨域 header("Access-Control-Allow-Origin:*"); //PHP设置JSON头 以JSON格式输出 header("Content-type:application/json; charset=utf-8"); //正则取字符串 preg_match_all('/字符串(.*?)字符串/i',$data,$out); // PHP把JSON对象转字符串不转码输出 json_encode($results, JSON_UNESCAPED_UNICODE); //PHP设置最大运行时间 0 是永久...
PHP携带Cookie用Curl进行Post或Get请求获取数据简单的curl请求(Get请求)<?php function hansCurl($url) { $url="https://www.vvhan.com"; $ip = rand(0, 255) . '.' . rand(0, 255) . '.' . rand(0, 255) . '.' . rand(0, 255); $header[] = "accept: application/json"; $header[] = "accept-encoding: gzip, ...
小文件直接2行代码解决<?php $a = file('xxxx.txt'); //读取同目录xxxx.txt文本 echo $a[5];//输入本文档的第6行内容 ?> 如果文件较大,内容较多用以下代码<?php $c = getLine('./a.txt', 10); // 读取a.txt文件第11行内容 echo $c; /** * 获取指定行内容 * * @param $file 文件路径 * @param $line 行数 * @param $length 指定行返回内容长度 */ function getLine($file, $line, $l...
<?php $url = "文件地址"; //网络资源的地址 $state = @file_get_contents($url, 0, null, 0, 1); //获取网络资源的字符内容 $filename = rand(0, 123562122) . '.jpg'; //文件名称生成 ob_start(); //打开输出 readfile($url); //输出图片文件 $img = ob_get_contents(); //得到浏览器输出 ob_end_clean(); //清除输出并关闭 $size = strlen($img); //得到图片大小 $f...
实现原理1.使用文本文档存放图片链接2.当用户请求API时,PHP读取TXT文件生成随机数随机选取一个图片链接3.直接使用302重定向到目标图片地址节省服务器宽带创建创建imgurl.txt文件,写入图片地址https://static.9az.ren/static/templates/handsome/v7.3.1/wt/assets/img/sj/1.jpg https://static.9az.ren/static/templates/handsome/v7.3.1/wt/assets/img/sj/2.jpg https://static.9az.ren/static/templ...
最近应一个博友要求写了个随机图的api,可让php直接在浏览器中输出图片,支持本地文件也支持图片链接,主要功能就类似于那位博友说的网上的漫月api,下面言归正传直接贴上代码吧。index.php(主体程序)<?php error_reporting(E_ERROR); require_once '../include/common.php'; require_once 'lib/imgdata.php'; require_once 'lib/functions.php'; $karnc = new imgdata; if ($_GET['a'] == 'local') { ...