SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP code not working on a certain server

    Hi,

    I have the following code in my application and it is not working on a certain VPS server and I have no idea why.

    Server: Linux - PHP Version 5.3.16

    PHP Code:
    <?php
    define
    ('PROJECTS_DIR''../projects/');

    // Gets project names from the projects folder.
    function projects() {
        
    $projects glob(PROJECTS_DIR.'*'GLOB_ONLYDIR);
        for (
    $i=0$i<count($projects); $i++) {
            
    $projects[$i] = basename($projects[$i]);
        }
        return 
    $projects;
    }

    $projects projects();

    if (empty(
    $projects)) {
    echo 
    'No projects found.';
    }
    ?>
    The above code works fine on all other servers I tested but not on this one. What could be the reason? What should I check in phpinfo() or php.ini?

    Thanks for any ideas.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    What do you mean by "not working" ? Do you get an error? An empty screen? The 'no projects found' message while there are projects?

    Maybe the PHP version on that server is < 4.3.0 ?
    And you might want to do a var_dump($projects) in the function to check the value.

  3. #3
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    What do you mean by "not working" ? Do you get an error? An empty screen? The 'no projects found' message while there are projects?

    Maybe the PHP version on that server is < 4.3.0 ?
    And you might want to do a var_dump($projects) in the function to check the value.
    No errors, no output. PHP 5.3.16.

    I tried var_dump($projects), it gave

    array(1) { [0]=> string(0) "" }

    So, the problem is probably with the function, maybe glob() doesn't work with some setting. No idea...

  4. #4
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is part of a function I use to create a drop-down menu that provides a list of directory names in $logs_dir. It works on several servers including windows/IIS7

    It might throw some light on your problem:

    PHP Code:
        foreach(glob($logs_dir.'/*'GLOB_ONLYDIR) as $dir){ 
            
    $dir basename($dir);
            if(
    stripos($dir,".") != FALSE){
               
    $html .= '<option value='.$dir'>' .$dir'</option>';
            }
        } 
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  5. #5
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The issue seems to be that glob() function is not working on that server. No idea if it is disabled or if it can be disabled somehow. If you have any ideas, please share with me. Thanks.

  6. #6
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What PHP version is installed on that server? Must be 4.3.x or higher for glob() to work
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  7. #7
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 2ndmouse View Post
    What PHP version is installed on that server? Must be 4.3.x or higher for glob() to work
    PHP 5.3.16 as I mentioned two times previously. I also checked php.ini and "disable_functions" is empty. I don't understand why in the world would glob not work on that one server while it is working on like a thousand other different servers.

  8. #8
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,871
    Mentioned
    206 Post(s)
    Tagged
    12 Thread(s)

  9. #9
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Standard 'omg it doesnt work, but its not a WPSE' debugging. Echo all the things!
    PHP Code:
    <?php
    define
    ('PROJECTS_DIR''../projects/');
    echo 
    "ProjDir: "PROJECTS_DIR."<br />";
    // Gets project names from the projects folder.
    function projects() {
        
    $projects glob(PROJECTS_DIR.'*'GLOB_ONLYDIR);
        echo 
    "FDebug1: ".print_r($projects,true)."<br/>"
        for (
    $i=0$i<count($projects); $i++) {
            
    $projects[$i] = basename($projects[$i]);
        }
        echo 
    "FDebug2: ".print_r($projects,true)."<br/>";
        return 
    $projects;
    }

    $projects projects();
        echo 
    "EDebug1: ".print_r($projects,true)."<br/>";
    if (empty(
    $projects)) {
    echo 
    'No projects found.';
    }
    ?>
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  10. #10
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    @StarLion ; a complicating factor is this (from the php manual):
    Note:

    On some systems it is impossible to distinguish between empty match and an error.
    So the empty array the OP gets could mean that there are no projects, or that there was an error.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •