Welcome to WebDesignForums.net!
You're currently viewing WDF as a guest. By registering for a free account, you'll be able to participate with other members in our friendly community. Being a member allows you to ask questions and get answers for those troublesome web development tasks!

In addition, as a member you'll be able to post your websites up for review. Using our unique website review system you can gain some amazing feedback from some of the best web developers around. This is a completely free service to all registered members.

Ready to register yet? Registration is 100% free. Click Here To Join Now!

PHP Source Code in Color!!!

Discussion in 'Coding Articles & Tutorials' started by Wired, Nov 8, 2003.

  1. Offline

    Wired WDF Moderator and Alien Overlord

    Message Count:
    7,600
    Likes Received:
    133
    Trophy Points:
    63
    Ever wondered how someone posts the source of their PHP, and in color? Here's how! http://us4.php.net/manual/en/function.highlight-file.php

    Step 1: save the following code as source.php

    PHP:
    <html>
    <head>
    <title>Source Display</title>
    </head>
    <body bgcolor="white">
    <?php
        $script 
    getenv("PATH_TRANSLATED");
        if (!
    $script) {
            echo 
    "<br /><b>ERROR: Script Name needed</b><br />";
        } else {
            if (
    ereg("(\.php|\.inc)$",$script)) {
                echo 
    "<h1>Source of: $PATH_INFO</h1>\n<hr />\n";
                
    highlight_file($script);
            } else {
                echo 
    "<h1>ERROR: Only PHP or include script names are allowed</h1>"
            }
        }
        echo 
    "<hr />Processed: "date("Y/M/d H:i:s"time());
    ?>
    </BODY>
    </HTML>
    From here, there are 2 ways to go.

    If you have access to your server's httpd.conf file, add the following into it:
    From here, all you would have to do is to reference your code like so: webdesignforums.net/source/whatever.php

    If you don't have access to your httpd.conf file, then you can reference the same file like so:
    webdesignforums.net/source.php/whatever.php

    Note: Either way you go, don't forget to replace webdesignforums.net with your domain name. And this will only work with php files in the same directory or in a sub-directory, so this will not work with php files hosted on other sites. Because PHP is a server-side language, this is not possible.


  2. Offline

    drews New Member

    Message Count:
    63
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    St. Petersburg, Florida
    Actually there is a much easier way to do this.

    PHP:

    <?php
     
    $file 
    $_GET["file"];
     
    show_source($file);
     
    ?>
    Save that file as source.php and you have it. You can then view the source of a file by going to http://www.my-site.com/source.php?file=whatever.xxx

    Obviously, you will get errors if the file does not exist, or if you don't have proper permissions on the file.


  3. Offline

    Squeakypants New Member

    Message Count:
    67
    Likes Received:
    0
    Trophy Points:
    0


  4. Offline

    Wired WDF Moderator and Alien Overlord

    Message Count:
    7,600
    Likes Received:
    133
    Trophy Points:
    63
    correct, however some people don't have the ability to change their apache settings.


  5. Offline

    Detective New Member

    Message Count:
    4
    Likes Received:
    0
    Trophy Points:
    0
    is there a way out ?


  6. Offline

    Wired WDF Moderator and Alien Overlord

    Message Count:
    7,600
    Likes Received:
    133
    Trophy Points:
    63
    What are you talking about?


  7. Offline

    jbagley New Member

    Message Count:
    845
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Cape Town
    I think he is talking about how to get out of this thread! LOL :classic:


  8. Offline

    Squeakypants New Member

    Message Count:
    67
    Likes Received:
    0
    Trophy Points:
    0
    wtf?? lol


Share This Page