Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post

    if then make green, else, make red problems.

    On this code:

    PHP Code:
    <?php
    $configname 
    "../includes/config.inc.php";
    $configmod substr(sprintf('%o'fileperms($configname)), -4);
    echo 
    "<table width=\"100%\"  border=\"2\" cellspacing=\"0\" cellpadding=\"3\">";
    echo 
    "<tr>";
    echo 
    "<th scope=\"col\">File Name</th>";
    echo 
    "<th scope=\"col\">Needed Chmod</th>";
    echo 
    "<th scope=\"col\">Current Chmod</th>";
    echo 
    "</tr><tr>";
    echo 
    "<td>"$configname ."</td>";
    echo 
    "<td>0777</td>";
    echo 
    "<td>$configmod</td>";
    echo 
    "</tr><table>";
    ?>
    i want it to change to be, check the file for permissions, it it doesn't have the right permissions, make the row with its information red, if it does, then make it green. Im not sure how to go about this, any ideas?

    This is the page with the current code on it: http://www.lonelylizard.com/~eli/tes...l/install1.php

  • #2
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    Hi,

    First, you need some CSS for your red and green states. Something like:

    Code:
    TR.badperms TD { 
      color:#CC0000;
    }
    
    TR.goodperms TD { 
      color:#00CC00;
    }
    It depends what you regard as "correct permissions", so:

    PHP Code:

    $configname 
    "../includes/config.inc.php"
    clearstatcache();
    $configmod substr(sprintf('%o'fileperms($configname)), -4); 
    $goodperms //Whatever - NOTE: you need to put the permission you require in here or this code will be in error.
    $trcss = (($configmod != $goodperms) ? "badperms" "goodperms");

    echo 
    "<table width=\"100%\"  border=\"2\" cellspacing=\"0\" cellpadding=\"3\">"
    echo 
    "<tr>"
    echo 
    "<th scope=\"col\">File Name</th>"
    echo 
    "<th scope=\"col\">Needed Chmod</th>"
    echo 
    "<th scope=\"col\">Current Chmod</th>"
    echo 
    "</tr><tr class=".$trcss.">"
    echo 
    "<td>"$configname ."</td>"
    echo 
    "<td>0777</td>"
    echo 
    "<td>$configmod</td>"
    echo 
    "</tr><table>"
    That should work. If you want to perform other checks on permissions (i.e. checking for more than just one value), this link should give you some ideas: http://uk.php.net/manual/en/function.fileperms.php

    Hope that helps!

    Mike.
    Last edited by mlse; 01-01-2006 at 12:01 PM.
    Die Welt ist ein Irrenhaus und hier ist die Zentrale!

  • #3
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    thanks for the speedy reply, but i have one more question.

    Can you explain what this line does?

    PHP Code:
    $trcss = (($configmod != $goodperms) ? "badperms" "goodperms"); 

  • #4
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That is using the ternary operator.

    It is a short way of using an if/else statement.

    PHP Code:
    if($configmod != $goodperms){ //if not equal to
     
    $trcss "badperms";
    }
    else{
     
    $trcss =  "goodperms");


  • #5
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    ok, thanks.

  • #6
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    Yes indeed. Strictly speaking it's not good programming practice, but I use it because I'm a rebel Also I'm lazy
    Die Welt ist ein Irrenhaus und hier ist die Zentrale!


  •  

    Posting Permissions

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