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?
Easy PHP question from clueless
Collapse
X
-
Provided your web-server has PHP installed, you can insert it into any file with a .php extension inside <?php ?> brackets.Originally posted by defienceHi....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? -
Yes, provided all of the php code is correct.Originally posted by defienceThank 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
-
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
-
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
-
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?Originally posted by defienceI'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, 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 youOriginally posted by MotomaWell, 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.
http://www.hackthissit e.org/missions/permprogramming/2/Comment
-
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
-
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
Comment