如何在此 API 中声明全局变量?

2024-04-30

我的应用程序有一个production or development我可以切换的设置。设置服务器时,我在中设置了这个标志Applications > Mamp > Conf > Apache > httpd.conf。它的目的是给我的本地 API 目录一个服务器别名。它还定义文档根等。

Listen 44447

<VirtualHost *:44447>
DocumentRoot "/Users/user/Desktop/PushChatServer/api"
ServerName 192.168.1.5:44447
ServerAlias pushchat.local
CustomLog "/Users/user/Desktop/PushChatServer/log/apache_access.log" combined
ErrorLog "/Users/user/Desktop/PushChatServer/log/apache_error.log"

SetEnv APPLICATION_ENV development
php_flag magic_quotes_gpc off

<Directory "/Users/user/Desktop/PushChatServer/api">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
</VirtualHost>

我的目标是在我的 api 中设置一个全局变量并将其传递给另一个文件。我的应用程序使用的 php 文件称为api.php我想使用一个名为的全局变量$Var1。我设置了$Var1像这样在api.php

//In api.php
global $Var1;
$Var1 = '1';

当我尝试调用它时,没有收到任何输出。我这样称呼它:

<?php

 //Checks for warnings
error_reporting(E_ALL);
ini_set("display_errors", 1);

error_reporting(E_ALL|E_STRICT); ini_set('display_errors', 'on');

include 'api.php'

echo "Var1";

?>

问题是浏览器中根本没有输出。我现在意识到代码块api.php这会干扰全局变量。我仍然不确定为什么。当我从中删除此代码块时api.php全局变量成功显示在Test.php。如何保留代码块并成功显示全局Test.php?

try 
{
// Are we running in development or production mode? You can easily switch
// between these two in the Apache VirtualHost configuration.
if (!defined('APPLICATION_ENV'))
    define('APPLICATION_ENV', getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production');

// In development mode, we show all errors because we obviously want to 
// know about them. We don't do this in production mode because that might
// expose critical details of our app or our database. Critical PHP errors
// will still be logged in the PHP and Apache error logs, so it's always
// a good idea to keep an eye on them.
if (APPLICATION_ENV == 'development')
{
    error_reporting(E_ALL|E_STRICT);
    ini_set('display_errors', 'on');

}
else
{
    error_reporting(0);
    ini_set('display_errors', 'off');
}

// Load the config file. I prefer to keep all configuration settings in a
// separate file so you don't have to mess around in the main code if you
// just want to change some settings.
require_once 'api_config.php';
$config = $config[APPLICATION_ENV];

// In development mode, we fake a delay that makes testing more realistic.
// You're probably running this on a fast local server but in production
// mode people will be using it on a mobile device over a slow connection.
if (APPLICATION_ENV == 'development')
    sleep(0);
// To keep the code clean, I put the API into its own class. Create an
// instance of that class and let it handle the request.

$api = new API($config);
$api->handleCommand();

echo "OK" . PHP_EOL;

}
catch (Exception $e)
{
// The code throws an exception when something goes horribly wrong; e.g.
// no connection to the database could be made. In development mode, we
// show these exception messages. In production mode, we simply return a
// "500 Server Error" message.

if (APPLICATION_ENV == 'development')
    var_dump($e);
else
    exitWithHttpError(500);
}

////////////////////////////////////////////////////////////////////////////////

function exitWithHttpError($error_code, $message = '')
{
switch ($error_code)
{
    case 400: header("HTTP/1.0 400 Bad Request"); break;
    case 403: header("HTTP/1.0 403 Forbidden"); break;
    case 404: header("HTTP/1.0 404 Not Found"); break;
    case 500: header("HTTP/1.0 500 Server Error"); break;
}
header('Content-Type: text/plain');

if ($message != '')
    header('X-Error-Description: ' . $message);
exit;
}

function isValidUtf8String($string, $maxLength, $allowNewlines = false)
{

if (empty($string) || strlen($string) > $maxLength)
    return false;

if (mb_check_encoding($string, 'UTF-8') === false)
    return false;

// Don't allow control characters, except possibly newlines 
for ($t = 0; $t < strlen($string); $t++)
{
    $ord = ord($string{$t});

    if ($allowNewlines && ($ord == 10 || $ord == 13))
        continue;

    if ($ord < 32)
        return false;
}

return true;
}

function truncateUtf8($string, $maxLength)
{
$origString = $string;
$origLength = $maxLength;

while (strlen($string) > $origLength)
{
    $string = mb_substr($origString, 0, $maxLength, 'utf-8');
    $maxLength--;
}

return $string;
}

UPDATE

api.php 的完整源代码。我的目标是声明一个全局变量并使用 require 语句将其传递到一个新文件。只有删除该文件开头的整个 try 块才能执行此操作,并且我需要知道原因。

<?php

global $Var1;
$Var1 = '1';    

// This is the server API for the PushChat iPhone app. To use the API, the app
// sends an HTTP POST request to our URL. The POST data contains a field "cmd"
// that indicates what API command should be executed.

try 
{
// Are we running in development or production mode? You can easily     switch
// between these two in the Apache VirtualHost configuration.
if (!defined('APPLICATION_ENV'))
    define('APPLICATION_ENV', getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production');

// In development mode, we show all errors because we obviously want to 
// know about them. We don't do this in production mode because that might
// expose critical details of our app or our database. Critical PHP errors
// will still be logged in the PHP and Apache error logs, so it's always
// a good idea to keep an eye on them.
if (APPLICATION_ENV == 'development')
{
    error_reporting(E_ALL|E_STRICT);
    ini_set('display_errors', 'on');

}
else
{
    error_reporting(0);
    ini_set('display_errors', 'off');
}

// Load the config file. I prefer to keep all configuration settings in a
// separate file so you don't have to mess around in the main code if you
// just want to change some settings.
require_once 'api_config.php';
$config = $config[APPLICATION_ENV];

// In development mode, we fake a delay that makes testing more realistic.
// You're probably running this on a fast local server but in production
// mode people will be using it on a mobile device over a slow connection.
if (APPLICATION_ENV == 'development')
    sleep(0);
// To keep the code clean, I put the API into its own class. Create an
// instance of that class and let it handle the request.

$api = new API($config);
$api->handleCommand();

echo "OK" . PHP_EOL;

}
catch (Exception $e)
{
// The code throws an exception when something goes horribly wrong; e.g.
// no connection to the database could be made. In development mode, we
// show these exception messages. In production mode, we simply return a
// "500 Server Error" message.

if (APPLICATION_ENV == 'development')
    var_dump($e);
else
    exitWithHttpError(500);
}

////////////////////////////////////////////////////////////////////////////////

function exitWithHttpError($error_code, $message = '')
{
switch ($error_code)
{
    case 400: header("HTTP/1.0 400 Bad Request"); break;
    case 403: header("HTTP/1.0 403 Forbidden"); break;
    case 404: header("HTTP/1.0 404 Not Found"); break;
    case 500: header("HTTP/1.0 500 Server Error"); break;
}
header('Content-Type: text/plain');

if ($message != '')
    header('X-Error-Description: ' . $message);
exit;
}

function isValidUtf8String($string, $maxLength, $allowNewlines = false)
{

if (empty($string) || strlen($string) > $maxLength)
    return false;

if (mb_check_encoding($string, 'UTF-8') === false)
    return false;

// Don't allow control characters, except possibly newlines 
for ($t = 0; $t < strlen($string); $t++)
{
    $ord = ord($string{$t});

    if ($allowNewlines && ($ord == 10 || $ord == 13))
        continue;

    if ($ord < 32)
        return false;
}

return true;
}

function truncateUtf8($string, $maxLength)
{
$origString = $string;
$origLength = $maxLength;

while (strlen($string) > $origLength)
{
    $string = mb_substr($origString, 0, $maxLength, 'utf-8');
    $maxLength--;
}

return $string;
}

////////////////////////////////////////////////////////////////////////////////

class API
{
// Because the payload only allows for 256 bytes and there is some overhead
// we limit the message text to 190 characters.
const MAX_MESSAGE_LENGTH = 190;

private $pdo;

function __construct($config)
{
    // Create a connection to the database.
    $this->pdo = new PDO(
        'mysql:host=' . $config['db']['host'] . ';dbname=' . $config['db']['dbname'], 
        $config['db']['username'], 
        $config['db']['password'],
        array());

    // If there is an error executing database queries, we want PDO to
    // throw an exception. Our exception handler will then exit the script
    // with a "500 Server Error" message.
    $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // We want the database to handle all strings as UTF-8.
    $this->pdo->query('SET NAMES utf8');
}

function handleCommand()
{

    // Figure out which command the client sent and let the corresponding
    // method handle it. If the command is unknown, then exit with an error
    // message.
    if (isset($_POST['cmd']))
    {
        switch (trim($_POST['cmd']))
        {
            case 'join': $this->handleJoin(); return;
            case 'leave': $this->handleLeave(); return;
            case 'update': $this->handleUpdate(); return;
            case 'message': $this->handleMessage(); return;
        }
    }

    exitWithHttpError(400, 'Unknown command');
}

// The "join" API command registers a user to receive notifications that
// are sent in a specific "chat room". Each chat room is identified by a
// secret code. All the users who register with the same secret code can
// see each other's messages.
//
// This command takes the following POST parameters:
//
// - user_Id:  A unique identifier. Must be a string of 40 hexadecimal characters.
// - token: The device's device token. Must be a string of 64 hexadecimal
//          characters, or "0" if no token is available yet.
// - name:  The nickname of the user. Must be a UTF-8 string of maximum 255
//          bytes. Only the first 20 bytes are actually shown in the push 
//          notifications.
// - code:  The secret code that identifies the chat room. Must be a UTF-8
//          string of maximum 255 bytes.
//


function handleJoin()
{
    //function getUserId;
    $userId = $this->getUserId();
    $token = $this->getDeviceToken(true);
    $name = $this->getString('name', 255);
    $code = $this->getString('code', 255);

    // When the client sends a "join" command, we add a new record to the
    // active_users table. We identify the client by the user_id that it
    // provides. When the client sends a "leave" command, we delete its
    // record from the active_users table.

    // It is theoretically possible that a client sends a "join" command
    // while its user_id is still present in active_users (because it did not
    // send a "leave" command). In that case, we simply remove the old
    // record first and then insert the new one.

    $this->pdo->beginTransaction();

    $stmt = $this->pdo->prepare('DELETE FROM active_users WHERE user_Id = ?');
    $stmt->execute(array($userId));

    $stmt = $this->pdo->prepare('INSERT INTO active_users (user_Id, device_token, nickname, secret_code, ip_address) VALUES (?, ?, ?, ?, ?)');
    $stmt->execute(array($userId, $token, $name, $code, $_SERVER['REMOTE_ADDR']));

    $this->pdo->commit();

}

// The "leave" API command removes a user from a chat room. That user will
// no longer receive push notifications for messages sent to that room.
//
// This command takes the following POST parameters:
//
// - user_id: A unique identifier. Must be a string of 40 hexadecimal characters.
//
function handleLeave()
{
    $userId = $this->getUserId();
    $stmt = $this->pdo->prepare('DELETE FROM active_users WHERE user_Id = ?');
    $stmt->execute(array($userId));
}

// The "update" API command gives a user a new device token.
//
// This command takes the following POST parameters:
//
// - user_id:  A unique identifier. Must be a string of 40 hexadecimal characters.
// - token: The device's device token. Must be a string of 64 hexadecimal
//          characters.
//
function handleUpdate()
{
    $userId = $this->getUserId();
    $token = $this->getDeviceToken(false);
    $stmt = $this->pdo->prepare('UPDATE active_users SET device_token = ? WHERE user_Id = ?');
    $stmt->execute(array($token, $userId));
}

// The "message" API command sends a message to all users who are registered
// with the same secret code as the sender of the message.
//
// This command takes the following POST parameters:
//
// - user_id: A unique identifier. Must be a string of 40 hexadecimal characters.
// - text: The message text. Must be a UTF-8 string of maximum 190 bytes.
//
function handleMessage()
{
    $userId = $this->getUserId();
    /*$text = $this->getString('text', self::MAX_MESSAGE_LENGTH, true);*/

    // First, we get the record for the sender of the message from the
    // active_users table. That gives us the nickname, device token, and
    // secret code for that user.

    $stmt = $this->pdo->prepare('SELECT * FROM active_users WHERE user_Id = ? LIMIT 1');
    $stmt->execute(array($userId));
    $user = $stmt->fetch(PDO::FETCH_OBJ);

    if ($user !== false)
    {
        // Put the sender's name and the message text into the JSON payload
        // for the push notification.
        $payload = $this->makePayload($user->nickname/*, $text*/);

        // Find the device tokens for all other users who are registered
        // for this secret code. We exclude the device token of the sender
        // of the message, so he will not get a push notification. We also
        // exclude users who have not submitted a valid device token yet.
        $stmt = $this->pdo->prepare("SELECT device_token FROM active_users WHERE secret_code = ? AND device_token <> ? AND device_token <> '0'");
        $stmt->execute(array($user->secret_code, $user->device_token));
        $tokens = $stmt->fetchAll(PDO::FETCH_COLUMN);

        // Send out a push notification to each of these devices.
        foreach ($tokens as $token)
        {
            $this->addPushNotification($token, $payload);
        }
    }
}

// Retrieves the user identifier from the POST data. If the user_id does not
// appear to be valid, the script exits with an error message.
function getUserId()
{   
    if (!isset($_POST['user_id']))
        exitWithHttpError(400, 'Missing user_id');

    $userId = trim(urldecode($_POST['user_id']));
    if (!$this->isValidUserId($userId))
        exitWithHttpError(400, 'Invalid user_id');

    return $userId;
}

// Checks whether the format of the user identifier is correct (40 hex
// characters or 32 for the simulator).
function isValidUserId($userId)
{
    if (strlen($userId) != 40 && strlen($userId) != 32)  // 32 for simulator
        return false;

    if (preg_match("/^[0-9a-fA-F]+$/", $userId) == 0)
        return false;

    return true;
}

// Retrieves the device token from the POST data. If the token does not
// appear to be valid, the script exits with an error message.
function getDeviceToken($mayBeEmpty = false)
{
    if (!isset($_POST['token']))
        exitWithHttpError(400, 'Missing device token');

    $token = trim($_POST['token']);

    // The "join" command allows a token value of "0" to be specified,
    // which is necessary in case the client did not yet obtain a device
    // token at that point. We allow such clients to join, but they will
    // not receive any notifications until they provide a valid token
    // using the "update" command.
    if ($mayBeEmpty && $token == "0")
        return $token;

    if (!$this->isValidDeviceToken($token))
        exitWithHttpError(400, 'Invalid device token');

    return $token; 

}

// Checks whether the format of the device token is correct (64 hexadecimal
// characters). Note: we have no means to verify whether the device token
// was really issued by APNS and corresponds to an actual device.
function isValidDeviceToken($deviceToken)
{
    if (strlen($deviceToken) != 64)
        return false;

    if (preg_match("/^[0-9a-fA-F]{64}$/", $deviceToken) == 0)
        return false;

    return true;
}

// Looks in the POST data for a field with the given name. If the field
// is not a valid UTF-8 string, or it is too long, the script exits with
// an error message.
function getString($name, $maxLength, $allowNewlines = false)
{
    if (!isset($_POST[$name]))
        exitWithHttpError(400, "Missing $name");

    $string = trim($_POST[$name]);
    if (!isValidUtf8String($string, $maxLength, $allowNewlines))
        exitWithHttpError(400, "Invalid $name");

    return $string;
}

// Creates the JSON payload for the push notification message. The "alert"
// text has the following format: "sender_name: message_text". Recipients
// can obtain the name of the sender by parsing the alert text up to the
// first colon followed by a space.
function makePayload($senderName, $text)
{
    // Convert the nickname of the sender to JSON and truncate to a maximum
    // length of 20 bytes (which may be less than 20 characters).
    $nameJson = $this->jsonEncode($senderName);
    $nameJson = truncateUtf8($nameJson, 20);

    // Convert and truncate the message text
    $textJson = $this->jsonEncode($text);
    $textJson = truncateUtf8($textJson, self::MAX_MESSAGE_LENGTH);

    // Combine everything into a JSON string
    $payload = '{"aps":{"alert":"' . $nameJson . ': ' . $textJson . '","sound":"beep.caf"}}';
    return $payload;
}

// We don't use PHP's built-in json_encode() function because it converts
// UTF-8 characters to \uxxxx. That eats up 6 characters in the payload for
// no good reason, as JSON already supports UTF-8 just fine.
function jsonEncode($text)
{
    static $from = array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"');
    static $to = array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"');
    return str_replace($from, $to, $text);
}

// Adds a push notification to the push queue. The notification will not
// be sent immediately. The server runs a separate script, push.php, which 
// periodically checks for new entries in this database table and sends
// them to the APNS servers.
function addPushNotification($deviceToken, $payload)
{
    // Payloads have a maximum size of 256 bytes. If the payload is too
    // large (which shouldn't happen), we won't send this notification.
    if (strlen($payload) <= 256)
    {
        $stmt = $this->pdo->prepare('INSERT INTO push_queue (device_token, payload, time_queued) VALUES (?, ?, NOW())');
        $stmt->execute(array($deviceToken, $payload));
    }

}
}


?>

None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在此 API 中声明全局变量? 的相关文章

  • Apache 网络服务器启动时出现错误[关闭]

    这个问题不太可能对任何未来的访客有帮助 它只与一个较小的地理区域 一个特定的时间点或一个非常狭窄的情况相关 通常不适用于全世界的互联网受众 为了帮助使这个问题更广泛地适用 访问帮助中心 help reopen questions 我刚刚切换
  • Laravel 5.1 中的VerifyCsrfToken.php 第 53 行:(Firefox 浏览器)中出现 TokenMismatchException?

    我试图找出为什么会出现这个错误 即使它是全新安装的 我在我的项目中遇到了这个错误 所以我用谷歌搜索 没有一个答案对我有用 所以我创建了新项目并复制了所有控制器 视图和模型 几个小时后工作正常 再次出现令牌不匹配错误 为什么在 laravel
  • 在会话 cookie 中存储大量数据会产生什么影响?

    谁能解释一下在会话中存储大量数据的缺点或给我指出一些阅读材料 我也很感兴趣在会话中存储数据和从数据文件读取数据之间是否有任何区别 如果您在会话中存储大量数据 则输入 输出性能会下降 因为会有大量读取 写入 默认情况下 PHP 中的会话存储在
  • 如何在MAMP中设置环境变量?

    如何在 MAMP 版本 3 3 中设置环境变量 我可以在我的 PHP 应用程序中使用它 我已经更新了 Applications MAMP Library bin envvars and envvars std file并添加以下行 Lice
  • session_regenerate_id 没有创建新的会话 id

    我有一个脚本 旨在完成当前会话并开始新的会话 我使用了一段代码 它在我的开发计算机上运行良好 但是 当我将其发布到生产服务器时 会话 ID 始终保持不变 以下是我重新启动会话的代码 session start SESSION array P
  • Symfony2中如何获取所有post参数? [复制]

    这个问题在这里已经有答案了 我想获取a的所有post参数symfony http symfony com Form I used all parameter this gt get request gt getParameterHolder
  • php 如何统计文件夹中的文件数量?

    我想让用户能够在自己的文件夹中上传一些文件 图片 但只有当该文件夹包含的图片少于五张时才可能 如果已经有 5 张图片 脚本必须让用户知道他 她的文件夹已满 所以 我想知道php中是否有函数可以计算文件夹中的文件数量 或者 php 中有其他方
  • php 中的简单授权/登录功能

    我希望第一次实现用户登录到我的网站 我很高兴构建自己的解决方案 或者实现一些开源的东西 但是到目前为止 在我的搜索中没有任何包是明显的选择 同样 我完全意识到 作为一名中级 php 程序员 如果我推出自己的解决方案 并真正敞开大门 我很可能
  • 如何以编程方式获取 WooCommerce 中的所有产品?

    我想获取 WooCommerce 中的所有产品数据 产品 sku 名称 价格 库存数量 可用性等 我可以使用 wp query 来做到这一点吗 这样你就可以通过 wp query 获取所有产品 global wpdb all product
  • 使用 PHP 的 Google Glass GDK 身份验证

    我正在尝试点击此链接来验证 GDK 中的用户 https developers google com glass develop gdk authentication https developers google com glass de
  • AWS S3 上传的图像已损坏

    我正在 AWS ec2 ubuntu 机器上工作 我的代码在 cakephp 中 当我尝试将任何图像上传到 AWS S3 时 它都会损坏 虽然它在核心 php 代码中运行良好 这是我的控制器代码 if this gt User gt sav
  • PHP7构造函数类名

    我有一个 Laravel 4 2 应用程序 它可以与 PHP5 一起使用 没有任何问题 由于我安装了一个运行 PHP7 的新 vagrant box 一旦我运行一个模型 其中函数名称与类名称 关系函数 相同 就会出现错误 如下所示
  • Android GCM 服务器的 API 密钥

    我有点困惑我应该为 GCM 服务器使用哪个 API 密钥 在文档中它说使用 android api 密钥 这对我不起作用并且总是给出未经授权的 http developer android com google gcm gs html ht
  • 如何编写在正文中包含锚标记的 Zend Framework URL?

    使用 Zend Framework 中设置的标准 MVC 我希望能够显示始终具有锚点的页面 现在我只是在 phtml 文件中添加一个带有 anchor 的无意义参数
  • 如何在 HTML / Javascript 页面中插入 PHP 下拉列表

    好吧 这是我的第二篇文章 请接受我是一个完全的新手 愿意学习 花了很多时间在各个网站上寻找答案 而且我几乎已经到达了我需要到达的地方 至少在这一点上 我有一个网页 其中有许多 javascript 函数 这些函数一起使用 google 地图
  • Azure 上的“phpcomposer.phar install”出现“无法终止进程”错误

    我正在尝试将我的 Symfony 2 应用程序部署到 Microsoft Azure 网站云 为此 我按照本指南中的步骤操作http symfony com doc current cookbook deployment azure web
  • 将数组拆分为特定数量的块

    我知道array chunk 允许将数组拆分为多个块 但块的数量根据元素的数量而变化 我需要的是始终将数组拆分为特定数量的数组 例如 4 个数组 以下代码将数组分为 3 个块 两个块各有 2 个元素 1 个块有 1 个元素 我想要的是将数组
  • 如何在html中制作多行类型的文本框?

  • mysqli bind_param 中的 NULL 是什么类型?

    我正在尝试将参数绑定到 INSERT INTO MySQLi 准备好的语句 如果该变量存在 否则插入 null 然后我知道 type variable i corresponding variable has type integer d
  • PHP 和 NLP:嵌套括号(解析器输出)到数组?

    想要将带有嵌套括号的文本转换为嵌套数组 以下是 NLP 解析器的输出示例 TOP S NP PRP I VP VBP love NP NP DT a JJ big NN bed PP IN of NP NNS roses 原文 我喜欢一大床

随机推荐

  • 有没有办法在 Visual Studio 或 MATLAB 中“映射”程序执行顺序?

    我所说的 地图 是指我有一个 主 函数 它调用内部的许多其他程序 我希望能够看到哪个文件首先运行 第二个 第三个等等 基本上 我希望能够请参阅这个大型 OOP 设计程序 创建者没有为其制作 UML 类图 中的依赖项列表和顺序 以帮助破译代码
  • 带 Retrofit 的 JSON 解析

    我最近开始使用Retrofit 我对此了解不多 我用谷歌搜索了这个问题 但没有答案适合我的问题 这是 JSON 响应 results description eng This is second time testing img url t
  • 窗口的打开事件和窗口句柄

    如何从刚刚打开的 Outlook 窗口获取窗口句柄 IntPtr OutLook Items items oFolder Items foreach OutLook MailItem mail in items mail Display I
  • TailwindCSS / PurgeCSS 提取器字符串删除一些类

    对于 Tailwind 和 PostCSS PurgeCSS 来说相当新 所以希望这是一个相当简单的修复 In my tailwind config js 我扩展了一些间距值 包括添加 0 5 值以与默认的 Tailwind 间距比例对齐
  • docker asp.net core 容器在 mysql 容器之后启动

    我有一个带有 asp net core 的 docker 容器和一个带有 mysql 的容器 现在我需要等待 mysql 容器启动并准备好 两个容器都通过 docker compose yml 启动 就像是https github com
  • VSS 的有效绑定根?

    我正在尝试修复我拥有的项目的视觉源安全绑定 当我选择我认为项目应该绑定到的位置时 我会收到一个对话框 其中显示 The folder you chose is not a valid binding root for the project
  • 如何防止文件被直接 URL 访问?

    我正在使用 Apache 并且我的目录中有一个示例 Web 文件夹本地主机 喜欢 http localhost test 文件位于test文件夹 index html sample jpg htaccess 样本来源index html i
  • Angular2 选择 ngValue null

    这就是我想要做的 我想要一个选择列表绑定到具有 ngValue 的对象数组 但第一个选项需要是带有null value Model this managers id null name None id 1 name Jeffrey id 2
  • div 中的内部 html 更改时触发事件

    I have div对于一些信息 填写为 innerHTML单击按钮 目标是我想要 slideDown添加 div 中的文本时的 div 可以用 jQuery 来实现吗 Example div div 将文本添加到 div document
  • Android 表单验证 UI 库

    有iOSUS2表单验证器 https github com ustwo US2FormValidator用于用户输入验证的库 见下图 我认为该库比默认情况下在某些内容未验证时弹出警报更好 我正在寻找如何在 Android 上做这样的事情 有
  • 保护登录和评论表单免受 CSRF 攻击

    我读过很多关于CSRF保护的文章 这个不错 http seclab stanford edu websec csrf csrf pdf 以及关于SO的各种问题 但它们似乎都没有足够的信息来回答我的问题 我正在开发自己的 CMS 我想保护我的
  • 如何检查节点中的req.body是否为空,express?

    下面是我的请求正文 它是从客户端发送的 var credentials ConsumerData ConsumerStoreId a ConsumerUserId a CustomerData CustomerId 2345678890 E
  • ASP.NET 服务器端或客户端的验证控件?

    ASP NET 中的验证控件在服务器端和客户端都有效吗 或者它仅用于客户端验证 Thanks ASP NET 验证控件执行这两项操作client side and server side验证 EnableClientValidation是财
  • 使用 Jinja2 模板在 HTML 文本区域中显示 FastAPI 响应(元组)

    这是我的 FastAPI 后端 main py from typing import Optional from fastapi import FastAPI Request Form from fastapi templating imp
  • 国际天气 API (PHP) [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我正在寻找最好的 免费 便宜 国际天气 PHP API 有什么建议么 看看这个答案 https sta
  • 在 C++ 中将 unix 时间戳转换为星期几?

    如何根据任意 Unix 时间戳 秒 确定加利福尼亚州的星期几 太平洋时间 我四处搜寻 但没有找到 C 的内置库 UTC 通常比 PT 早 8 小时 但只需从 Unix 时间戳中减去 8 小时并创建一个tmstruct 不起作用 因为这会折扣
  • 未处理的拒绝(ChunkLoadError):加载块 1 失败

    我基本上想做一个poc将我的主应用程序的某些部分提取到一个单独的包中 我已在我的 git 存储库中构建了一个示例单独包myapp poc ui https github com prabhatmishra33 myapp poc ui 现在
  • 将自行车分配给人员 - 第一优先级(距离最近的人最近的自行车)

    将网格传递给某个位置有自行车和人员的函数 c A a b D d B C Output 像这样的东西 A 1 B 3 C 8 D 1 其中 A 是人 1 是到达自行车所需的步数 标准 距离自行车最近的人 优先获得自行车 单辆自行车不能分配给
  • 如何让 gcc/clang 警告 switch 语句中缺少中断

    有什么办法可以使gcc or clang警告 switch 语句中缺少中断 具体来说 我几乎总是希望 case 语句以中断结束 如果我不这样做的话 如果我能让编译器抱怨 那就太好了 如果它会寻找一个break语句或一个 fall throu
  • 如何在此 API 中声明全局变量?

    我的应用程序有一个production or development我可以切换的设置 设置服务器时 我在中设置了这个标志Applications gt Mamp gt Conf gt Apache gt httpd conf 它的目的是给我