Is there anything wrong with this code?
Posted: Wed Sep 08, 2004 9:27 pm
Hello,
I used this code to navigate in the site I'm working on..
The code is working but now we are informed by the host that our site is using too much resources in the bin/php. we are suspecting the code to be the source of problem but I don't know whats wrong since I'm a programmer but I just started to learn what I need in php..
if you can have a look at this code and guide me if there is a proplem with it or if it's ok .. I'll appreciate that
the variables:
subject: the name of the page without the extension.. except for the news.
section: the name of the folder
subsection: the name of the subfolder
file: to store the relative path of the file
and I use main.php as the main page in each folder..
and to sum the code in readable way:
If the (subject) is not passed through the url then
---- (subject) = main
if (section) then
---- if it is the news section then
--------- file= news/(subject)
---- else
--------- if (subsection) then
-------------- file= (section)/(subsection)/(supject).php
--------- else
-------------- file= (section)/(supject).php
else
---- file=(subject).php
if the file exist then
---- include the file
else
---- print the error message
I may mention also that the site is popular that it get 1000+ click/day. but we are told by the host that the site is getting 100 hit/second that it made the load in the server and they are also gave a hint that this code maybe the source of the problem..
Thanks,
zas
I used this code to navigate in the site I'm working on..
The code is working but now we are informed by the host that our site is using too much resources in the bin/php. we are suspecting the code to be the source of problem but I don't know whats wrong since I'm a programmer but I just started to learn what I need in php..
if you can have a look at this code and guide me if there is a proplem with it or if it's ok .. I'll appreciate that
Code: Select all
<?php
if(! $_GET['subject']){
$subject='main';}
if ($_GET['section']){
if ($section=='news'){
$file=$section."/".$subject;}
else{
if ($_GET['subsection']){
$file=$section."/".$subsection."/".$subject.$_GET['page'].".php";}
else{
$file=$section."/".$subject.$_GET['page'].".php";}
} }
else{
$file=$subject.$_GET['page'].".php";}
if (file_exists($file)){
include($file);}
else{
echo "Unable to find the requested page." ;}
?>subject: the name of the page without the extension.. except for the news.
section: the name of the folder
subsection: the name of the subfolder
file: to store the relative path of the file
and I use main.php as the main page in each folder..
and to sum the code in readable way:
If the (subject) is not passed through the url then
---- (subject) = main
if (section) then
---- if it is the news section then
--------- file= news/(subject)
---- else
--------- if (subsection) then
-------------- file= (section)/(subsection)/(supject).php
--------- else
-------------- file= (section)/(supject).php
else
---- file=(subject).php
if the file exist then
---- include the file
else
---- print the error message
I may mention also that the site is popular that it get 1000+ click/day. but we are told by the host that the site is getting 100 hit/second that it made the load in the server and they are also gave a hint that this code maybe the source of the problem..
Thanks,
zas