全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
12
返回列表 发新帖
楼主: zzr

200金币求一个php get查询源码,金币稍后补上

[复制链接]
发表于 2017-8-28 10:57:25 | 显示全部楼层
zzr 发表于 2017-8-28 10:46
就查询目录下pass.txt吧。。每行一个。。

有点急事 中午写
发表于 2017-8-28 11:06:08 | 显示全部楼层
本帖最后由 cnly1987 于 2017-8-28 11:07 编辑

我给你写个。
实在是很久没写过PHP了,都是用python了,想了半天没想起怎么写数组。。。
新建index.php、db.php文件。
db.php:

  1. <?php


  2. class db{

  3.         private $host='IP';
  4.         private $username='帐号';
  5.         private $password='密码';
  6.         private $database='数据库名;

  7.         public function connect(){
  8.                 $c = mysqli_connect($this->host,$this->username,$this->password,$this->database);
  9.                 return $c;
  10.                
  11.         }

  12.         public function query($sql){
  13.                 $c = $this->connect();
  14.                 $res = $c->query($sql);
  15.                 if(count($res)>1){
  16.                         return json_encode(array('status' => 'yes'))
  17.                 else{
  18.                         return json_encode(array('status' => 'no'))
  19.                 }
  20.         }

  21. }
复制代码


index.php

  1. <?php
  2. include("db.php");
  3. $pass = $_GET['pass'];
  4. $c = new db;
  5. $res= $c->query("select * from tablename where field like '%$pass%' ");

  6. echo $res;       
  7. ?>
复制代码
发表于 2017-8-28 11:21:44 | 显示全部楼层
本帖最后由 521vps 于 2017-8-28 16:22 编辑

233
发表于 2017-8-28 11:32:07 | 显示全部楼层
本帖最后由 hdown 于 2017-8-28 11:41 编辑

都闪开,让我来写!


https://gist.github.com/shellus/185f87d729328f6ac8fdc2986b8643b0

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shellus
  5. * Date: 2017/8/28
  6. * Time: 11:30
  7. */
  8. $fd = fopen("pass.txt", "r");
  9. // 如果php运行在linux,那么pass.txt里面的换行符用\n
  10. // 如果php运行在windows,那就用\r\n
  11. // 如果要固定用\n,那就把代码中的PHP_EOL换成"\n"

  12. function check($pass){
  13.     if (trim($pass) === "") return false;

  14.     global $fd;
  15.     while (($line = stream_get_line($fd, 1024, PHP_EOL)) !== false){
  16.         if ($line === $pass){
  17.             return true;
  18.         }
  19.     }
  20.     return false;
  21. }


  22. if (check(@$_GET['pass'])){
  23.     echo "1";
  24. }else{
  25.     echo "0";
  26. }
复制代码
发表于 2017-8-28 11:59:51 | 显示全部楼层
  1. <?php
  2. define('FILE_PATH','pass.txt');
  3. if(!isset($_GET['pass'])){
  4.     die("错误的请求参数");
  5. }
  6. $pass = $_GET['pass'];
  7. if(!file_exists(FILE_PATH)) {
  8.     die("数据文件不存在");
  9. }
  10. $file = fopen(FILE_PATH, 'r');
  11. if(!$file){
  12.     die("数据文件打开失败!");
  13. }
  14. $isFind = false;
  15. while (!feof($file)) {
  16.     $line = stream_get_line($file, 8192, PHP_EOL);
  17.     if($line == $pass){
  18.         echo json_encode(['status' => 'yes']);
  19.         $isFind = true;
  20.         break;
  21.     }
  22. }
  23. if(!$isFind){
  24.     echo json_encode(['status' => 'no']);
  25. }
  26. fclose($file);
复制代码

萌新初学者围观dalao
发表于 2017-8-28 12:19:55 | 显示全部楼层
  1. <?php
  2. $txt =  'pass.txt'; //TXT源文件

  3. $row = file_get_contents($txt);
  4. ini_set('memory_limit', '-1');
  5. $rows=explode("\n",$row);

  6. $pass = $_GET['pass'];//获取get参数

  7. $is = in_array($pass,$rows);
  8. if($is) echo 'status=[yes]';
  9. else echo 'status=[no]';

  10. ?>
复制代码

这个只能查找相同的值不能相似或者包含
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-6-3 11:02 , Processed in 0.058555 second(s), 6 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表