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. Quote 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 Quote 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. Quote 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. Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/85823-simple/#findComment-438055 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.