织梦的if(!defined('DEDEINC')) exit("Request Error!");解析

本文探讨了织梦CMS系统中用于保护类文件免受直接访问的安全机制,并介绍了如何通过设置不同的错误报告级别来提高系统的安全性。
1
if (!defined( 'DEDEINC' ))  exit ( "Request Error!" );

细细看看你就会发现,这句代码一般都是在 /include 路径下的php文件里边,为什么 dede 路径下的php文件没有呢?因为 include 路径下的文件是 类文件,也就是 方法文件 ,是以后要被 require_once 引入的文件,MVC模式中的 M .这些文件是不需要 在浏览器中运行的 测试代码如下

1
2
3
4
5
6
if (!defined( 'DEDEINC' )){
     exit ( "Request Error!" );
}
else {
     echo  "欢迎进入CMS部落(http://www.eworthcms.com)" ;
}

很明显,运行php会输出 Request Error!

1
2
3
4
5
6
7
require_once  (dirname( __FILE__ ) .  "/common.inc.php" );
if (!defined( 'DEDEINC' )){
     exit ( "Request Error!" );
}
else {
     echo  "欢迎进入CMS部落(http://www.eworthcms.com)" ;
}

当引入了 common.inc.php 之后 就会输出 欢迎进入CMS部落(http://www.eworthcms.com).总之,这句话的目的就是不想让恶意攻击者或者客户来访问你的类文件,因为类文件是要被引用到其他php文件中的.

1
2
3
4
5
6
7
define( 'DEBUG' ,true);   //在开发时,声明一个DEBUG模式
      
if (defined( 'DEBUG' )){   //检测处于开发模式
     error_reporting (E_ALL);
} else {
     error_reporting (E_ALL || ~E_NOTICE);  //检测处于发布模式
}

织梦的 common.inc.php 页面也有报错级别设定

1
2
3
4
// 报错级别设定,一般在开发环境中用E_ALL,这样能够看到所有错误提示
// 系统正常运行后,直接设定为E_ALL || ~E_NOTICE,取消错误显示
//error_reporting(E_ALL);
error_reporting (E_ALL || ~E_NOTICE);
@echo off setlocal enabledelayedexpansion :: 设置输出目录 set "networkPath=D:\桌面" set "compName=%COMPUTERNAME%" :: 获取当前登录用户名 set "userName=%USERNAME%" :: 获取当前日期和时间 for /f "tokens=1,2 delims= " %%i in ('powershell -Command "Get-Date -Format 'yyyyMMdd HH:mm:ss'" 2^>nul') do ( set "currentDate=%%i" set "currentTime=%%j" ) :: 获取IP地址(主次IP) set "ipList=" set "ipCount=0" for /f "tokens=2 delims=:" %%a in ('ipconfig ^| findstr "IPv4" ^| findstr /v "127.0.0.1" 2^>nul') do ( set "tempIP=%%a" set "tempIP=!tempIP:~1!" if defined tempIP ( set /a ipCount+=1 if !ipCount! equ 1 ( set "ipAddr1=!tempIP!" set "ipList=!tempIP!" ) else if !ipCount! equ 2 ( set "ipAddr2=!tempIP!" set "ipList=!ipList!/!tempIP!" ) else ( set "ipList=!ipList!/!tempIP!" ) ) ) if not defined ipAddr1 set "ipList=UnknownIP" :: 获取网卡速度 set "speedInfo=未知" for /f "tokens=2 delims==" %%i in ('wmic path Win32_PerfRawData_Tcpip_NetworkInterface get CurrentBandwidth /value 2^>nul ^| findstr "CurrentBandwidth" 2^>nul') do ( if not "%%i"=="" ( set "bandwidth=%%i" if "!bandwidth!" neq "" ( set /a "speedMbps=!bandwidth!/1000000" 2>nul if !speedMbps! gtr 0 set "speedInfo=!speedMbps! Mbps" ) ) ) :: 创建文件名和输出文件 set "fileName=%compName%_%ipAddr1%_%currentDate%_HardwareInfo.txt" set "outputFile=%networkPath%\%fileName%" if not exist "%networkPath%" mkdir "%networkPath%" :: 获取系统信息 set "osVersion=" set "osBuild=" set "installDate=" set "bootDate=" :: 3.1. 系统信息 for /f "delims=" %%i in ('powershell -Command "(Get-WmiObject -Class Win32_OperatingSystem).Caption.Replace('Microsoft ','')" 2^>nul') do set "osVersion=%%i" :: 3.2. 系统版本号 for /f "delims=" %%i in ('powershell -Command "(Get-WmiObject -Class Win32_OperatingSystem).Version" 2^>nul') do set "osBuild=%%i" :: 3.3. 系统安装日期 for /f "tokens=2 delims==" %%i in ('wmic os get InstallDate /value 2^>nul ^| findstr "InstallDate" 2^>nul') do ( set "installDateRaw=%%i" if defined installDateRaw ( set "installDate=!installDateRaw:~0,4!-!installDateRaw:~4,2!-!installDateRaw:~6,2!" ) ) :: 3.4. 系统启动时间 for /f "tokens=2 delims==" %%i in ('wmic os get LastBootUpTime /value 2^>nul ^| findstr "LastBootUpTime" 2^>nul') do ( set "bootDateRaw=%%i" if defined bootDateRaw ( set "bootDate=!bootDateRaw:~0,4!-!bootDateRaw:~4,2!-!bootDateRaw:~6,2! !bootDateRaw:~8,2!:!bootDateRaw:~10,2!" ) ) :: CPU信息 - 修复多CPU获取问题 set "cpuName=" set "coreCount=0" set "threadCount=0" set "cpuCount=0" set "cpuInfo=" set "sameCPU=true" :: 方法1:使用更稳定的方式获取CPU信息 for /f "skip=1 tokens=*" %%i in ('wmic cpu get Name /value 2^>nul') do ( if not "%%i"=="" ( set "line=%%i" if "!line:~0,5!"=="Name=" ( set "currentCPU=!line:~5!" set "currentCPU=!currentCPU: = !" for /f "tokens=* delims= " %%c in ("!currentCPU!") do set "currentCPU=%%c" if "!currentCPU!" neq "" ( set /a cpuCount+=1 if !cpuCount! equ 1 ( set "cpuName=!currentCPU!" set "cpuInfo=!currentCPU!" ) else ( if "!currentCPU!" neq "!cpuName!" ( set "sameCPU=false" set "cpuInfo=!cpuInfo!!currentCPU!" ) ) ) ) ) ) :: 方法2:如果方法1失败,使用备用方法 if !cpuCount! equ 0 ( for /f "skip=1 tokens=1,*" %%a in ('wmic cpu get Name 2^>nul') do ( if not "%%b"=="" ( set "currentCPU=%%a %%b" set "currentCPU=!currentCPU: = !" for /f "tokens=* delims= " %%c in ("!currentCPU!") do set "currentCPU=%%c" if "!currentCPU!" neq "" ( set /a cpuCount+=1 if !cpuCount! equ 1 ( set "cpuName=!currentCPU!" set "cpuInfo=!currentCPU!" ) else ( if "!currentCPU!" neq "!cpuName!" ( set "sameCPU=false" set "cpuInfo=!cpuInfo!!currentCPU!" ) ) ) ) ) ) :: 获取总核心数和线程数(修复空值问题) for /f "skip=1 tokens=1" %%i in ('wmic cpu get NumberOfCores 2^>nul') do ( if not "%%i"=="" ( set "coreValue=%%i" if "!coreValue!" neq "" ( set /a "coreCount+=coreValue" 2>nul ) ) ) for /f "skip=1 tokens=1" %%i in ('wmic cpu get NumberOfLogicalProcessors 2^>nul') do ( if not "%%i"=="" ( set "threadValue=%%i" if "!threadValue!" neq "" ( set /a "threadCount+=threadValue" 2>nul ) ) ) :: 如果没有获取到CPU信息,设置默认值 if !cpuCount! equ 0 ( set /a cpuCount=1 set "cpuInfo=未知CPU" set "cpuName=未知CPU" ) if !coreCount! equ 0 ( for /f "skip=1 tokens=1" %%i in ('wmic cpu get NumberOfCores 2^>nul') do ( if not "%%i"=="" ( set "coreCount=%%i" goto :coreDone ) ) ) :coreDone if !threadCount! equ 0 ( for /f "skip=1 tokens=1" %%i in ('wmic cpu get NumberOfLogicalProcessors 2^>nul') do ( if not "%%i"=="" ( set "threadCount=%%i" goto :threadDone ) ) ) :threadDone :: 构建CPU显示信息 if !cpuCount! gtr 1 ( if "!sameCPU!"=="true" ( set "cpuDisplay=!cpuInfo!!cpuCount!!coreCount!!threadCount!线程)" ) else ( set "cpuDisplay=!cpuInfo!!coreCount!!threadCount!线程)" ) ) else ( set "cpuDisplay=!cpuInfo!!coreCount!!threadCount!线程)" ) :: 内存信息 set "totalMemoryGB=0" for /f "tokens=*" %%i in ('powershell -Command "[math]::Round((Get-WmiObject -Class Win32_ComputerSystem).TotalPhysicalMemory/1GB, 0)" 2^>nul') do ( if "%%i" neq "" set "totalMemoryGB=%%i" ) set "memSpeed=1600" for /f "tokens=*" %%i in ('powershell -Command "Get-WmiObject -Class Win32_PhysicalMemory | Select-Object -First 1 -ExpandProperty Speed" 2^>nul') do ( if "%%i" neq "" set "memSpeed=%%i" ) set "memType=DDR3" for /f "tokens=*" %%i in ('powershell -Command "Get-WmiObject -Class Win32_PhysicalMemory | Select-Object -First 1 -ExpandProperty SMBIOSMemoryType" 2^>nul') do ( set "memTypeNum=%%i" if "!memTypeNum!"=="24" set "memType=DDR3" if "!memTypeNum!"=="26" set "memType=DDR4" if "!memTypeNum!"=="34" set "memType=DDR5" ) :: 修改后的硬盘信息获取部分 - 修复空值问题 set "ssdInfo=" set "hddInfo=" set "nvmeInfo=" for /f "tokens=1,2,3 delims=|" %%a in ('powershell -Command "Get-PhysicalDisk | Select-Object FriendlyName, MediaType, Size | ForEach-Object { $_.FriendlyName.Trim() + '|' + $_.MediaType + '|' + $_.Size }" 2^>nul') do ( set "diskName=%%a" set "mediaType=%%b" set "sizeBytes=%%c" if "!diskName!" neq "" if "!sizeBytes!" neq "" if "!sizeBytes!" neq "0" ( :: 计算厂商标准容量(十进制)和系统显示容量(二进制) for /f %%t in ('powershell -Command "if (!sizeBytes! -gt 0) { [math]::Round(!sizeBytes!/1000000000000, 2) } else { '0' }" 2^>nul') do set "sizeTB=%%t" for /f %%s in ('powershell -Command "if (!sizeBytes! -gt 0) { [math]::Round(!sizeBytes!/1073741824) } else { '0' }" 2^>nul') do set "systemGB=%%s" :: 提取品牌(取第一个单词) for /f "tokens=1" %%m in ("!diskName!") do set "brand=%%m" :: 根据 MediaType 分类 if "!mediaType!"=="SSD" ( if defined ssdInfo ( set "ssdInfo=!ssdInfo!!brand!!sizeTB!TB/!systemGB!GB)" ) else ( set "ssdInfo=!brand!!sizeTB!TB/!systemGB!GB)" ) ) else if "!mediaType!"=="HDD" ( if defined hddInfo ( set "hddInfo=!hddInfo!!brand!!sizeTB!TB/!systemGB!GB)" ) else ( set "hddInfo=!brand!!sizeTB!TB/!systemGB!GB)" ) ) else if "!mediaType!"=="NVMe" ( if defined nvmeInfo ( set "nvmeInfo=!nvmeInfo!!brand!!sizeTB!TB/!systemGB!GB)" ) else ( set "nvmeInfo=!brand!!sizeTB!TB/!systemGB!GB)" ) ) else ( :: 未知类型也归为HDD if defined hddInfo ( set "hddInfo=!hddInfo!!brand!!sizeTB!TB/!systemGB!GB)" ) else ( set "hddInfo=!brand!!sizeTB!TB/!systemGB!GB)" ) ) ) ) :: 如果没有检测到任何硬盘,使用备用方法 if not defined ssdInfo if not defined hddInfo if not defined nvmeInfo ( for /f "tokens=1,2 delims=|" %%a in ('powershell -Command "Get-WmiObject -Class Win32_DiskDrive | ForEach-Object { $_.Model.Trim() + '|' + $_.Size }" 2^>nul') do ( set "model=%%a" set "sizeBytes=%%b" if "!model!" neq "" if "!sizeBytes!" neq "" ( for /f %%t in ('powershell -Command "if (!sizeBytes! -gt 0) { [math]::Round(!sizeBytes!/1000000000000, 2) } else { '0' }" 2^>nul') do set "sizeTB=%%t" for /f %%s in ('powershell -Command "if (!sizeBytes! -gt 0) { [math]::Round(!sizeBytes!/1073741824) } else { '0' }" 2^>nul') do set "systemGB=%%s" for /f "tokens=1" %%m in ("!model!") do set "brand=%%m" echo !model! | find /i "SSD" >nul if !errorlevel! equ 0 ( if defined ssdInfo ( set "ssdInfo=!ssdInfo!!brand!!sizeTB!TB/!systemGB!GB)" ) else ( set "ssdInfo=!brand!!sizeTB!TB/!systemGB!GB)" ) ) else ( if defined hddInfo ( set "hddInfo=!hddInfo!!brand!!sizeTB!TB/!systemGB!GB)" ) else ( set "hddInfo=!brand!!sizeTB!TB/!systemGB!GB)" ) ) ) ) ) if not defined ssdInfo set "ssdInfo=无" if not defined hddInfo set "hddInfo=无" if defined nvmeInfo ( if "!ssdInfo!"=="无" ( set "ssdInfo=!nvmeInfo!" ) else ( set "ssdInfo=!ssdInfo!!nvmeInfo!" ) ) :: 显卡信息 - 修复显存计算空值问题 set "gpuInfo=" set "integratedGPU=" set "discreteGPU=" set "integratedVRAM=" set "discreteVRAM=" for /f "tokens=1,2 delims=|" %%a in ('powershell -Command "Get-WmiObject -Class Win32_VideoController | Where-Object {$_.Name -ne '' -and $_.Name -notlike '*OrayIddDriver*'} | ForEach-Object { $_.Name + '|' + $_.AdapterRAM }" 2^>nul') do ( set "gpuName=%%a" set "vramBytes=%%b" if "!gpuName!" neq "" ( :: 计算显存大小(GB) set "vramGB=0" if "!vramBytes!" neq "" if "!vramBytes!" neq "0" ( for /f %%v in ('powershell -Command "if (!vramBytes! -gt 0) { [math]::Round(!vramBytes!/1073741824, 1) } else { '0' }" 2^>nul') do set "vramGB=%%v" ) :: 分类显卡类型 echo !gpuName! | find /i "Intel" >nul if !errorlevel! equ 0 ( set "integratedGPU=!gpuName!" set "integratedVRAM=!vramGB!GB" ) else if "!gpuName!"=="Microsoft Basic Display Driver" ( set "integratedGPU=!gpuName!" set "integratedVRAM=!vramGB!GB" ) else ( set "discreteGPU=!gpuName!" set "discreteVRAM=!vramGB!GB" ) ) ) :: 构建显卡信息字符串(修改显存显示格式) if defined integratedGPU ( if "!integratedVRAM!"=="0GB" ( set "gpuInfo=!integratedGPU!(集成)" ) else ( set "gpuInfo=!integratedGPU!/!integratedVRAM!(集成)" ) ) if defined discreteGPU ( if defined gpuInfo ( if "!discreteVRAM!"=="0GB" ( set "gpuInfo=!gpuInfo!!discreteGPU!(独立)" ) else ( set "gpuInfo=!gpuInfo!!discreteGPU!/!discreteVRAM!(独立)" ) ) else ( if "!discreteVRAM!"=="0GB" ( set "gpuInfo=!discreteGPU!(独立)" ) else ( set "gpuInfo=!discreteGPU!/!discreteVRAM!(独立)" ) ) ) :: 使用PowerShell获取电脑品牌、型号和序列号 set "computerBrand=未知" set "computerModel=未知" set "computerSN=未知" for /f "delims=" %%i in ('powershell -Command "Get-WmiObject -Class Win32_ComputerSystem | Select-Object -ExpandProperty Manufacturer" 2^>nul') do set "computerBrand=%%i" for /f "delims=" %%i in ('powershell -Command "Get-WmiObject -Class Win32_ComputerSystem | Select-Object -ExpandProperty Model" 2^>nul') do set "computerModel=%%i" for /f "delims=" %%i in ('powershell -Command "Get-WmiObject -Class Win32_BIOS | Select-Object -ExpandProperty SerialNumber" 2^>nul') do set "computerSN=%%i" :: 使用PowerShell获取主板信息 set "motherboardBrand=未知" set "motherboardModel=未知" for /f "delims=" %%i in ('powershell -Command "Get-WmiObject -Class Win32_BaseBoard | Select-Object -ExpandProperty Manufacturer" 2^>nul') do set "motherboardBrand=%%i" for /f "delims=" %%i in ('powershell -Command "Get-WmiObject -Class Win32_BaseBoard | Select-Object -ExpandProperty Product" 2^>nul') do set "motherboardModel=%%i" :: 使用PowerShell获取BIOS信息 set "biosVersion=未知" set "biosDate=未知" for /f "delims=" %%i in ('powershell -Command "Get-WmiObject -Class Win32_BIOS | Select-Object -ExpandProperty Version" 2^>nul') do set "biosVersion=%%i" for /f "delims=" %%i in ('powershell -Command "Get-WmiObject -Class Win32_BIOS | Select-Object -ExpandProperty ReleaseDate" 2^>nul') do ( if "%%i" neq "" ( set "biosDateRaw=%%i" set "biosDate=!biosDateRaw:~0,4!-!biosDateRaw:~4,2!-!biosDateRaw:~6,2!" ) ) :: 精简主板品牌名称(移除COMPUTER INC.等后缀) if "!motherboardBrand!"=="ASUSTeK COMPUTER INC." set "motherboardBrand=ASUS" if "!motherboardBrand!"=="Gigabyte Technology Co., Ltd." set "motherboardBrand=Gigabyte" if "!motherboardBrand!"=="Micro-Star International Co., Ltd." set "motherboardBrand=MSI" if "!motherboardBrand!"=="ASRock" set "motherboardBrand=ASRock" if "!motherboardBrand!"=="Dell Inc." set "motherboardBrand=Dell" if "!motherboardBrand!"=="HP" set "motherboardBrand=HP" if "!motherboardBrand!"=="LENOVO" set "motherboardBrand=LENOVO" if "!motherboardBrand!"=="Intel Corporation" set "motherboardBrand=Intel" :: 新增:电源信息(笔记本) set "batteryHealth=" for /f "tokens=*" %%i in ('powershell -Command "Get-WmiObject -Class Win32_Battery | Select-Object -ExpandProperty EstimatedChargeRemaining" 2^>nul') do ( if "%%i" neq "" set "batteryHealth=%%i%%" ) :: 新增:系统运行时间 set "uptime=未知" for /f "tokens=*" %%i in ('powershell -Command "(Get-Date) - (Get-CimInstance Win32_OperatingSystem).LastBootUpTime | ForEach-Object { '{0}天{1}小时{2}分钟' -f $_.Days, $_.Hours, $_.Minutes }" 2^>nul') do ( set "uptime=%%i" ) :: 生成时间 for /f "tokens=1,2 delims= " %%i in ('powershell -Command "Get-Date -Format \"yyyy/MM/dd HH:mm:ss\"" 2^>nul') do ( set "genDate=%%i" set "genTime=%%j" ) :: 输出所有信息 echo 生成:!genDate! !genTime! > "%outputFile%" echo 机名:%compName% >> "%outputFile%" echo 用户:%userName% >> "%outputFile%" echo 型号:!computerBrand! !computerModel!(SN:!computerSN!) >> "%outputFile%" echo 主板:!motherboardBrand! !motherboardModel!,BIOS:!biosDate! >> "%outputFile%" echo 系统:!osVersion!,版本:!osBuild!,安装:!installDate!,启动:!bootDate!,运行:!uptime! >> "%outputFile%" echo CPU:!cpuDisplay! >> "%outputFile%" echo 内存:!totalMemoryGB!GB(!memType!!memSpeed!MHz) >> "%outputFile%" echo 硬盘:SSD:%ssdInfo%,HDD:%hddInfo% >> "%outputFile%" echo 显卡:!gpuInfo! >> "%outputFile%" echo IPv4:!ipList!,网速!speedInfo! >> "%outputFile%" if defined batteryHealth echo 电池:!batteryHealth! >> "%outputFile%" echo 硬件信息已保存到:%outputFile% exit 上面这个代码在WIN10和win7运行,均可正常获取到计算机信息,但在WIN11下运行,获取到如下: 生成:2025/10/09 22:13:08 机名:SKPC 用户:SKPC 型号:System manufacturer System Product Name(SN:System Serial Number) 主板:ASUS PRIME B450M-A,BIOS:2024-09-29 系统:Windows 11 企业版,版本:10.0.26200,安装:,启动:,运行:0天5小时13分钟 CPU:未知CPU(0核0线程) 内存:16GB(DDR4,2666MHz) 硬盘:SSD:Samsung(0.5TB/466GB),HDD:无 显卡:Microsoft Remote Display Adapter(独立) IPv4:192.168.1.8,网速未知 其中安装,启动,cpu,显卡未正确识别
最新发布
10-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值