Jump to content

Simple question (really it is)


prime

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

 <?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
Share on other sites

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
Share on other sites

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.