php判断https
‘壹’ php 判断是post还是get
PHP 判断是否为Get/Post/Ajax提交
/**
* 是否是AJAx提交的
* @return bool
*/
function isAjax(){
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
return true;
}else{
return false;
}
}
/**
* 是否是GET提交的
*/
function isGet(){
return $_SERVER['REQUEST_METHOD'] == 'GET' ? true : false;
}
/**
* 是否是POST提交
* @return int
*/
function isPost() {
return ($_SERVER['REQUEST_METHOD'] == 'POST' && checkurlHash($GLOBALS['verify']) && (empty($_SERVER['HTTP_REFERER']) || preg_replace("~https?:\/\/([^\:\/]+).*~i", "\\1", $_SERVER['HTTP_REFERER']) == preg_replace("~([^\:]+).*~", "\\1", $_SERVER['HTTP_HOST']))) ? 1 : 0;
}
‘贰’ php正则表达式 正则匹配网址是否带http:// https://
$str = "https://xxxxxxxxx";
if(preg_match("/^(http:\/\/|https:\/\/).*$/",$str)){
echo "yes";
}
亲测是可以的,你可以自己拿去试一试
‘叁’ 如何使用php判断服务器是否是HTTPS连接
/**
*判断是否SSL协议
*@returnboolean
*/
functionis_ssl(){
if(isset($_SERVER['HTTPS'])&&('1'==$_SERVER['HTTPS']||'on'==strtolower($_SERVER['HTTPS']))){
returntrue;
}elseif(isset($_SERVER['SERVER_PORT'])&&('443'==$_SERVER['SERVER_PORT'])){
returntrue;
}
returnfalse;
}
‘肆’ 我要问的是,后端PHP怎么判断请求是来自前端
可以通过http_referer来判断.
如果安全性要求高的话建议用https 并且在前台表单里生成一个验证字符串,每次提交都判断验证字符串是否有效。
‘伍’ php 如何用正则表达式判断字符串是否是域名
$pattern ="/(https?|ftps?:)\ / \ / (\w+\.)?(\w+)(\.\w+){1,3}/";
‘陆’ 如何使用php判断服务器是否是HTTPS连接
是否https
functionis_https()
{
if(!empty($_SERVER['HTTPS'])&&strtolower($_SERVER['HTTPS'])!=='off')
{
returnTRUE;
}
elseif(isset($_SERVER['HTTP_X_FORWARDED_PROTO'])&&$_SERVER['HTTP_X_FORWARDED_PROTO']==='https')
{
returnTRUE;
}
elseif(!empty($_SERVER['HTTP_FRONT_END_HTTPS'])&&strtolower($_SERVER['HTTP_FRONT_END_HTTPS'])!=='off')
{
returnTRUE;
}
returnFALSE;
}
‘柒’ php判断服务器地址是否https
$a=$_SERVER['HTTP_REFERER'];//得到当前的URL地址
$aa=stristr($a, 'http');//查找字符串http
if ($aa != false) {
echo '这个是http';
}else {
echo '这个是https';
}
‘捌’ 怎样用php获取当前时间'https'的内容,用传值的方式
php用curl,在请求时携带:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true); // 从证书中检查SSL加密算法是否存在
‘玖’ php如何验证网址是否正确
public function getUrlParams()
{
if ($this->_urlParams === null)
{
$pa = @parse_url($this->getUrl());
$pa['scheme'] = isset($pa['scheme']) ? strtolower($pa['scheme']) : 'http';
if ($pa['scheme'] !== 'http' && $pa['scheme'] !== 'https')
{
trigger_error("Invalid url scheme `{$pa['scheme']}`", E_USER_WARNING);
return false;
}
if (!isset($pa['host']))
{
trigger_error("Invalid request url, host required", E_USER_WARNING);
return false;
}
if (!isset($pa['path']))
$pa['path'] = '/';
// basic auth
if (isset($pa['user']) && isset($pa['pass']))
$this->applyBasicAuth($pa['user'], $pa['pass']);
// convert host to IP address
$port = isset($pa['port']) ? intval($pa['port']) : ($pa['scheme'] === 'https' ? 443 : 80);
$pa['ip'] = $this->hasHeader('x-server-ip') ?
$this->getHeader('x-server-ip') : self::getIpAddr($pa['host']);
$pa['conn'] = ($pa['scheme'] === 'https' ? 'ssl' : 'tcp') . '://' . $pa['ip'] . ':' . $port;
// host header
if (!$this->hasHeader('host'))
$this->setHeader('host', strtolower($pa['host']));
else
$pa['host'] = $this->getHeader('host');
$this->_urlParams = $pa;
}
return $this->_urlParams;
}
public function getUrlParam($key)
{
$pa = $this->getUrlParams();
return isset($pa[$key]) ? $pa[$key] : null;
}
‘拾’ 这个php防外链代码怎么改才能自动判断url是否带http://
呵,直接给你正则好了
$url=$_GET['url'];
$preg='|^http://|'; //正则,匹配以http://开头的字符串
if(!preg_match($preg,$url)) { //如果不能匹配
$url='http://'.$url;
}
header("Location:".$url);
对了,建议你用<?php somecode... ?>的格式