日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

php 解决方案,php优化解决方案

發布時間:2023/11/27 生活经验 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php 解决方案,php优化解决方案 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

php優化

本帖最后由 xuzuning 于 2013-09-30 13:05:14 編輯

//define?server?info?begin

$servername?=?"192.168.1.182";

$serverusername?=?"whh";

$serverpassword?=?"whh";

$database="whh";

$usertable="user";

$userfield="user_name";

$passwordfield="password";

//define?server?info?end

$fh??=?fopen("php://stdin",?'r');

$stdout?=?fopen('php://stdout',?'w');

$fs?=?fopen("auth-log.txt."?.?getmypid(),?'a');

if(!$fh){

die("Cannot?open?STDIN\n");

}

do{

$lenBytes?=?fgets($fh,?3);

$len?=?unpack('n',?$lenBytes);

$len?=?$len[1];

if($len<1)?continue;

$msg?=?fgets($fh,?$len+1);

$toks=explode(':',$msg);

fwrite($fs,?$msg?.?"\n");

$method?=?array_shift($toks);

fwrite($fs,?"$method\n");

$result?=?false;

switch($method){

case?'auth':

list($username,?$server,?$password)?=?$toks;

$password?=?trim($password);

fwrite($fs,?"checking?user:?$username?and?password?$password\n");

//check?password?begin

$conn=mysql_connect($servername,?$serverusername,?$serverpassword);

mysql_query("set?names?'utf8'");

if(!$conn){

die("could?not?connect?to?the?database");

}

$db_select=mysql_select_db($database);//選擇數據庫

if(!$db_select)

{

die("could?not?to?the?database");

}

$query="select?*?from?$usertable?where?$userfield?=?'$username'?and?$passwordfield='$password'";//構建查詢語句

$result=mysql_query($query);//執行查詢

$count=mysql_numrows($result);//取得條數

mysql_close($conn);

if($count?>?0){

$result?=?true;

}else{

$result?=?false;

}

//check?password?end

break;

case?'isuser':

list($username,?$server)?=?$toks;

//check?password?begin

$conn=mysql_connect($servername,?$serverusername,?$serverpassword);

mysql_query("set?names?'utf8'");

if(!$conn){

die("could?not?connect?to?the?database");

}

$db_select=mysql_select_db($database);//選擇數據庫

if(!$db_select)

{

die("could?not?to?the?database");

}

$query="select?*?from?$usertable?where?$userfield?=?'$username'";//構建查詢語句

$result=mysql_query($query);//執行查詢

$count=mysql_numrows($result);//取得條數

mysql_close($conn);

if($count?>?0){

$result?=?true;

}else{

$result?=?false;

}

//check?password?end

break;

default:

$result?=?false;

}

$message?=??@pack("nn",?2,?$result);

fwrite($stdout,?$message);

$dump?=?@unpack("nn",?$message);

$dump?=?$dump["n"];

fwrite($fs,?$dump?.?"\n");

flush();

}?while(true);

大家好!

對php我不懂,請大家看下是否可以對該php做些優化呢?

我是寫java的,發現可能在這個地方“$conn=mysql_connect($servername,?$serverusername,?$serverpassword);”可以進行優化,沒有必要每次都生成一個$conn。

總結

以上是生活随笔為你收集整理的php 解决方案,php优化解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。