简体   繁体   English

exec PHP不传递参数

[英]exec PHP not passing arguments

I am trying to execute a php script from within another php script. 我试图从另一个PHP脚本中执行一个PHP脚本。 I cant seem to get it to pass the parameters properly. 我似乎无法使其正确传递参数。 What am I doing wrong? 我究竟做错了什么?

First script called 第一个脚本称为

<?php

 $item = "hello";
 $item2 = "world";
 exec("php scriptToBeExecuted.php arg1=".$item." arg2=".$item2." &"); 
?>

Script to be executed 要执行的脚本

<?php
var_dump($argc);
if (isset($argv)) 
{
     parse_str(implode('&', array_slice($argv, 1)), $_GET);

     $item= $_GET['arg1'];
     $item2= $_GET['arg2'];;
}
else
{
   echo "not set";
}
?>

I do not recieve any output in a browser when I try to execute this. 尝试执行此操作时,在浏览器中未收到任何输出。 Which isn't the main issue because I am using this to make database calls but like I said, after hours of fussing with this, it will not execute properly or at all 这不是主要问题,因为我正在使用它进行数据库调用,但是就像我说的那样,经过数小时的忙碌之后,它将无法正常执行或根本无法执行

You have to either run this script as a command or as a web page. 您必须以命令或网页的形式运行此脚本。 If the former, there is no such thing as $_GET . 如果是前者,则没有$ _GET这样的东西。 If the latter, there is no $argv . 如果是后者,则没有$ argv Try this. 尝试这个。

First script called 第一个脚本称为

<?php    
 $item = "hello";
 $item2 = "world";
 exec("php scriptToBeExecuted.php $item $item2"); 
?>

Script to be executed 要执行的脚本

<?php
var_dump($argc);
if (count($argv) === 3) {
     $item= $argv[1];
     $item2= $argv[2];
} else {
   echo "not set";
}
?>

See also: 也可以看看:

PHP passing $_GET in linux command prompt PHP在Linux命令提示符中传递$ _GET

$_SERVER['argv'] with HTTP GET and CLI issue $ _SERVER ['argv'],带有HTTP GET和CLI问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM