LoggedIn Posted January 13, 2008 Share Posted January 13, 2008 Hey, I need the code that will check if a file called file.php is in there if its not it will redirect to file2.php without loading the rest of the page? Thanks. Link to comment https://forums.phpfreaks.com/topic/85823-simple/ Share on other sites More sharing options...
joecooper Posted January 13, 2008 Share Posted January 13, 2008 <?php $filename = 'file.php'; //file to check if it excists if (file_exists($filename)) { //check if it excists echo "The file $filename exists"; // return echo that its there... replace this with the code for the page etc... } else { //if it doesnt excist header("Location: file2.php");//redirect to another page die(); //dont load anything else from this page } ?> i beleieve this would work Link to comment https://forums.phpfreaks.com/topic/85823-simple/#findComment-438002 Share on other sites More sharing options...
Fyorl Posted January 13, 2008 Share Posted January 13, 2008 <?php $fname = 'file.php'; if(!file_exists($fname)) { header("Location: file2.php"); exit; } ?> Edit: Sorry, joecooper's should work just as well but I didn't see his updated code before I posted. Link to comment https://forums.phpfreaks.com/topic/85823-simple/#findComment-438003 Share on other sites More sharing options...
LoggedIn Posted January 13, 2008 Author Share Posted January 13, 2008 Would it be safe to remove the echo to say its there. Link to comment https://forums.phpfreaks.com/topic/85823-simple/#findComment-438052 Share on other sites More sharing options...
nikefido Posted January 13, 2008 Share Posted January 13, 2008 Would it be safe to remove the echo to say its there. It's "safe" in that it won't break your code, however it is the main way (right now) for you to know if the file exists or not. Link to comment https://forums.phpfreaks.com/topic/85823-simple/#findComment-438055 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.