473,395 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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?
Feb 3 '07 #1
15 1455
Motoma
3,237 Expert 2GB
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.
Feb 3 '07 #2
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?
Feb 3 '07 #3
Motoma
3,237 Expert 2GB
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.
Feb 3 '07 #4
Thank you! I'll give it a try.
Feb 3 '07 #5
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 = ImageCreateFromPng("PNG.png");


for ($y = 0; $y < 30; $y++) {
for ($x = 0; $x < 100; $x++) {
$rgb = ImageColorAt($im, $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($morse);

echo $result;

?>
[/PHP]
Feb 3 '07 #6
Motoma
3,237 Expert 2GB
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?
Feb 3 '07 #7
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.
Feb 3 '07 #8
Motoma
3,237 Expert 2GB
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?
Feb 3 '07 #9
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.
Feb 5 '07 #10
Motoma
3,237 Expert 2GB
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.
Feb 5 '07 #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.
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.hackthissite.org/missions/permprogramming/2/
Feb 5 '07 #12
Motoma
3,237 Expert 2GB
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.
Feb 5 '07 #13
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.
Feb 6 '07 #14
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?
Feb 6 '07 #15
Motoma
3,237 Expert 2GB
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?
That is exactly what that means.
Feb 6 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Wm | last post by:
I'm totally clueless on this one -- I'm getting 3 copies of every Email (in plain text, not HTML as expected), from a single mail() line... Can anyone tell me what might be causing the duplicates??...
33
by: Jim Hill | last post by:
I've done some Googling around on this and it seems like creating a here document is a bit tricky with Python. Trivial via triple-quoted strings if there's no need for variable interpolation but...
2
by: Brian | last post by:
Taking cluelessness to a whole new level. < http://support.apollohosting.com/ > The beginning of the html is below. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> ...
50
by: jbailo | last post by:
Subject: dotnet is a farce. You know, I was always impressed with the way one could write a http program with c# or java. To me, it showed how 'superior' these languages are because they made...
2
by: BLetts | last post by:
I have an ASP.NET app that must allow users to upload files. The files are stored in a virtual directory. I use Server.MapPath to map from the virtual directory name to a physical path, then the...
13
by: Kirk McDonald | last post by:
Say I have a database containing chunks of Python code. I already have a way to easily load, edit, and save them. What is slightly baffling to me is how I can effectively pass this code some...
7
by: Doe | last post by:
I've been trying this for months. Doesn't work. I've used the code in this article, http://support.microsoft.com/kb/311288/en-us, HOW TO: Invoke the Find, View Source, and Options Dialog Boxes...
17
by: Bruno | last post by:
I have a feature that is hosted on a different domain from the primary one in a frame, and need to retain values in a cookie. example: A web page at one.com contains a frame which has a page...
7
by: alexandre_irrthum | last post by:
Hi there, I am trying to use pyserial to read data from a temperature logger device (T-logger). T-logger is based on the DS1615 temperature recorder chip (Dallas Semiconductor). According to the...
3
by: eggman89 | last post by:
Hi I'm doing my Fourth Year B.E. project under the internship of MindTree! Now they have only told us what to do , but haven't guide much! Now, we have been told to develop an search...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.