简体   繁体   English

是否可以在 php 文档上输出某些内容,并且仅当它的 URL 在 MySQL 数据库中的值为 true 时才使其死亡?

[英]Is it possible to output certain content on a php document and make it die only if it’s URL is present with a value of true on a MySQL database?

I am trying to setup a PHP document but I currently am looking for a way to use the die() function and display some content on every page using my global configuration file.我正在尝试设置一个 PHP 文档,但我目前正在寻找一种使用die()函数并使用我的全局配置文件在每个页面上显示一些内容的方法。 The way I am think how it should work is that IF the requested URL (eg domain.com/services/disabledservice) would have /services/disabled service and a value of 1 to make the value true in a MYSQL DB.我认为它应该如何工作的方式是,如果请求的 URL(例如 domain.com/services/disabledservice)将具有/services/disabled service并且值为1以使该值在 MYSQL DB 中为真。

The plan is to have the URL be collected and checked with a table than if the row has a value of 1 for status it will display a disabled page message but if it's 0 it will load normally.计划是收集 URL 并使用表格检查 URL,如果该行的状态值为 1,它将显示禁用页面消息,但如果为 0,它将正常加载。

Some research I have conducted may lead be to think that using the SQL query and the if function could work for this.我进行的一些研究可能会导致认为使用 SQL 查询和 if 函数可以解决这个问题。

The idea I have is this but it may not be correct.我的想法是这样,但它可能不正确。

<?php $pageurl = [requested URL content here]
$checkstatus = "SELECT * FROM servicestatus WHERE page =" . $pageurl . "AND status = 1";
if ($status = mysqli_query($conn, $servicestatus)) {
    if (mysqli_num_rows($status) = 1) { ?> html content here
    <?php }
} else { ?>
    page as normal
<?php } ?>

Edit:编辑:

To explain what I am trying to do.. I am trying to fetch the URL without everything past “?”为了解释我想要做什么..我试图在没有所有内容的情况下获取URL“?” Than I am trying to use that in a DB query to check with the database if that has a value of “m” or “d” and if it has one of those values next to the URL which is being fetched it will display the appropriate error page.比我试图在数据库查询中使用它来检查数据库是否具有“m”或“d”的值,并且如果它在正在获取的 URL 旁边具有这些值之一,它将显示适当的错误页面。 This is being included as part of my core configuration file which includes my “$conn” and the core values for most stuff.这被包含在我的核心配置文件中,其中包括我的“$conn”和大多数东西的核心值。 The problem I am facing is that when I send my URL without everything past the “?”我面临的问题是,当我发送 URL 时,所有内容都没有超过“?” I am not receiving my error page and everything is loading like normal.我没有收到我的错误页面,一切都正常加载。

Use any one the following php functions:使用以下任一 php 函数:

include 'path_to_the_page.php' (or) require 'path_to_the_page.php';

The difference between include and require arises when the file being included cannot be found: include will emit a warning ( E_WARNING ) and the script will continue, whereas require will emit a fatal error ( E_COMPILE_ERROR ) and halt the script.当无法找到被包含的文件时,include 和 require 之间的区别就出现了:include 将发出警告 ( E_WARNING ) 并且脚本将继续,而 require 将发出致命错误 ( E_COMPILE_ERROR ) 并停止脚本。

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

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