I've broken something but not sure what

carlgale

Verified User
Joined
Oct 12, 2006
Messages
34
Hi

Sorry if posted in the wrong section, I think it fits here but not 100% sure...


On my server I use a few php includes to pull content from text files (on my server) and insert that content in other pages. I use the following code to achieve this

PHP:
<?
    // specify directory
    $directory = "/path/to/directory";

    // make a list of text file paths in directory
    if ($handle = opendir($directory)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != ".." && preg_match("/\.txt$/",$file)){
                $file_paths[] = $directory."/".$file;
            }
        }
        closedir($handle);
    }
    
    // randomize the file path list
    shuffle($file_paths);
    
    // and select the first path
    $textfile = $file_paths[0];
    
    // do something with selected path such as output the contents...
    echo file_get_contents($textfile);        
?>

This was working fine and all was good. However, a few days back I formatted the server and reinstalled direct admin. Now when I run the above code I get a blank page, no content is pulled even if I just set up a test directory. If I used <php></php> at the start and end instead of <? then the code just breaks. All the server settings are as they were previously so that should be fine. PHP and Open Base are turned off on all domains. When I rebuilt DA I selected option 3 from the 3 build choices menu. Would that have made any difference?


Any help would be most welcome please, I have tested everything I think it could be but still not success.

Thanks
Carl
 
What you're looking for is the php.ini setting short_open_tag, which you could set to On.

Also the correct alternative is <?php code_here ?>
 
Hi, thanks for the reply. Just checked the php.ini and it says short_open_tag
; Default Value: On so I assume that to mean it's already turned on?
 
Well since you brought up the <? thing, I assumed this was the issue. You could verify it by chaning <? to <?php and see if it works. If it does work, then the issue is short_open_tag, if not, then I'm guessing there goes something wrong with accessing that file in the script. The file might not be there or maybe it doesn't have access to it.

You should get an error in that case, if not try enabling it by putting

<?php
error_reporting(E_ALL);

right there on the top of the script.
 
Hi, thanks for the reply. Just checked the php.ini and it says short_open_tag
; Default Value: On so I assume that to mean it's already turned on?

Check your php.ini again with nano and search for 'short_open_tag'. The first time you'll get some piece of documentation, second result is the real setting. Make sure there are no ';' before 'short_open_tag: on'. Faster is the solution of Arieh, replace the first '<?' of your script to '<?php', save and test the file.
 
Back
Top