1

When I run the following script:

<html>
<head>
<title>Example</title>
</head>
<?php
echo get_include_path(), "\n";

var_dump(is_file('/usr/lib/php/HTTP/OAuth.php'));
?>
<body>
</body>
</html>

I get the following output on the rendered page:

.:/php/includes:/usr/lib/php:/usr/lib/php/PEAR bool(true)

However, if I run this script:

<html>
<head>
<title>Example</title>
</head>
<?php
echo get_include_path(), "\n";

var_dump(is_file('/usr/lib/php/HTTP/OAuth.php'));

#### NEW SECTION ####

if (include(''/usr/lib/php/HTTP/OAuth.php'') == 'OK') {
echo 'INCLUDE OK, "\n"';
} else { echo 'INCLUDE FAILED \n' ; }

#### END NEW SECTION ####

?>
<body>
</body>
</html>

I get the following output:

.:/php/includes:/usr/lib/php:/usr/lib/php/PEAR bool(true) INCLUDE FAILED \n

Why would the include fail if the file is said to exist already?

uname output in case it is helpful:

Darwin 70cd606c7510 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun  7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386

Thank you for your help.

John

1
  • 1
    ''/usr/lib/php/HTTP/OAuth.php'' is a syntax error. Are you sure that's it? Commented Jan 15, 2012 at 4:48

1 Answer 1

3

You should have read Example #4 on the PHP help page:

<?php
// won't work, evaluated as include(('vars.php') == 'OK'), i.e. include('')
if (include('vars.php') == 'OK') {
    echo 'OK';
}

// works
if ((include 'vars.php') == 'OK') {
    echo 'OK';
}
?>

Also, are the double single quotes in your original code a typo?

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for the feedback @animuson and to everyone who read my post. I removed the double quotes and made the change you suggested, and I still get the same result (boolean returns true but the include does not return 'OK'). See updated code below: <html> <head> <title>Example</title> </head> <?php echo get_include_path(), "\n"; var_dump(is_file('/usr/lib/php/HTTP/OAuth.php')); #### NEW SECTION #### if (include '/usr/lib/php/HTTP/OAuth.php' == 'OK') { echo 'INCLUDE OK, "\n"'; } else { echo 'INCLUDE FAILED \n' ; } #### END NEW SECTION #### ?> <body> </body> </html>
Does that file actually return 'OK'? An include by default will not return anything, the file has to return something to compare too.
var_dump prints true ... here is the output from running the script: .:/php/includes:/usr/lib/php:/usr/lib/php/PEAR bool(true) INCLUDE FAILED \n
That just means the file exists. Also, your include statement should be ((include '/usr/lib/php/HTTP/OAuth.php') == 'OK') and the file that you're including actually has to return the value 'OK' (return 'OK';) in order for that conditional statement to pass.
Just changed the if statement to: if ((include '/usr/lib/php/HTTP/OAuth.php') == 'OK') { It still prints the same line: .:/php/includes:/usr/lib/php:/usr/lib/php/PEAR bool(true) INCLUDE FAILED \n
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.