-1

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. The way I am think how it should work is that IF the requested URL (e.g. domain.com/services/disabledservice) would have /services/disabled service and a value of 1 to make the value true in a 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.

Some research I have conducted may lead be to think that using the SQL query and the if function could work for this.

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 “?” 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. This is being included as part of my core configuration file which includes my “$conn” and the core values for most stuff. The problem I am facing is that when I send my URL without everything past the “?” I am not receiving my error page and everything is loading like normal.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Kai
  • 1
  • 3
  • Your $conn is not defined, firstly you should connect to mysql and then execute your query. The code seems to be working. – Viswanath Polaki Jul 30 '19 at 05:08
  • My connection is defined in my thing I just don’t know how I would execute my idea like getting the url to place in the query – Kai Jul 30 '19 at 05:17
  • So your real question is actually just “how do i get the current page URL in PHP”? If so: – misorude Jul 30 '19 at 06:38
  • Possible duplicate of [Get the full URL in PHP](https://stackoverflow.com/questions/6768793/get-the-full-url-in-php) – misorude Jul 30 '19 at 06:38

1 Answers1

0

Use any one the following php functions:

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.

Akeel ahamed
  • 877
  • 11
  • 11
  • This doesn’t really help me in any way.... nor does it have any relation to the question other than I am using require to link my header, navbar and configuration files up... – Kai Jul 31 '19 at 05:40