ASP页调用PHP页里的内容该怎么实现

ASP页调用PHP页里的内容该怎么实现,第1张

这个问题还真不知道。不过为了帮助你,在网上找了一个参考资料希望适合你: 用Microsoft.XMLHTTP调用本地PHP文件runphp.php,并向runphp.php提交要执行的php代码

当然,在runphp.php 中要用到eval()来执行提交的代码相当简单吧

具体细节实现:

1.用Microsoft.XMLHTTP调用本地PHP

程序代码 function runphp(command)

on error resume next

dim Http

dim serPhp

serPhp="http://" &Request.ServerVariables("SERVER_NAME") &mid(Request.ServerVariables("PATH_INFO"),1,instrrev(Request.ServerVariables("PATH_INFO"),"/")) &"runphp.php"

command=URLEncoding("phpcommand=" &command)

set Http=server.createobject("Microsoft.XMLHTTP")

Http.open "POST",serPhp,false

Http.setrequestheader "content-length",len(command)

Http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

Http.send command

if Http.readystate<>4 then

exit function

end if

runphp=BytesToBstr(Http.responseBody,"gb2312") '注意WAP网页用utf-8,WEB用gb2312

set http=nothing

if err.number<>0 then err.Clear

end function

'2、转换乱玛,直接用xmlhttp调用有中文字符的网页得到的将是乱玛,可以通过adodb.stream组件进行转换

Function BytesToBstr(body,Cset)

dim objstream

set objstream = Server.CreateObject("adodb.stream")

objstream.Type = 1

objstream.Mode =3

objstream.Open

objstream.Write body

objstream.Position = 0

objstream.Type = 2

objstream.Charset = Cset

BytesToBstr = objstream.ReadText

objstream.Close

set objstream = nothing

End Function

在提交的命令中,我们用的是post方法,会被urlencoded,那些",',\,还有中文.会在eval中执行错误,所以还需要进行处理,下面是编码处理函数:

程序代码 Function URLEncoding(vstrIn)

strReturn = ""

For i = 1 To Len(vstrIn)

ThisChr = Mid(vStrIn,i,1)

If Abs(Asc(ThisChr)) <&HFF Then

strReturn = strReturn &ThisChr

Else

innerCode = Asc(ThisChr)

If innerCode <0 Then

innerCode = innerCode + &H10000

End If

Hight8 = (innerCode And &HFF00)\ &HFF

Low8 = innerCode And &HFF

strReturn = strReturn &"%" &Hex(Hight8) &"%" &Hex(Low8)

End If

Next

strReturn=replace(strReturn,chr(34),"%22")

strReturn=replace(strReturn,chr(39),"%27")

URLEncoding = strReturn

End Function

下面是runphp.php文件内容:比较简单

程序代码 <?

if($_SERVER["HTTP_HOST"]==$_SERVER["SERVER_NAME"]){

$phpCommand=StripSlashes($_POST["phpcommand"])

if(trim($phpCommand)!="")eval($phpCommand)

}

?>

第一句 if($_SERVER["HTTP_HOST"]==$_SERVER["SERVER_NAME"])是为了限至命令只能从本地服务器提交,有一定的安全措施

如果你的机器在支持ASP.NET的同时,又安装了支持PHP的平台,那这种 *** 作是完全可以的。

你只要把一台原本安装过IIS(支持ASP.NET)的机器上再安装PHP支持系统,让它也能解析PHP并且正常浏览,那剩下的工作就是代码怎么去(Include)的问题了。

对技术没难度,对机器有要求:

如果你的机器在支持ASP.NET的同时,又安装了支持PHP的平台,那这种 *** 作是完全可以的。

理论上完全可行的东西,只需要你去验证:

你只要把一台原本安装过IIS(支持ASP.NET)的机器上再安装PHP支持系统,让它也能解析PHP并且正常浏览,那剩下的工作就是代码怎么去(Include)的问题了。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/12051480.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存