如何在php作业调度器功能页中添加$id

如何在php作业调度器功能页中添加$id,php,mysql,Php,Mysql,我正在使用phpjobscheduler脚本,我想发送带有$id的链接,但问题是链接是使用curl和include函数打开的,所以我如何在数据库中添加link+id,或者当它触发打开链接时,$id如何附加并使url类似于link+id…第一页是将数据插入数据库的索引这里是index.php代码 $query="INSERT INTO data (scriptpath) VALUES ('http://localhost/test.php?id=')"; 这是一个功能页面,我想我

我正在使用phpjobscheduler脚本,我想发送带有$id的链接,但问题是链接是使用curl和include函数打开的,所以我如何在数据库中添加link+id,或者当它触发打开链接时,$id如何附加并使url类似于link+id…第一页是将数据插入数据库的索引这里是index.php代码

        $query="INSERT INTO data (scriptpath) VALUES ('http://localhost/test.php?id=')";
这是一个功能页面,我想我们将用id完成url,但不知道下面的代码在哪里

<?php
function fire_script($script,$id,$buffer_output=1)
{
        if(($buffer_output) AND (!DEBUG)) ob_start();//buffer output 
        $scriptRunning = new scriptStatus;
        $scriptRunning->script=$script;
        if ($scriptRunning->Running($id) )
        {
            if (DEBUG) echo "<br>Now running: $script- id=$id (debug ref. 3.9b)<br>";
            $start_time = microtime(true);
            $fire_type = (function_exists('curl_exec') ) ? " PHP CURL " : " PHP fsockopen ";
        //                 "://" satisfies both cases http:// and https://
        if (strstr($script,"://") ) fire_remote_script($script);
        else
        {
            include(LOCATION.$script);
            $fire_type=" PHP include ";
        }
        if(($buffer_output) AND (!DEBUG)) 
        {
            $scriptRunning->output=ob_get_contents();
            ob_end_clean();
        }
        if (!$buffer_output) $scriptRunning->output="";
        $scriptRunning->execution_time=number_format( (microtime(true) - $start_time), 5 )." seconds via".$fire_type;
        $scriptRunning->Stopped($id);
    }
}

function Clear($id)
{
    $dbc = dbc::instance();
        //If things go wrong, or script timeout CLEAR script so will run next time
        $result = $dbc->prepare("UPDATE table SET currently_running = '0' where id='$id' ");
        $result = $dbc->execute($result); 
    }

    class scriptStatus {
        public $script;
        public $output;
        public $executionTime;
        public function Running($id)
        {
            $dbc = dbc::instance();
            $result = $dbc->prepare("UPDATE table SET currently_running='1' where id='$id' ");
            $result = $dbc->execute($result);
        register_shutdown_function('Clear', $id);//registered incase execution times out before scriptStatus->Stopped called
        return $result;                          //register_shutdown_function always works, where destruct might not!
    }
    public function Stopped($id)
    {
        $dbc = dbc::instance();
        $result = $dbc->prepare("UPDATE table SET currently_running='0' where id='$id' ");
        $result = $dbc->execute($result);
        if (ERROR_LOG) //save log to db
        {
            $now = time();
            $this->script=clean_input($this->script);
        $this->output=substr(htmlentities($this->output), 0, MAX_ERROR_LOG_LENGTH);// truncate output to defined length     
        $query="INSERT INTO ".LOGS_TABLE." (`id`, `date_added`,`script`, `output`, `execution_time`)
        VALUES (NULL,'$now', '$this->script','$this->output','$this->execution_time') ";
        $result = $dbc->prepare($query);
        $result = $dbc->execute($result);
        if (DEBUG) echo "<br>QUERY to insert data to ".LOGS_TABLE." table:<br>$query (debug ref. 3.9c)<br>";
    }   
}
}

function fire_remote_script($url)
{
$url_parsed = parse_url($url);
$scheme = $url_parsed["scheme"];
$host = $url_parsed["host"];
$port = isset($url_parsed["port"]) ? $url_parsed["port"] : 80;
$path = isset($url_parsed["path"]) ? $url_parsed["path"] : "/";
$query = isset($url_parsed["query"]) ? $url_parsed["query"] : "";
$user = isset($url_parsed["user"]) ? $url_parsed["user"] : "";
$pass = isset($url_parsed["pass"]) ? $url_parsed["pass"] : "";
$useragent="";
$referer=$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$buffer="";
if (function_exists('curl_exec'))
{
    $ch = curl_init($scheme."://".$host.$path);
    curl_setopt($ch, CURLOPT_PORT, $port);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt($ch, CURLOPT_FAILONERROR,1); // true to fail silently
        curl_setopt($ch, CURLOPT_AUTOREFERER,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$query);
        curl_setopt($ch, CURLOPT_REFERER,$referer);
        curl_setopt($ch, CURLOPT_USERAGENT,$useragent);
        curl_setopt($ch, CURLOPT_USERPWD,$user.":".$pass);
        $buffer = curl_exec($ch);
        curl_close($ch);
    }
    elseif ( $fp = @fsockopen($host, $port, $errno, $errstr, 30) )
    {
        $header = "POST $path HTTP/1.0\r\nHost: $host\r\nReferer: $referer\r\n"
        ."Content-Type: application/x-www-form-urlencoded\r\n"
        ."User-Agent: $useragent\r\n"
        ."Content-Length: ". strlen($query)."\r\n";
        if($user!= "") $header.= "Authorization: Basic ".base64_encode("$user:$pass")."\r\n";
        $header.= "Connection: close\r\n\r\n";
        fputs($fp, $header);
        fputs($fp, $query);
        if ($fp) while (!feof($fp)) $buffer.= fgets($fp, 8192);
        @fclose($fp);
    }
    echo $buffer;
}

class dbc extends PDO
{
    protected static $instance;

    public function __construct()
    {   
        $options = array(PDO::ATTR_PERSISTENT => true,
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
            PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES '".CHARSET."';"
            );
        try {
            $this->dbconn = new PDO(DBDRIVER.":host=".DBHOST.";port=".DBPORT.";dbname=".DBNAME,DBUSER,DBPASS,$options);
            return $this->dbconn;
        }
        catch (PDOException $e){ $this->reportDBError($e->getMessage()); }   
    }

    public function reportDBError($msg)
    {
        if (DEBUG) print_r('<div style="padding:10%;"><h3>'.nl2br($msg).'</h3>(debug ref. 3.9d)</div>');
        else
        {
            if(!session_id()) session_start();
            $_SESSION['mysql_errors'] = "\n\nDb error: ".$msg."\n";
        }
    }

    public static function instance()
    {
        if (!isset(self::$instance)) self::$instance = new self();
        return self::$instance;
    }

    public function prepare($query, $options = NULL) {
        try { return $this->dbconn->prepare($query); }
        catch (PDOException $e){ $this->reportDBError($e->getMessage()); }   
    }      

    public function bindParam($query) {
        try { return $this->dbconn->bindParam($query); }
        catch (PDOException $e){ $this->reportDBError($e->getMessage()); }     
    }

    public function query($query) {
        try {
            if ($this->query($query)) return $this->fetchAll();
            else return 0;
        } 
        catch (PDOException $e){ $this->reportDBError($e->getMessage()."<hr>".$e->getTraceAsString()); } }

        public function execute($result) {//use for insert/update/delete
            try { if ($result->execute()) return $result; } 
            catch (PDOException $e){ $this->reportDBError($e->getMessage()."<hr>".$e->getTraceAsString()); }     
        }
        public function executeGetRows($result) {//use to retrieve rows of data
            try { 
                if ($result->execute()) return $result->fetchAll(PDO::FETCH_ASSOC);
                else return 0;
            }
            catch (PDOException $e){ $this->reportDBError($e->getMessage()."<hr>".$e->getTraceAsString()); }     
        }

        public function __clone()
        {  //not allowed
        }
        public function __destruct()
        {
            $this->dbconn = null;
        }
    }

是的,您必须有link.php?id=4而不是link+id link.php?NameOfVariable=VariableValue

所以只需在函数中添加id并将其附加到url
fire\u remote\u脚本($url,$id)
然后这一行
$url\u parsed=parse\u url($ur.'id=.$id
)`我也尝试了,但没有找到workingerror是未定义的变量:第318行的C:\xampp\functions.php中的id和fire\u remote\u script()缺少参数2,在这一行
if(strstrstr($script,“:/”)fire\u remote\u script($script)中调用
如果(strstrstr($script,“:/”)fire\u remote\u script($script,“:/”),您还需要传递id
if
但您还需要确保$id对它可用,以传递这些错误修复,但是现在链接页面通过错误未定义索引:test.php第6行代码中的C:\xampp\htdocs\test.php中的id是include(“functions.php”)$id=清除输入($获取['id'])$dbc=dbc::instance()$结果=$dbc->prepare(“从id='$id'的表中选择*)$行=$dbc->executeGetRows($result);foreach($row作为$row){$id=$row[“id”];echo$id;}