Home
Calendar
Certifications
Columns
Features
Forum
Resources
Vitals
Latest Additions
April 2013 Free Giveaway Sponsor - eLearnSecurity
Human Intelligence to Navigate the Security Data Deluge
February 2013 Free Giveaway Winner of SANS CyberCon Training
Interview: Bugcrowd Founders on Herding Ninjas for Crowdsourced Bug Bounties
Network Forensics: The Tree in the Forest
March 2013 Free Giveaway Sponsor - Mile2
Book Review: Violent Python
February 2013 Free Giveaway Sponsor - SANS
Holiday 2012 Free Giveaway Winner of Metasploit Pro by Rapid7
Course Review: SANS FOR408 Computer Forensic Investigations – Windows In-Depth
The Security Consulting Sugar High
Tutorial: Fun with SMB on the Command Line
Interview: Ilia Kolochenko, CEO of High-Tech Bridge
October 2012 Free Giveaway Winner of LearningGate Training
The Broken: Assessing Corporate Security in 2012 to Make a Better 2013
EH-Net Login
Welcome Guest.
Username:
Password:
Remember me
Lost Password?
No account yet?
Register
Who's Online
We have 50 guests online
Free Business and Tech Magazines and eBooks
You are here:
Home
Ethical Hacking Discussions and Related Certifications
Programming
PHP Help
EH-Net
May 24, 2013, 08:12:17 PM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News
: Go back to The Ethical Hacker Network Online Magazine
Home Page
Home
Help
Calendar
Login
Register
EH-Net
>
Ethical Hacking Discussions and Related Certifications
>
Programming
(Moderator:
don
) >
PHP Help
Pages: [
1
]
Go Down
« previous
next »
Print
Author
Topic: PHP Help (Read 6667 times)
0 Members and 1 Guest are viewing this topic.
BillV
Hero Member
Offline
Posts: 1892
PHP Help
«
on:
September 04, 2009, 10:05:48 PM »
Hey guys, I have a small piece of code I'm trying to make dynamic and I'm a little stumped - it's been driving me nuts for a little while now.. was wondering if anyone might have some insight...
Code:
foreach($w1 as $v1){
foreach($w2 as $v2){
foreach($w3 as $v3){
$all_w[]=$v1.$v2.$v3;
}
}
}
I'm trying to figure out how I can make that dynamic, so I don't have to have 50 nested foreach loops... I think I can get the first part, but building the array at the end seems to be the tough part. Any suggestions?
Thanks!
Logged
payup
Newbie
Offline
Posts: 1
Re: PHP Help
«
Reply #1 on:
September 04, 2009, 11:09:20 PM »
Code:
<?php
$all
= array();
function
merge
(
$arraynum
){
////// whatever you are merging, typically this won't be here either, but would be defined elsewhere and passed to the function
static
$myArrayName1
= array (
'a'
,
'b'
);
static
$myArrayName2
= array (
'c'
,
'd'
,
'e'
);
static
$myArrayName3
= array (
'f'
,
'g'
,
'h'
,
'i'
);
//////
foreach (${
'myArrayName'
.
$arraynum
} as
$arrayitem
){
$GLOBALS
[
'all'
][] =
$arrayitem
;
}
$arraynum
++;
if(${
'myArrayName'
.
$arraynum
}!=
""
){
merge
(
$arraynum
);
}
else{
return
$GLOBALS
[
'all'
];
}
}
merge
(
1
);
foreach (
$all
as
$arrayitem
){
echo
$arrayitem
;
}
?>
Logged
Jhaddix
Sr. Member
Offline
Posts: 317
Re: PHP Help
«
Reply #2 on:
September 04, 2009, 11:16:28 PM »
Can you describe in words what you were trying to accomplish?
Logged
GSEC, GPEN, GWAPT, ECPPT, WAHHlive, LSOAdvancedPenTester
http://www.securityaegis.com
http://www.pentesterscripting.com
http://code.google.com/p/pentest-bookmarks/
BillV
Hero Member
Offline
Posts: 1892
Re: PHP Help
«
Reply #3 on:
September 05, 2009, 07:51:44 AM »
Thanks payup! That looks like it should do the trick.. will have to try it out
Jason:
I have an unknown amount of arrays ($w) that contain an unknown amount of elements ($v) each. The basics of it, is that I needed to find every possible combination always starting with an item from the first, then the second, etc.
So if...
$w = a, b, c
$w2 = d, e, f
I need to find:
ad, ae, af, bd, be, bf, cd, ce, cf
And this could of course be something more intense:
$w = a, b, c, d
$w2 = h, j, l, 1, 4, 6, $
$w3 = 5, 2
etc.
The code I was using above worked really well and did the trick, but only up to the amount of 'foreach' that I had.
Logged
Ketchup
Hero Member
Offline
Posts: 1021
Re: PHP Help
«
Reply #4 on:
September 05, 2009, 12:15:03 PM »
Bill,
Can you use a two dimensional array here, instead of having a bunch of one dimensional arrays?
Logged
~~~~~~~~~~~~~~
Ketchup
BillV
Hero Member
Offline
Posts: 1892
Re: PHP Help
«
Reply #5 on:
September 05, 2009, 03:30:21 PM »
I probably could, but I think I've come to the realization that it doesn't matter at this point. I have to cap it at 5 or 6 deep. Anything past that causes PHP to error out complaining about memory:
Quote
Fatal error: Allowed memory size of 25165824 bytes exhausted (tried to allocate 2097152 bytes)
Logged
ethicalhack3r
Full Member
Offline
Posts: 139
Re: PHP Help
«
Reply #6 on:
September 05, 2009, 07:06:56 PM »
Quote from: BillV on September 05, 2009, 03:30:21 PM
I probably could, but I think I've come to the realization that it doesn't matter at this point. I have to cap it at 5 or 6 deep. Anything past that causes PHP to error out complaining about memory:
Quote
Fatal error: Allowed memory size of 25165824 bytes exhausted (tried to allocate 2097152 bytes)
I think you can increase the alocated memory size in PHP.ini. Probably best to find a better solution tho.
Logged
UNIX
Hero Member
Offline
Posts: 1235
Re: PHP Help
«
Reply #7 on:
September 06, 2009, 12:59:02 PM »
If you can't find another solution the entry for changing the allocated memory would be at
memory_limit
if I remember correctly and if you haven't found it yet.
Logged
BillV
Hero Member
Offline
Posts: 1892
Re: PHP Help
«
Reply #8 on:
September 07, 2009, 07:51:03 AM »
Yeah, I'm aware of it.. I don't have the ability to change it in the hosting environment.
Logged
Ketchup
Hero Member
Offline
Posts: 1021
Re: PHP Help
«
Reply #9 on:
September 07, 2009, 09:47:43 AM »
I find that it's usually better to optimize your code than to increase memory capacity.
Bill, can you parse the arrays in steps? If you don't find what you are looking for in 5 arrays, mark them as such and start another loop for the next 5, and so on?
Would they let you stick a small CGI in the hosting environment. Maybe you can write this procedure in C, Perl, etc. and offload it from PHP. Obviously this could completely run away with RAM.
Logged
~~~~~~~~~~~~~~
Ketchup
Pages: [
1
]
Go Up
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
EH-Net
-----------------------------
=> Calendar Of Events
===> ChicagoCon 2007
===> ChicagoCon 2008s
===> ChicagoCon 2008f
===> ChicagoCon 2009s
=> Ethical Hacktivism
=> News Items and General Discussion About EH-Net
===> Greetings
=> Special Events
-----------------------------
Ethical Hacking Discussions and Related Certifications
-----------------------------
=> General Certification
===> Networking
===> OS
===> Security
=> Compliance, Regulations & Standards
=> Control Systems
=> Cyber Warfare
=> Forensics
===> CCE / MCCE - (Master) Certified Computer Examiner
===> CHFI - Computer Hacking Forensic Investigator
===> EnCE - EnCase® Certified Examiner
===> GCFA - GIAC Certified Forensics Analyst
=> Hardware
=> Incident Response
===> CSIH - Computer Security Incident Handler
===> GCIH - GIAC Certified Incident Handler
=> Malware
===> Advisories
=> Mobile
=> Network Pen Testing
===> CEH - Certified Ethical Hacker
===> CPTC - Certified Penetration Testing Consultant
===> CPTE - Certified Penetration Testing Engineer
===> CSTA - Certified Security Testing Associate
===> eCPPT - eLearnSecurity Certified Professional Penetration Tester
===> ECSA - EC-Council Certified Security Analyst
===> GPEN - GIAC Certified Penetration Tester
===> OSCP - Offensive Security Certified Professional
=> Physical Security
=> Programming
=> Social Engineering
=> Web Applications
=> Wireless
===> CWNP Certs
===> GAWN - GIAC Assessing Wireless Networks
===> OSWP - Offensive Security Wireless Professional
=> Other
-----------------------------
Columns
-----------------------------
=> Editor-In-Chief
=> Andress
=> Gates
=> Haddix
=> Hadnagy
=> Heffner
=> Hoffman
=> Linn
=> RichM
=> Murray
=> J. Peltier
=> Weidman
=> Wilson
-----------------------------
Features
-----------------------------
=> /root
=> Book Reviews
=> Opinions
=> Skillz
===> Examples
===> May 06 - Star Hacks, Episode V: The Empire Hacks Back
===> July 06 - Hack Bill!
===> Sept 06 - Netcat in the Hat
===> Nov 06 - Hitch-Hackers Guide to the Galaxy
===> Dec 06 - A Christmas (Hacking) Story
===> Feb 07 - Charlottes Web Site
===> April 07 - Microsoft Office Space
===> June 07 - Serenity Hack
===> Oct 07 - Worst. Ethical. Hacker. Challenge. Ever.
===> Dec 07 - Frosty the Snow Crash
===> March 2008 - It Happened One Friday
===> Oct 2008 - Scooby Doo and the Crypto Caper
===> Dec 08 - Santa Claus Is Hacking to Town
===> Feb 2009 - Brady Bunch Boondoggle
===> July 2009 - Prison Break
===> October 2009 - SSHliders
===> December 2009 - Miracle on Thirty-Hack Street
===> December 2010 - The Nightmare Before Charlie Browns Christmas
-----------------------------
Resources
-----------------------------
=> Career Central
===> Looking For Work
===> Looking To Hire
=> Links to cool sites.
=> Mass Media
=> News from the Outside World
=> Tools
=> Tutorials
===> Tutorial Requests
Loading...
Exclusive Deal
SANSFIRE 2013
June 15 - 22
5% Off
w/ Code
:
EHN_5
SANS Deals 4 EH-Netters
5% OFF
Any
SANS Course
in Any Format!
Coupon Code:
EHN_5
Including
SANS Rocky Mountain 2013
&
SANS Boston 2013
Polls
Compared to this year, 2013 will be:
Great!
Better.
About the same.
Little worse.
FUBAR!
Recent Forum Topics
News Items and General Discussion About EH-Net
: Change is Coming to EH-Net!!
(30) by
don
Tools
: Symbolic Exploit Assistant project is looking for collaborators
(0) by
galapag0
Greetings
: Hi from the UK
(5) by
prats84
GCIH - GIAC Certified Incident Handler
: Passed my GCIH
(9) by
prats84
Network Pen Testing
: Want a challenge? Want a GXPN practice exam?
(0) by
ajohnson
GCIH - GIAC Certified Incident Handler
: GCIH Free Practice test attempt
(1) by
prats84
EH-Net News Feeds
Latest Additions
Privacy Notice
for TDCC & All Properties
© 2013 The Ethical Hacker Network
Joomla!
is Free Software released under the GNU/GPL License.