dougu3591 2014-02-18 16:06
浏览 57
已采纳

通过命令行将GET / POST参数传递给php

I'll excuse myself behorehand because i'm quite sure there'll be some obvious solution or an answer already out there, but after quite some extensive search I just cant find it.

I'm developing a simplified web server as a project in .net. What i want to do is calling the php.exe for each HTML request to execute any php code within the file, and then return the result to my server where it will be served to the client.

This was quite simple without passing GET/POST parameters, but I can't find the way to make this work.

Right now i have this as my function to write the call the php via command line

Public Shared Function phpparse(ByVal requesttype As String, ByVal argnames() As String, ByVal argvals() As String)
    Dim proc As Process = New Process
    proc.StartInfo.FileName = "php\php.exe"
    Dim B As New System.Text.StringBuilder
    B.Append("-B ""$_")
    B.Append(requesttype & " = array(")
    For i As Integer = 0 To argnames.Length - 1
        B.Append("'" & argnames(i) & "' => '" & argvals(i) & "', ")
    Next
    B.Remove(B.Length - 2, 2)
    B.Append(");"" -F script.php")
    InputBox("", "", B.ToString)
    proc.StartInfo.Arguments = B.ToString
    proc.StartInfo.UseShellExecute = False
    proc.StartInfo.RedirectStandardOutput = True
    proc.StartInfo.CreateNoWindow = True
    proc.Start()
    Return proc.StandardOutput.ReadToEnd
End Function

which returns something like this:

-B "$_GET = array('name' => 'John', 'email' => 'john.doe@no.com');" -F script.php

and should be calling this test php script:

<html>
<body>

Welcome <?php echo $_GET["name"]; ?><br>
Your email address is: <?php echo $_GET["email"]; ?>

</body>
</html> 

but it gets stuck trying to read the answer

  • 写回答

2条回答 默认 最新

  • douqiu0351 2014-02-18 18:04
    关注

    I've found a work around the issue. I'm still looking for a proper solution but I can work with this for now

    The parameters of the call to the PHP CLI should be

    -r "$arrayname = array('arraypar1' => 'arrayval1', 'arraypar2' => 'arrayval2', ); require_once('C:\fullroutetofile\script.php');"

    It seems that you can't call -B and -f at the same time, but require_once lets you bypass that.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办