开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 1176|回复: 11
收起左侧

[求助] php转易语言

[复制链接]
结帖率:64% (29/45)
发表于 2024-2-4 11:49:49 | 显示全部楼层 |阅读模式   广东省惠州市
[PHP] 纯文本查看 复制代码
<?php        //version lite202

//set allowTestMenu to false to disable System/Server test page
$allowTestMenu = true;

header("Content-Type: text/plain; charset=x-user-defined");
error_reporting(0);
set_time_limit(0);

define(FileDoesNotExist, 0);
define(FileCannotBeOpened, 1);
define(FileIsSQLite2, 2);
define(FileIsSQLite3, 3);
define(FileIsInvalid, 4);

function phpversion_int()
{
        list($maVer, $miVer, $edVer) = preg_split("(/|\.|-)", phpversion());
        return $maVer*10000 + $miVer*100 + $edVer;
}

if (phpversion_int() < 50300)
{
        set_magic_quotes_runtime(0);
}

function GetLongBinary($num)
{
        return pack("N",$num);
}

function GetShortBinary($num)
{
        return pack("n",$num);
}

function GetDummy($count)
{
        $str = "";
        for($i=0;$i<$count;$i++)
                $str .= "\x00";
        return $str;
}

function GetBlock($val)
{
        $len = strlen($val);
        if( $len < 254 )
                return chr($len).$val;
        else
                return "\xFE".GetLongBinary($len).$val;
}

function EchoHeader($errno)
{
        $str = GetLongBinary(1111);
        $str .= GetShortBinary(202);
        $str .= GetLongBinary($errno);
        $str .= GetDummy(6);
        echo $str;
}

function EchoConnInfo()
{
        $version = sqlite_libversion();
        $str = GetBlock($version);
        echo $version ;
        $str .= GetBlock($version);
        echo $str;
        $str .= GetBlock($version);
        echo $str;
}

function EchoConnInfo3()
{
        $version = SQLite3::version();
        $str = GetBlock($version["versionString"]);
        $str .= GetBlock($version["versionString"]);
        $str .= GetBlock($version["versionString"]);
        echo $str;
}

function EchoResultSetHeader($errno, $affectrows, $insertid, $numfields, $numrows)
{
        $str = GetLongBinary($errno);
        $str .= GetLongBinary($affectrows);
        $str .= GetLongBinary($insertid);
        $str .= GetLongBinary($numfields);
        $str .= GetLongBinary($numrows);
        $str .= GetDummy(12);
        echo $str;
}

function EchoFieldsHeader($res, $numfields)
{
        $str = "";
        for ( $i = 0; $i < $numfields; $i++ ) {
                $str .= GetBlock(sqlite_field_name($res, $i));
                $str .= GetBlock("");
                
                $type = -2;        // SQLITE_TEXT
                $length = 0;
                $flag = 0;
                
                $str .= GetLongBinary($type);
                $str .= GetLongBinary($flag);
                $str .= GetLongBinary($length);
        }
        echo $str;
}

function EchoFieldsHeader3($res, $numfields)
{
        $str = "";
        for ( $i = 0; $i < $numfields; $i++ ) {
                $str .= GetBlock($res->columnName($i));
                $str .= GetBlock("");
                
                $type = SQLITE3_NULL;
                $length = 0;
                $flag = 0;
                
                $str .= GetLongBinary($type);
                $str .= GetLongBinary($flag);
                $str .= GetLongBinary($length);
        }
        echo $str;
}

function EchoData($res, $numfields, $numrows)
{
        for ( $i = 0; $i < $numrows; $i++ ) {
                $str = "";
                $row = sqlite_fetch_array( $res, SQLITE_NUM );
                for( $j = 0; $j < $numfields; $j++ ) {
                if( is_null($row[$j]) )
                        $str .= "\xFF";
                else
                        $str .= GetBlock($row[$j]);
                $str .= GetLongBinary(-2);
                }
                echo $str;
        }
}

function EchoData3($res, $numfields, $numrows)
{
        while ($row = $res->fetchArray(SQLITE3_NUM)) {
                $str = "";
                for ( $j = 0; $j < $numfields; $j++ ) {
                        if ( is_null($row[$j]) )
                                $str .= "\xFF";
                        else
                                $str .= GetBlock($row[$j]);
                        $str .= GetLongBinary($res->columnType($j));
                }
                echo $str;
        }
}

function SQLite2($action, $path, $queries)
{
        if (!function_exists("sqlite_open")) {
                EchoHeader(203);
                echo GetBlock("SQLite2 is not supported on the server");
                exit();
        }
        
        $errno_c = 0;
        $conn = sqlite_open($path, 0666, $error_c);
        if ($conn == FALSE) {
                $errno_c = 202;
        }
        
        EchoHeader($errno_c);
        if ($errno_c > 0) {
                echo GetBlock(sqlite_error_string($error_c));
        } elseif($action == "C") {
                EchoConnInfo();
        } elseif($action == "2") {
                sqlite_query($conn, "VACUUM");
                EchoConnInfo();
        } elseif($action == "Q") {
                for($i=0;$i<count($queries);$i++) {
                        $query = $queries[$i];
                        if ($query == "") continue;
                        if (phpversion_int() < 50400){  
                                if(get_magic_quotes_gpc())
                                        $query = stripslashes($query);
                        }
                        $res = sqlite_query($conn, $query);
                        $errno = sqlite_last_error($conn);
                        $affectedrows = sqlite_changes($conn);
                        $insertid = sqlite_last_insert_rowid($conn);
                        $numfields = sqlite_num_fields($res);
                        $numrows = sqlite_num_rows($res);
                        EchoResultSetHeader($errno, $affectedrows, $insertid, $numfields, $numrows);
                        if ($errno != 0)
                                echo GetBlock(sqlite_error_string($errno));
                        else {
                                if ($numfields > 0) {
                                        EchoFieldsHeader($res, $numfields);
                                        EchoData($res, $numfields, $numrows);
                                } else {
                                        echo GetBlock("");
                                }
                        }
                        if ($i<(count($queries)-1))
                                echo "\x01";
                        else
                                echo "\x00";
                }
        }
        
        sqlite_close($conn);
}

function SQLite3($action, $path, $queries)
{
        if (!class_exists("Sqlite3")) {
                EchoHeader(203);
                echo GetBlock("SQLite3 is not supported on the server");
                exit();
        }
        
        $flag = SQLITE3_OPEN_READWRITE;
        if ($action == "3")
                $flag = SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE;
        
        $errno_c = 0;
        $conn = new SQLite3($path, $flag);
        if ($conn == nil) {
                $errno_c = 202;
        }
        
        EchoHeader($errno_c);
        if ($errno_c > 0) {
                echo GetBlock(SQLite3::lastErrorMsg());
        } else if($action == "C") {
                EchoConnInfo3();
        } else if($action == "3") {
                $conn->query("VACUUM");
                EchoConnInfo3();
        } else if($action == "Q") {
                for($i=0;$i<count($queries);$i++) {
                        $query = $queries[$i];
                        if ($query == "") continue;
                        if (phpversion_int() < 50400){  
                                if(get_magic_quotes_gpc())
                                        $query = stripslashes($query);
                        }
                        $res = $conn->query($query);
                        $errno = $conn->lastErrorCode();
                        $affectedrows = $conn->changes();
                        $insertid = $conn->lastInsertRowID();
                        $numfields = 0;
                        $numrows = 0;
                        if (is_a($res, "SQLite3Result")) {
                                $numfields = $res->numColumns();
                                if ($numfields > 0) {
                                        while ($row = $res->fetchArray(SQLITE3_NUM)) {
                                                $numrows++;
                                        }
                                        $res->reset();
                                }
                        }
                        EchoResultSetHeader($errno, $affectedrows, $insertid, $numfields, $numrows);
                        if ($errno != 0)
                                echo GetBlock($conn->lastErrorMsg());
                        else {
                                if ($numfields > 0) {
                                        EchoFieldsHeader3($res, $numfields);
                                        EchoData3($res, $numfields, $numrows);
                                        $res->finalize();
                                } else {
                                        echo GetBlock("");
                                }
                        }
                        if ($i<(count($queries)-1))
                                echo "\x01";
                        else
                                echo "\x00";
                }
        }
        
        $conn->close();
}

        if (phpversion_int() < 50000) {
                EchoHeader(201);
                echo GetBlock("unsupported php version");
                exit();
        }
        
        if (!isset($_POST["actn"]) || !isset($_POST["dbfile"])) {
                $testMenu = $allowTestMenu;
                if (!$testMenu){
                        EchoHeader(202);
                        echo GetBlock("invalid parameters");
                        exit();
                }
        }
        
        if (!$testMenu){
                if ($action == "2" || $action == "3") {
                        if (!isset($_POST["version"])) {
                                EchoHeader(202);
                                echo GetBlock("invalid parameters");
                                exit();
                        }
                }
                
                if ($_POST["encodeBase64"] == '1') {
                        for($i=0;$i<count($_POST["q"]);$i++)
                                $_POST["q"][$i] = base64_decode($_POST["q"][$i]);
                }
                
                $action = $_POST["actn"];
                $file = $_POST["dbfile"];
                $queries = $_POST["q"];
                
                $status = FileDoesNotExist;
                if (is_file($file)) {
                        $fhandle = fopen($file, "r");
                        if ($fhandle) {
                                $sqlite2header = "** This file contains an SQLite 2.1 database **";
                                $sqlite3header = "SQLite format 3";
                                $string = fread($fhandle, strlen($sqlite2header));
                                if (strncmp($string, $sqlite2header, strlen($sqlite2header)) == 0)
                                        $status = FileIsSQLite2;
                                else if ($string == "" || strncmp(substr($string, 0, strlen($sqlite3header)), $sqlite3header, strlen($sqlite3header)) == 0)
                                        $status = FileIsSQLite3;
                                else
                                        $status = FileIsInvalid;
                                fclose($fhandle);
                        } else {
                                $status = FileCannotBeOpened;
                        }
                }
                
                if ($action == "2" || $action == "3") {
                        if ($status == FileDoesNotExist) {
                                if ($action == "2")
                                        SQLite2($action, $file, $queries);
                                else
                                        SQLite3($action, $file, $queries);
                        } else {
                                EchoHeader(202);
                                echo GetBlock("Datbase file exists already");
                        }
                } else {
                        switch ($status) {
                                case FileDoesNotExist:
                                        EchoHeader(202);
                                        echo GetBlock("Database file does not exist");
                                        break;
                                case FileCannotBeOpened:
                                        EchoHeader(202);
                                        echo GetBlock("Database file cannot be opened");
                                        break;
                                case FileIsSQLite2:
                                        SQLite2($action, $file, $queries);
                                        break;
                                case FileIsSQLite3:
                                        SQLite3($action, $file, $queries);
                                        break;
                                case FileIsInvalid:
                                        EchoHeader(202);
                                        echo GetBlock("Database file is encrypted or invalid");
                                        break;
                        }
                }
                exit();
        }



function doSystemTest()
{
        function output($description, $succ, $resStr) {
                echo "<tr><td class=\"TestDesc\">$description</td><td ";
                echo ($succ)? "class=\"TestSucc\">$resStr[0]</td></tr>" : "class=\"TestFail\">$resStr[1]</td></tr>";
        }
        output("[SQLite2] PHP version >= 5.0.0", phpversion_int() >= 50000, array("Yes", "No"));
        output("[SQLite2] sqlite_open() available", function_exists("sqlite_open"), array("Yes", "No"));
        output("[SQLite3] PHP version >= 5.3.0", phpversion_int() >= 50300, array("Yes", "No"));
        output("[SQLite3] SQLite3 class available", class_exists("SQLite3"), array("Yes", "No"));
        if (phpversion_int() >= 40302 && substr($_SERVER["SERVER_SOFTWARE"], 0, 6) == "Apache" && function_exists("apache_get_modules")){
                if (in_array("mod_security2", apache_get_modules()))
                        output("Mod Security 2 installed", false, array("No", "Yes"));
        }
}

header("Content-Type: text/html");
?>

结帖率:60% (3/5)

签到天数: 18 天

发表于 2024-2-4 12:28:24 | 显示全部楼层   河南省商丘市
本来打算翻译的,一看400行,放弃了,哈哈
回复 支持 反对

使用道具 举报

结帖率:100% (28/28)

签到天数: 29 天

发表于 2024-2-4 12:53:03 | 显示全部楼层   山东省泰安市
本来打算翻译的,一看400行,放弃了,哈哈
回复 支持 反对

使用道具 举报

结帖率:100% (78/78)

签到天数: 29 天

发表于 2024-2-4 14:44:26 | 显示全部楼层   河南省洛阳市
自由天下 发表于 2024-2-4 12:28
本来打算翻译的,一看400行,放弃了,哈哈

当时我以为那是500块
回复 支持 反对

使用道具 举报

签到天数: 29 天

发表于 2024-2-4 14:58:11 | 显示全部楼层   河北省石家庄市
风度猫 发表于 2024-2-4 14:44
当时我以为那是500块

要500块我都用想接了,哈哈
回复 支持 反对

使用道具 举报

结帖率:60% (3/5)

签到天数: 18 天

发表于 2024-2-4 15:02:59 | 显示全部楼层   河南省商丘市
风度猫 发表于 2024-2-4 14:44
当时我以为那是500块

500块精币
回复 支持 反对

使用道具 举报

结帖率:64% (29/45)

签到天数: 6 天

 楼主| 发表于 2024-2-4 15:10:43 | 显示全部楼层   广东省惠州市
冷渣渣 发表于 2024-2-4 12:53
本来打算翻译的,一看400行,放弃了,哈哈

不用全部翻译呢 只要翻译核心部分
回复 支持 反对

使用道具 举报

结帖率:100% (5/5)

签到天数: 12 天

发表于 2024-2-4 18:47:31 | 显示全部楼层   河南省平顶山市
本来打算翻译的,一看400行,放弃了,哈哈
回复 支持 反对

使用道具 举报

结帖率:100% (4/4)

签到天数: 7 天

发表于 2024-2-5 12:14:20 | 显示全部楼层   河北省邢台市
你可以转成js,然后再易语言执行js呀
回复 支持 反对

使用道具 举报

结帖率:100% (3/3)
发表于 2024-2-6 11:31:47 | 显示全部楼层   四川省自贡市
小羊要吃狼 发表于 2024-2-5 12:14
你可以转成js,然后再易语言执行js呀

这是个最好的主意
回复 支持 反对

使用道具 举报

  高级模式
B Color Image Link Quote Code Smilies |上传

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 793400750,邮箱:wp@125.la
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

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