prime Posted August 31, 2007 Share Posted August 31, 2007 I am including a php script I've written for every page. I don't need to include it here as its just a script to basically set site modes for maintenance and passwords and such, no big deal. but I seem to have run into a very very simple problem, which for the life of me I cant seem to work out. I want to have an "or die" function on an include like thus: <?php $local_pass = "off"; //not active yet $local_mode = "open"; @include("mscript.php") or die("unable to access MScript"); ?> But for some weird reason I cant seem to get this or die working on an include, is there something real basic here I'm missing? Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/ Share on other sites More sharing options...
phpSensei Posted August 31, 2007 Share Posted August 31, 2007 You need an if/else condition... Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338270 Share on other sites More sharing options...
prime Posted August 31, 2007 Author Share Posted August 31, 2007 I basically just want the page to die though if it cant access that file. And I'm not sure how to check if its accessible via an include Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338275 Share on other sites More sharing options...
Ken2k7 Posted August 31, 2007 Share Posted August 31, 2007 What do you mean if it can't access that file? It won't mess up a code. Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338278 Share on other sites More sharing options...
prime Posted August 31, 2007 Author Share Posted August 31, 2007 I know. But I am running it on a page that I don't want displayed at all if it cant include the file Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338282 Share on other sites More sharing options...
Jessica Posted August 31, 2007 Share Posted August 31, 2007 use require instead of include Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338285 Share on other sites More sharing options...
TutorMe Posted August 31, 2007 Share Posted August 31, 2007 The folloing code is completely untested, and coming from a noob, but try something like: <?php $success = @include("mscript.php"); if (!$success) { die('unable to access MScript') } $local_pass = "off"; //not active yet $local_mode = "open"; @include("mscript.php") ?> Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338286 Share on other sites More sharing options...
phpSensei Posted August 31, 2007 Share Posted August 31, 2007 The folloing code is completely untested, and coming from a noob, but try something like: <?php $success = @include("mscript.php"); if (!$success) { die('unable to access MScript') } $local_pass = "off"; //not active yet $local_mode = "open"; @include("mscript.php") ?> there you see, if statement. Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338288 Share on other sites More sharing options...
Fadion Posted August 31, 2007 Share Posted August 31, 2007 $success = @include("mscript.php") or die('Unable to access MScript'); //code Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338296 Share on other sites More sharing options...
prime Posted August 31, 2007 Author Share Posted August 31, 2007 None of thats working still :-( Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338303 Share on other sites More sharing options...
darkfreaks Posted August 31, 2007 Share Posted August 31, 2007 <?php $success = @require("mscript.php"); if (!$success) { die('unable to access MScript') } $local_pass = "off"; //not active yet $local_mode = "open"; @require("mscript.php") ?> Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338306 Share on other sites More sharing options...
Jessica Posted August 31, 2007 Share Posted August 31, 2007 Uhm...require? Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338307 Share on other sites More sharing options...
prime Posted August 31, 2007 Author Share Posted August 31, 2007 a straight require works good and gives a blank screen if it doesn't work. But I am also after a gracefull degrade message and that if statment just isn't working it's giving: Parse error: syntax error, unexpected '}' in /home/content/m/e/t/metaconcert/html/primefalcon/index.php on line 12 Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338310 Share on other sites More sharing options...
Fadion Posted August 31, 2007 Share Posted August 31, 2007 ok try echoing a succesfully included file: echo include 'myfile.php'; //ex it echoes '1' then: if((include 'myfile.php') != '1'){ die('Didnt load'); } //code Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338312 Share on other sites More sharing options...
darkfreaks Posted August 31, 2007 Share Posted August 31, 2007 what is line 12? Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338313 Share on other sites More sharing options...
Jessica Posted August 31, 2007 Share Posted August 31, 2007 require('file.php') OR die("error message"); Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338315 Share on other sites More sharing options...
teng84 Posted August 31, 2007 Share Posted August 31, 2007 use require or include depends on your needs any way try to use require_once and include_once try http://www.php.net/manual/en/function.file-exists.php Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338318 Share on other sites More sharing options...
teng84 Posted August 31, 2007 Share Posted August 31, 2007 require('file.php') OR die("error message"); oops i dont this would work if you cant find the path and u use require this will terminate the whole script but for include it will continue but still error will occur i vote!! http://www.php.net/manual/en/function.file-exists.php Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338325 Share on other sites More sharing options...
prime Posted August 31, 2007 Author Share Posted August 31, 2007 <?php $local_pass = "off"; //not active yet $local_mode = "open"; require("mscript.php") or die("unable to access script"); ?> Just gives a blank page if it fails, it wont give the die message. and with the Parse error: syntax error, unexpected '}' in /home/content/m/e/t/metaconcert/html/primefalcon/index.php on line 12 <?php $success = @require("mscript.php"); if (!$success) { die('unable to access MScript') }//This is line 12 $local_pass = "off"; //not active yet $local_mode = "open"; @require("mscript.php") ?> Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338328 Share on other sites More sharing options...
teng84 Posted August 31, 2007 Share Posted August 31, 2007 use require or include depends on your needs any way try to use require_once and include_once try http://www.php.net/manual/en/function.file-exists.php Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338329 Share on other sites More sharing options...
darkfreaks Posted August 31, 2007 Share Posted August 31, 2007 instead of include or require try require_once or include_once Try this was missing a ; at the end of the if statement <?php $success = @require("mscript.php"); if (!$success){ die('unable to access MScript'); } $local_pass = "off"; //not active yet $local_mode = "open"; @require("mscript.php"); ?> Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338331 Share on other sites More sharing options...
teng84 Posted August 31, 2007 Share Posted August 31, 2007 you dont have a terminator $aray=array('page.php', 'page2.php'); foreach($aray as $array) if (file_exists($array)) { require_once $array; } else { echo "The file $array does not exist"; } try i havent test that but that will test all your file you want to include by adding the value in an array Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338332 Share on other sites More sharing options...
prime Posted August 31, 2007 Author Share Posted August 31, 2007 The require was still giving blank, so I changed to include again so it reads <?php $success = @include("mscript.php"); if (!$success){ die('unable to access MScript'); } $local_pass = "off"; //not active yet $local_mode = "open"; @include("mscript.php"); ?> and that works perfectly, thank you so much, so much for the simple include or die I thought it would be lol Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338338 Share on other sites More sharing options...
teng84 Posted August 31, 2007 Share Posted August 31, 2007 instead of include or require try require_once or include_once Try this was missing a ; at the end of the if statement <?php $success = @require("mscript.php"); if (!$success){ die('unable to access MScript'); } $local_pass = "off"; //not active yet $local_mode = "open"; @require("mscript.php"); ?> that wont work thats the same as jesirose did look when we assign anything in a variable the action is also happening like $x=include 'fdsf.php'; even if you do that still the script or php will read your code as including that file so if the code cant find it it will give an error note: the result for that code you produce is not boolean so error will occur Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338339 Share on other sites More sharing options...
darkfreaks Posted August 31, 2007 Share Posted August 31, 2007 no i was still right he was just missing 2 terminators in his code so he got errors Link to comment https://forums.phpfreaks.com/topic/67390-simple-question-really-it-is/#findComment-338340 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.