⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 php_params.php

📁 Linux嵌入式设计配套光盘,学习嵌入式设计可参考
💻 PHP
字号:
<?php/********************************************************************  * Copyright (c) 2006, Graham P Phillips * All rights reserved. * * Redistribution and use in source and binary forms, with or without  * modification, are permitted provided that the following conditions  * are met: * *   * Redistributions of source code must retain the above copyright  *     notice, this list of conditions and the following disclaimer. *   * Redistributions in binary form must reproduce the above  *     copyright notice, this list of conditions and the following  *     disclaimer in the documentation and/or other materials provided  *     with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. ********************************************************************//* is_php_environment() checks whether this script is running in an in-process  * environment (like Apache) or or a CGI environment. */function is_php_environment() {  if (array_key_exists('SERVER_SOFTWARE', $_SERVER)) {    if (strstr($_SERVER['SERVER_SOFTWARE'], "PHP")) {      return true;    }    /* We know that GoAhead does not support PHP */    if (strstr($_SERVER['SERVER_SOFTWARE'], "GoAhead-Webs")) {      return false;    }    /* Apache and lighttpd define PHP_SELF */    if (array_key_exists('PHP_SELF', $_SERVER)) {      return true;     }  }  return false;}/* read_params() provides uniform access to form input parameters. * The caller can use this function to retrieve form parameters in  * the same way regardless of whether this script is running in a  * in-process environment (like Apache) or a CGI environment.  */ function read_params() {  $params = array();  if (is_php_environment()) {    foreach ($_REQUEST as $name => $value) {      $params[$name] = $value;    }  } else {    $content_length = -1;    if (array_key_exists('CONTENT_LENGTH', $_ENV)) {      /* post requests parameters are found in stdin */      if (is_numeric($_ENV['CONTENT_LENGTH'])) {        $content_length = $_ENV['CONTENT_LENGTH'];       }       if ($content_length > 0) {        $stdin = fopen('php://stdin', 'r');        $buffer = fgets($stdin, $content_length);        parse_str($buffer, $params);      }    }     /* post requests parameters are set an environment variables */    foreach ($_ENV as $name => $value)       $params[$name] = $value;  }  return $params;}/* daemon_connect() opens a connection using pg_connect() to the given * db_host, db_port and db_user.  The function returns the connection. * Error messages are appended to error[]. */function daemon_connect($db_host, $db_port, $db_user, &$error) {  if (!function_exists('pg_connect')) {    $error[] = "The pg_connect() function is not defined.";     $error[] = "This is probably because PHP on the web server was not configured with the --with-pgsql option.";     return NULL;   }  /* Suppress Postgres error messages */  error_reporting(error_reporting() & 0xFFFD);  $connection = pg_connect($db_host, $db_port, $db_user);  if (!$connection) {    $error[] = "Unable to connect to daemon.  Attempted to connect to \"" .$db_host . "\" on port " . $db_port . ".";     return NULL;  }  return $connection;}/* get_log_count() connects to logmuxd and gets the 'count' * field from the NetDest table.  The count is used as an * ID or signature to identify the most recent log message * available.  Returns a negative number if there is an error. */function get_log_count($host,$port) {  /* Suppress Postgres error messages */  error_reporting(error_reporting() & 0xFFFD);  /* connect to the RTA interface on the logger */  $connection = pg_connect($host, $port, '');  if ($connection == "") {     return(-1);  }  /* Get the count of log messages so far.  This count is the "ID". */  $command = "SELECT count FROM NetDest WHERE destname = 'default'";  $result = pg_exec($connection, $command);  if ($result == "") {     pg_close($connection);    return(-2);  }  $nrow = pg_NumRows($result);  if ($nrow == 1) {    $log_id = pg_result($result, 0, 0);    return($log_id);  }  else {    return(-3);  }  pg_freeresult($result);  pg_close($connection);}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -