Php Help - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Php Help (/showthread.php?tid=37313)
Php Help by Stigmata on 01-22-2005 at 10:18 AM
well its for a tutorial section. each tutorial is a txt file in a far far away folder.
first someone will will choose a language, and then they select a page/tutorial.
i have this so far
code: <?php
$page = htmlentities($_GET['page']) ;
$language = htmlentities($_GET['lan']) ;
if (!isset($_GET['page'])) {
if(!isset($_GET['lan'])) {
include ("pages/code/home.txt");
}
else {
include ("pages/code/$language.txt");
}
}
else {
include("pages/code/$language/$page.txt");
}
?>
now i want to create a sorta error page, if the file cannot be found, then it echos "page cannot be found"
thanks for the help
RE: Php Help by -dt- on 01-22-2005 at 10:25 AM
you just use file_exists
http://au.php.net/manual/en/function.file-exists.php
so you could use
code: $file = "path to file here";
if (!file_exists($file)) {
die("page can not be found");
}
just put it before anything echo's in your code and when the file can not be found it will echo "page can not be found" then kill the script
so in your script it would be something like
code:
<?php
$page = htmlentities($_GET['page']) ;
$language = htmlentities($_GET['lan']) ;
if (!isset($_GET['page'])) {
if(!isset($_GET['lan'])) {
include ("pages/code/home.txt");
}
else {
$file = "pages/code/$language.txt";
if (!file_exists($file)) { die("page can not be found");}
include ("$file");
}
}
else {
$file = "pages/code/$language/$page.txt";
if (!file_exists($file)) { die("page can not be found");}
include ("$file");
}
?>
[/code]
RE: Php Help by Stigmata on 01-22-2005 at 10:31 AM
thnx works like a charm
RE: Php Help by -dt- on 01-22-2005 at 10:33 AM
quote: Originally posted by Stigmata
thnx works like a charm
lol i just updated my post to apply to your code and you just posted that damm u
RE: Php Help by Stigmata on 01-22-2005 at 10:37 AM
blah, i dont want it to die, because it wont load the rest of my page
this is what i did
code: <?php
$page = htmlentities($_GET['page']) ;
$language = htmlentities($_GET['lan']) ;
if (!isset($_GET['page'])) {
if(!isset($_GET['lan'])) {
include ("pages/code/home.txt");
}
else {
$filename2 = '/pages/code/$language.txt';
if (file_exists($filename2)) {
include("/pages/code/$language.txt");
} else {
echo "Sorry, The Page Cannot Be Found";
}
}
}
else {
$filename = "pages/code/$language/$page.txt";
if (file_exists($filename)) {
include("pages/code/$language/$page.txt");
} else {
echo "Sorry, The Page Cannot Be Found";
}
}
?>
|