您现在的位置是:首页 > 网站建设网站建设

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

江湖快报网2023-04-13 13:05:34【网站建设】人已围观

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

这个问题还真不知道。不过为了帮助你,在网上找了一个参考资料希望适合你: 用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])是为了限至命令只能从本地服务器提交,有一定的安全措施

Tags:调用   实现   怎么

很赞哦! ()

文章评论

    共有条评论来说两句吧...

    用户名:

    验证码:

本站推荐