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 poi合并多个word成一个新word,原word中横版没了.
  • ¥15 【火车头采集器】搜狐娱乐这种列表页网址,怎么采集?
  • ¥15 求MCSCANX 帮助
  • ¥15 机器学习训练相关模型
  • ¥15 Todesk 远程写代码 anaconda jupyter python3
  • ¥15 我的R语言提示去除连锁不平衡时clump_data报错,图片以下所示,卡了好几天了,苦恼不知道如何解决,有人帮我看看怎么解决吗?
  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?