【问题标题】:Where to hide PHP to prevent email from triggering在哪里隐藏 PHP 以防止电子邮件触发
【发布时间】:2018-08-26 05:15:45
【问题描述】:

我目前正在使用 Twilio 进行 SMS 到电子邮件的集成。

Twilio 提供的代码需要位于公共 URL 上才能使集成工作。没有理由任何人都需要访问此 URL。

不幸的是,位于公共 URL 上的代码意味着随机网络爬虫可以并且确实加载它所在的页面,这会触发发送空白电子邮件。至少我认为这是在做什么?

我无法使用 if...else 来查看是否有任何字段为空,因为集成会自动发送诸如“正文”和“消息”之类的样板标签(因此,这些字段永远不会为空)。

所以,我想知道我的文件结构中是否有某个地方可以隐藏此 PHP,以便集成可以正常工作,但不会对 URL 进行随机 ping 操作。

编辑:这个 php 当前作为我的 index.php 文件存在于 /usr/share/nginx/html 文件夹中。我不是很有经验,我花了很多时间尝试找到一个地方把它放在它实际成功运行的地方......

【问题讨论】:

  • 如果您将名称 index.php 更改为 7eead553-5a1d-4797-9234-a7eda26369bb.php - 会起作用吗?
  • 使用 robots.txt ?
  • 感谢您的建议。重命名它会破坏集成(不知道为什么)。我添加了一个 robots.txt 文件,但我想我必须看看它在接下来的 24 小时内是否有效。显然,当我手动重新加载页面时,电子邮件仍然会触发。

标签: php email twilio integration


【解决方案1】:

这里是 Twilio 开发者宣传员。

这里有几个选项。

您可以add HTTP basic authentication to your server。然后,更改您的 Twilio 号码的 webhook URL 以在 URL 中包含用户名和密码。喜欢:

https://username:password@example.com/index.php

或者,您可以在您的代码中使用validate that the request came from Twilio 标头X-Twilio-Signature。这看起来有点像这样:

<?php
// NOTE: This example uses the next generation Twilio helper library - for more
require_once '/path/to/vendor/autoload.php';

use Twilio\Security\RequestValidator;

// Your auth token from twilio.com/console
$token = "YOUR_AUTH_TOKEN";

$signature = $_SERVER["HTTP_X_TWILIO_SIGNATURE"];

$validator = new RequestValidator($token);

$url = $_SERVER['SCRIPT_URI'];
$postVars = $_POST

if ($validator->validate($signature, $url, $postVars)) {
  // This is from Twilio!
  // The rest of your code to send the email goes here.
} else {
  // This is not from Twilio. Return a 403 response
  header('HTTP/1.1 403 Forbidden');
  exit;
}

你可以阅读更多关于securing your webhook endpoints in the Twilio documentation的信息。

【讨论】:

    【解决方案2】:

    如果可能,您应该将文件存储在 webroot 之外。

    否则……

    使用 .htaccess 访问deny from all

    【讨论】:

    • 据我了解,要通过公共 URL 访问 php,它需要存在于 webroot 中,这可以解释为什么当我将它放在外面时它并不能真正工作。你能详细说明我将如何使用 .htaccess 吗?似乎我需要一个特定的 IP 才能允许,我认为我需要从 Twilio 获得?
    • 查看 philnash 的回答
    猜你喜欢
    • 2011-09-29
    • 1970-01-01
    • 2016-01-21
    • 2018-10-06
    • 2013-08-28
    • 2012-06-19
    • 1970-01-01
    • 2011-10-10
    • 2020-12-01
    相关资源
    最近更新 更多