Jump to content

Php if require function fails then display custom error message


Flames

Recommended Posts

the title is pretty much the question.

let me show you an example

<?php
$array = array(1, 2, 3);
$module = $_GET['module'];
if(in_array($module, $array))
{
require_once("module/" . $module . ".php");
}
?>

so if i put page.php?module=1 it will load module/1.php

but what if i put module=2 and the page doesnt exist i get a horrible message from the webhost, so what i want to do is make it say Required module was not found. i tried using or die("message") but i just got an error.

 

note: the code might not be 100% right i just wrote it in about 20 seconds.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.