这是一款利PHP对百度搜索下拉框提示免费代码实现参数配置调试的程序源代码.
由想要对网站进行搜索下拉调试的站长朋友们进行方便、快速的效果演示,具体参考下面的PHP代码.
如何使用?
请新建一份PHP文档,并将下面PHP代码粘贴进去,然后通过浏览器访问访该文档即可进行预览openSug各种效果
1 php 2 $starttime = explode(' ',microtime()); 3 $title = array( 4 'qun' => 'QQ群', 5 'friend' => '分流节点', 6 'api' => 'API进阶', 7 ); 8 9 session_start(); 10 $n = empty($_GET["n"]) ? NULL : $_GET["n"]; 11 $f = empty($_POST["friend"]) ? NULL : $_POST["friend"]; 12 $q = empty($_POST["qun"]) ? NULL : $_POST["qun"]; 13 $l = empty($_POST["link"]) ? NULL : $_POST["link"]; 14 15 date_default_timezone_set("PRC"); 16 header("Refresh: 3600"); 17 header("Content-Type:text/html;charset=utf-8"); 18 header("Cache-Control: max-age=". 9E9); 19 header("Expires: ". gmdate ("l, d F Y H:i:s",strtotime("+9 year"))." GMT"); 20 21 define("Q", "./qun.list"); 22 define("F", "./friend.list"); 23 define("D", "./js/opensug.js"); 24 define("WP_USE_THEMES", false); 25 define("G", "aHR0cHM6Ly9vcGVuc3VnLmdpdGh1Yi5pby9qcy9vcGVuc3VnLmpz"); 26 define("I", substr($_SERVER["PHP_SELF"],strrpos($_SERVER["PHP_SELF"], "/")+1)); 27 define("H", dirname(((isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"]=="on") || (isset($_SERVER["HTTP_X_FORWARDED_PROTO"]) && $_SERVER["HTTP_X_FORWARDED_PROTO"] == "https")) ? "https://". $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"] : "http://". $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"])); 28 define("S", $_SERVER["SERVER_NAME"]); 29 define("client", '_'. md5($_SERVER['REMOTE_ADDR']) .'_'); 30 //empty($_SERVER['HTTP_VIA']) or exit('Access Denied!'); 31 if(isset($_SESSION[client])){ 32 list($s1, $s2) = explode(' ', microtime()); 33 if( (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000) - $_SESSION[client] < 2000){ 34 header("Refresh:5"); 35 header("HTTP/1.1 403 Forbidden"); 36 exit('[403]刷新过于频繁, 请稍后重试!
'); 37 } 38 $_SESSION[client] = (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000); 39 }else{ 40 list($s1, $s2) = explode(' ', microtime()); 41 $_SESSION[client] = (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000); 42 } 43 44 if($n == 'js') _down(D);elseif($n == 'php')_down(I); 45 if(!empty($_GET['dl'])) _down('./user/'. $_GET['dl']); 46 47 // update openSug.js 48 if($n == S) exit(G); 49 if(!file_exists(D)){/* || (time()-filemtime(D)) > 604800*/ 50 !is_dir("./js/")&&mkdir("./js/", 0755, true); 51 $res = _curl(base64_decode(G)); 52 if(strlen($res) > 10){ 53 if(!file_put_contents(D, $res )) exit("Error: execution failed."); 54 }else(exit("Update failed!")); 55 header("Refresh: 3"); 56 exit("Updating openSug.js file, please wait..."); 57 } 58 59 if(!empty($f)){ 60 $url = parse_url($f) ? parse_url($f) : NULL; 61 if(!empty($url["host"])){ 62 $auth = _curl($url["scheme"] ."://". $url["host"] . (!empty($url["path"]) ? $url["path"] : NULL) ."?n=". $url["host"]); 63 if($auth == G){ 64 if(!file_put_contents(F, $url["scheme"]."://".$url["host"].$url["path"]."|" )) exit("Error: execution failed."); 65 $Msg = "Subnode sharing is complete, thank you for your support!"; 66 header("Refresh: 0"); 67 }else($Msg ="Error:The submission failed and the site you submitted is not an openSug subnode."); 68 } 69 } 70 71 if(!empty($q)){ 72 if(preg_match("/^\d*$/",$q) && strlen($q) > 4){ 73 if(!empty($l) && strlen($l) == 64 && preg_match('/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9a-zA-Z]+$/', $l) == 1) $links = $l; 74 else $qunt = 'Illegal IdKey!'; 75 if(!file_put_contents(Q, intval($q).','. (empty($links) ? NULL : $links) .'|', FILE_APPEND)) $qunt = 'Failed!'; 76 $qunt = 'Success.'; 77 }else $qunt='Illegal group number!'; 78 } 79 80 if((!empty($_POST['user']))){ 81 !is_dir("./user/")&&mkdir("./user/", 0755, true); 82 if(!file_exists(D))exit($Msg = "The openSug.js file is missing."); 83 $userJS = time() .'.js'; 84 if(!file_put_contents('./user/'. $userJS, ( get('sugResult',"") ? 'var _source;_source="'. get('sugResult',"") .'";':NULL) . file_get_contents(D) . "\r\n". $_POST['conf'] ."\r\n//{{".date('H:i:s m/d Y').'}}'.(!empty($_SERVER["HTTP_CLIENT_IP"]) ? $_SERVER["HTTP_CLIENT_IP"] : !empty($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"]:!empty($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:NULL)."{".$_SERVER['HTTP_USER_AGENT'].'}' )) exit("Error: execution failed."); 85 } 86 87 88 function get($i="",$o=""){return empty($_GET[$i]) ? $o : $_GET[$i];} 89 function _down($d){ 90 if(!file_exists($d)){header("HTTP/1.0 404 Not Found");return"";} 91 header("Content-type: application/javascript"); 92 header("Content-Disposition: attachment; filename=\"". basename($d) ."\""); 93 exit(file_get_contents($d)); 94 } 95 96 function _curl($url = ""){ 97 if(function_exists("curl_init") && strlen($url) > 6){ 98 $c = curl_init(); 99 curl_setopt($c, CURLOPT_URL, $url); 100 curl_setopt($c, CURLOPT_TIMEOUT,5); 101 curl_setopt($c, CURLOPT_RETURNTRANSFER,TRUE); 102 curl_setopt($c, CURLOPT_SSL_VERIFYPEER,false); 103 curl_setopt($c, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); 104 $res = curl_exec($c); 105 $sta = curl_getinfo($c)["http_code"]; 106 curl_close($c); 107 if($sta == '200') return $res; 108 return false; 109 }else(exit("Error:the current environment does not support cURL.")); 110 }?> 111echo empty($n) ? '' : $title[$n] .'['. (empty($_GET["sugResult"]) ? 'BaiduSuggestion' : $_GET["sugResult"]) .'.bind()] - ';?>百度搜索下拉框提示免费代码 - openSug.js .bind" /> 112 <header role="banner" style="padding:2.5% 4.5455%;background-color:#191919;margin-bottom:1em;"> 113 117 header> 118 119class="container"> 120 121 if($n=='api'){?> 122285class="list" style="margin-bottom:0;"> 123181 elseif($n=='qun'){?> 182class="item title">124class="c-list-title">API进阶class="row" style="padding:5rem">125关于出现Uncaught TypeError: Cannot read property '_GUID' of null的解决方案,请点击此处...
126class="list"> 183195 elseif($n=='friend'){?> 196class="item title"> 184186class="c-list-title">加入QQ群讨论185class="item" style="padding:10px;word-wrap:break-word;"> 187 if(file_exists(Q)){$tmp=explode('|',file_get_contents(Q));$cou=count($tmp)-2;for($i=0;$i<=$cou;$i++){$tt=explode(',',$tmp[$i]);$last=$i==$cou?' style="color:red;font-weight:bold;text-decoration:underline" title="最新分享群讨论 '.$tt[0].'"'.$tt[0]:"";echo empty($tt[1])?'$last.' οnclick="prompt(\'请手动加群:\','.$tt[0].');">'.$tt[0].' ':'$tt[1].'" target="_blank"'.$last.'>'.$tt[0].' ';}}?> 188189190 shang.qq.com/wpa/qunwpa?idkey=$l;?>" /> 194
191 群号码:$q;?>" /> 192 if(isset($qunt))echo ' '.$qunt;?> 193class="list"> 197211 else{?> 212节点:$f;?>" /> 198199
class="item title">200class="c-list-title">openSug分流节点class="item" style="padding:10px;word-wrap:break-word;"> 201 if(file_exists(F)){ 202 $tmp=explode('|',file_get_contents(F)); 203 $cou=count($tmp)-2; 204 for($i=0;$i<=$cou;$i++){ 205 $url = parse_url($tmp[$i]); 206 echo '$tmp[$i] .'" target="_blank">'. $url['host'] .' '; 207 } 208 }?>209 210class="list"> 213267 268 php } 269 echo ' 282 * 浏览器支持:IE6+, Firefox, Chrome, Safari, Opera, Edge...class="item-1st"> 214228class="item title"> 215217class="c-list-title">baiduSug = "1"216class="item"> 218224class="c-list-title"> 219223221 选中词条时默认执行表单提交动作 222 class="DEMO1">220class="msfo">class="DEMO3 DEMO0 DEMO4" maxlength="2048" name="wd" autocapitalize="off" autocomplete="off" autocorrect="off" autofocus="autofocus" placeholder="baiduSug = '1'" baiduSug="1" />class="code"> 225227<form action="https://www.baidu.com/baidu" target="_blank">226
<input type="text" baiduSug="1" name="word" size="30" />
<input type="submit" value="百度搜索" />
</form>class="item-2nd"> 229255class="item title"> 230232class="c-list-title">baiduSug = "2"231class="item"> 233251class="c-list-title"> 234250235 236 237 248 选中词条时不执行表单提交动作 249class="DEMO1"> 238247class="msfo"> 239245 246240244241 class="DEMO3 DEMO0 DEMO4" id="inputObj" maxlength="2048" name="wd" autocapitalize="off" autocomplete="off" autocorrect="off" placeholder="baiduSug = '2'" baiduSug="2" /> 242243class="code"> 252254<form action="https://www.baidu.com/baidu" target="_blank">253
<input type="text" baiduSug="2" name="word" size="30" />
<input type="submit" value="百度搜索" />
</form>class="item-3rd"> 256266class="item title"> 257259class="c-list-title">API258class="item"> 260 263264class="code">提供“百度搜索框提示”API,打造您的个性化搜索框提示功能! 获得开始...265
283 * 在网页中引入Javascript文件,Javascript代码请尽量添加到网页中 </body> 闭合标签之前.
284 * 如使用utf-8编码,请务必在script标签中设置 charset="gbk" 属性,否则搜索提示词会出现乱码.已修正!class="src" onClick="prompt('请把以下代码添加到网页</body>后面','<script type="text/javascript" src="https://opensug.github.io/js/opensug.js">');"><script type="text/javascript" src="https://cdn.jsdelivr.net/g/opensug/"></script>为受窘的人说一句解围的话;为沮丧的人说一句鼓励的话;为疑惑的人说一句提醒的话;为自卑的人说一句自信的话;为痛苦的人说一句安慰的话...因为,更多时候,我们需要的是雪中送炭,而不是锦上添花.286 if(get('sugResult',""))echo '';?> 287 288 if($n=='api'){?> 289 290
DNS: charles.ns.cloudflare.com、janet.ns.cloudflare.com
echo date('Y.m.d H:i:s[D|z]');?> if(function_exists('memory_get_usage')){$mem = round(memory_get_usage() / 1024, 2);echo $mem > 1000 ? round($mem / 1024, 2) .'MB': $mem .'KB';}$endtime = explode(' ',microtime());$thistime=$endtime[0]+$endtime[1]-($starttime[0]+$starttime[1]);echo " ". round($thistime,2) ."second.";?>291 292 293