orbitalnets Posted March 11, 2008 Share Posted March 11, 2008 Hi All, I have made a super basic PHP wesite with all just php includes. Noting fancy. http://orbitalnets.com/previews/masseerme/index.php?page=default I have also made a index.php files that handles the url and 404 not found page. This is the contents of the index.php file: <?php function get_include_contents($filename) { if (is_file($filename)) { ob_start(); include $filename; $contents = ob_get_contents(); ob_end_clean(); return $contents; } return false; } $errormsg = get_include_contents('404.php'); $pagename = $_GET['page']; $extension = "php"; if(file_exists("$pagename.$extension")) { include "$pagename.$extension"; } elseif($pagename=="") { include "default.$extension"; } else { echo "$errormsg"; } ?> This is working just fine. But I notice a PHP error in the server log: [Tue Mar 11 09:18:56 2008] [error] [client 82.95.50.149] PHP Notice: Undefined index: page in /usr/local/apache2/htdocs/previews/masseerme/index.php on line 15, referer: http://orbitalnets.com/previews/ Line 15 seems to be: $pagename = $_GET['page']; Other than the fact that this is working should I worry about this? How can I code this better? of correct? I feel that this is not the correct way to do this. Please let me know. Regards, Dwayne Quote Link to comment https://forums.phpfreaks.com/topic/95609-404-php-help/ Share on other sites More sharing options...
sasa Posted March 11, 2008 Share Posted March 11, 2008 change $pagename = $_GET['page']; to if(isset($_GET['page']))$pagename = $_GET['page']; else $pagename = ""; Quote Link to comment https://forums.phpfreaks.com/topic/95609-404-php-help/#findComment-489453 Share on other sites More sharing options...
uniflare Posted March 11, 2008 Share Posted March 11, 2008 for development purposes i tend to use E_ALL for error_reportnig in php.ini, alternatively you can do either at the start of you script: ini_set("error_reporting","E_ALL"); OR error_reporting("E_ALL"); hope this helps, Quote Link to comment https://forums.phpfreaks.com/topic/95609-404-php-help/#findComment-489462 Share on other sites More sharing options...
orbitalnets Posted March 11, 2008 Author Share Posted March 11, 2008 Thanks. now the error in the log does not appear.. i guest just me php coding.. thx.. d Quote Link to comment https://forums.phpfreaks.com/topic/95609-404-php-help/#findComment-489471 Share on other sites More sharing options...
sasa Posted March 11, 2008 Share Posted March 11, 2008 you did NOT have error just notice Quote Link to comment https://forums.phpfreaks.com/topic/95609-404-php-help/#findComment-489478 Share on other sites More sharing options...
orbitalnets Posted March 11, 2008 Author Share Posted March 11, 2008 Ok now I see there si 2 diferent scenarios for 404 page. 1. http://orbitalnets.com/previews/masseerme/dfghdgh and 2. http://orbitalnets.com/previews/masseerme/index.php?page=dfghdgh The option number 2 shows the 404 page. But option number 1 shows just the text 404.php in de body. For the option number one should I refer to the .htaccess file or could this be done also with php? Let me know. Regards, Dwayne Quote Link to comment https://forums.phpfreaks.com/topic/95609-404-php-help/#findComment-489480 Share on other sites More sharing options...
uniflare Posted March 11, 2008 Share Posted March 11, 2008 you would either need htaccess or a better option would be to edit the apache httpd.conf file and change the error pages in there... (no one like htacess/htpasswd stuff anymore - even apache website says its not reccommended to use ht files) Quote Link to comment https://forums.phpfreaks.com/topic/95609-404-php-help/#findComment-489487 Share on other sites More sharing options...
orbitalnets Posted March 11, 2008 Author Share Posted March 11, 2008 Ok. I expected the default internet explorer not found page rather than the text 404.php in the browser when typing a wrong url like this: http://orbitalnets.com/previews/masseerme/dfghdgh instead of this http://orbitalnets.com/previews/masseerme/index.php=dfghdgh Thanks I will refer the httpd.conf. Regards, Dwayne Quote Link to comment https://forums.phpfreaks.com/topic/95609-404-php-help/#findComment-489493 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.