Easy PHP question from clueless

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • defience
    New Member
    • Jan 2007
    • 27

    Easy PHP question from clueless

    Hi....I have a question about PHP, which I know nothing about. I was wondering what to do with some php code that I came across on the internet and I wanted to see how it works. Using this page as an example, let's say the code will count every letter on this page and give an answer. How do I go about getting the code to work? Do I simply insert it anywhere in the source code or does it require 'compiled' like some other languages?
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Originally posted by defience
    Hi....I have a question about PHP, which I know nothing about. I was wondering what to do with some php code that I came across on the internet and I wanted to see how it works. Using this page as an example, let's say the code will count every letter on this page and give an answer. How do I go about getting the code to work? Do I simply insert it anywhere in the source code or does it require 'compiled' like some other languages?
    Provided your web-server has PHP installed, you can insert it into any file with a .php extension inside <?php ?> brackets.

    Comment

    • defience
      New Member
      • Jan 2007
      • 27

      #3
      Thank you for the quick reply. So let's say I have this:
      <?php
      blah
      blah
      blah
      ?>

      ...and I'm on this forum page. I can view the source code, then paste that in to it? Then I have to 'save as' *.php and it should run and count the page characters for me?

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by defience
        Thank you for the quick reply. So let's say I have this:
        <?php
        blah
        blah
        blah
        ?>

        ...and I'm on this forum page. I can view the source code, then paste that in to it? Then I have to 'save as' *.php and it should run and count the page characters for me?
        Yes, provided all of the php code is correct.

        Comment

        • defience
          New Member
          • Jan 2007
          • 27

          #5
          Thank you! I'll give it a try.

          Comment

          • defience
            New Member
            • Jan 2007
            • 27

            #6
            Well, it just makes the code visible on the actual page so I figured I should post specifics. Below is the challenge and the php code:

            [PNG image=small black box with white dots throughout]
            The pixels in the above image are numbered 0..99 for the first row, 100..199 for the second row etc. White pixels represent ascii codes. The ascii code for a particular white pixel is equal to the offset from the last white pixel. For example, the first white pixel at location 65 would represent ascii code 65 ('A'), the next at location 131 would represent ascii code (131 - 65) = 66 ('B') and so on.

            The text contained in the image is the answer encoded in Morse, where "a test" would be encoded as ".- / - . ... -"
            You have 15 seconds time to send the solution

            [PHP]

            <?php
            error_reporting (E_ALL ^ E_NOTICE);
            $im = ImageCreateFrom Png("PNG.png");


            for ($y = 0; $y < 30; $y++) {
            for ($x = 0; $x < 100; $x++) {
            $rgb = ImageColorAt($i m, $x, $y);
            $r = ($rgb >> 16) & 0xFF;
            $g = ($rgb >> 8) & 0xFF;
            $b = $rgb & 0xFF;
            if ($b == 1) {
            $xcoord[] = $x;
            $ycoord[] = $y;
            }
            }
            }


            for ($i = 0; $i < count($xcoord); $i++) {
            $xcoord[$i] += $ycoord[$i] * 100;
            $coord[$i] = $xcoord[$i] - $xcoord[$i-1];
            $morse .= chr($coord[$i]);
            }

            echo $morse . "<br />";

            include 'morsemod.php';

            $result = morse_decode($m orse);

            echo $result;

            ?>
            [/PHP]

            Comment

            • Motoma
              Recognized Expert Specialist
              • Jan 2007
              • 3236

              #7
              Does your server have PHP installed? Is the extension on the file .php? Are you viewing the page through your webserver, or by opening it locally?

              Comment

              • defience
                New Member
                • Jan 2007
                • 27

                #8
                I'm not sure if my webserver has php enabled. The page where the image is viewed is online and the solution to it changes with every failed attempt. As for the php code, I came across it on a site in a forum similar to this one and I copied and pasted it into Notepad for the time so I could have it handy. Now, I have and account at t35.com, which is a free webhosting site, and I put the code in there and saved it as a .php file, if that helps anything.

                Comment

                • Motoma
                  Recognized Expert Specialist
                  • Jan 2007
                  • 3236

                  #9
                  Originally posted by defience
                  I'm not sure if my webserver has php enabled. The page where the image is viewed is online and the solution to it changes with every failed attempt. As for the php code, I came across it on a site in a forum similar to this one and I copied and pasted it into Notepad for the time so I could have it handy. Now, I have and account at t35.com, which is a free webhosting site, and I put the code in there and saved it as a .php file, if that helps anything.
                  And you said it only printed out the php code? I'm not sure what the problem is. T35.com claims that all users are given PHP access. Do you have a link that I could take a look at?

                  Comment

                  • defience
                    New Member
                    • Jan 2007
                    • 27

                    #10
                    Yeah, at t35.com I saved the file as a .php but I guess I'm not sure what to do with it from there. Do I open the website with the PNG and then open the file from t35? I'm not sure how that would get the script to run.

                    Comment

                    • Motoma
                      Recognized Expert Specialist
                      • Jan 2007
                      • 3236

                      #11
                      Well, as it is set up right now, you would need to upload the png to the server and set it the the filename you are trying to open in your script.

                      Comment

                      • defience
                        New Member
                        • Jan 2007
                        • 27

                        #12
                        Originally posted by Motoma
                        Well, as it is set up right now, you would need to upload the png to the server and set it the the filename you are trying to open in your script.
                        Motoma, here is the site with the challenge. Could you take a quick look at it and see if it's possible to use that .php script to accomplish this? Thank you
                        http://www.hackthissit e.org/missions/permprogramming/2/

                        Comment

                        • Motoma
                          Recognized Expert Specialist
                          • Jan 2007
                          • 3236

                          #13
                          Dude, I'm not going to help you with a hacking challenge for anoter site.
                          Take a look at PHP.net's GD reference page. Then take a look at the source for the page, side by side with PHP.net's cURL reference.
                          Learning is the most important part of hacking.

                          Comment

                          • defience
                            New Member
                            • Jan 2007
                            • 27

                            #14
                            Yeah, I figured that if I posted the website, it might get a negative reaction but for me it's just about having harmless fun and learning things in the process. I had to write a simple program to pass one challenge and it was a rewarding feeling once I finished it. I used python for that one but like I said, I came across this php script and was curious as to how it worked and I wanted to see it in action. Thanks again for the replies & for the links.

                            Comment

                            • defience
                              New Member
                              • Jan 2007
                              • 27

                              #15
                              One more question.....in the code it has this: include 'morsemod.php'; Is that like with other languages where it's making a call to another script that has to be accessed for the entire code to work, or is that just a reference to the actual code itself?

                              Comment

                              Working...