|
-
Sep 5th, 2008, 05:47 AM
#1
Thread Starter
Fanatic Member
[Resolved] List All Requests
Would any one happen to know a code that put all the requests from a form into an array?
So instead going:
PHP Code:
$_REQUEST['txtName']
$_REQUEST['txtAge']
You could just go :
PHP Code:
$allRequests[2]
Doesn't have to be secure, it's for testing only.
That way I can out put all the requests.
It would be nice to be able to determine whether they are gets or posts. But not required.
Looking though google didn't help .
Last edited by Slyke; Sep 7th, 2008 at 08:10 AM.
-
Sep 5th, 2008, 08:23 AM
#2
Re: List All Requests
Would any one happen to know a code that put all the requests from a form into an array?
That's what $_REQUEST is!
Explain more.
-
Sep 7th, 2008, 02:21 AM
#3
Thread Starter
Fanatic Member
Re: List All Requests
Yeah, but it's tricky !
Say if I submitted a form (using get) with these:
txtName=MYNAME&txtAge=13&rdoSex=on&txtFlower=my+favourite+flower&txtWords=
And posted these:
txtCharacter=thecharacter
Some are blank and some aren't.
How can I get the PHP script to output something like:
txtName(get) = MYNAME
txtAge(get) = 13
rdoSex(get) = on
txtFlower(get) = my favourite flower
txtCharacter(post) = thecharacter
txtWords(get) =
I believe it would have to loop though the $_POST and $_GET array, to get the difference. But doing this is the trouble, I don't know how to find the upper and/or lower of these arrays (Probably because they don't use numbers) or how to loop through them because of this.
-
Sep 7th, 2008, 05:36 AM
#4
Re: List All Requests
Here's an attempt:
PHP Code:
header('Content-type: text/plain');
$request_vars = array_merge( array_combine( array_map(create_function('$k', 'return $k."(get)";'), array_keys($_GET)), array_values($_GET) ), array_combine( array_map(create_function('$k', 'return $k."(post)";'), array_keys($_POST)), array_values($_POST) ) );
ksort($request_vars);
foreach ($request_vars as $k => $v) echo $k.' = '.$v."\n";
I am sure this can be improved.
-
Sep 7th, 2008, 05:49 AM
#5
Re: List All Requests
Better:
PHP Code:
$request_vars = array();
foreach (array( 'get' => $_GET, 'post' => $_POST, 'cookie' => $_COOKIE ) as $source => $vars) { $request_vars = array_merge($request_vars, array_combine( array_map(create_function('$k', 'return $k."('.$source.')";'), array_keys($vars)), array_values($vars) )); }
ksort($request_vars);
foreach ($request_vars as $k => $v) echo $k.' = '.$v."\n";
Last edited by penagate; Sep 7th, 2008 at 07:54 AM.
-
Sep 7th, 2008, 07:43 AM
#6
Thread Starter
Fanatic Member
Re: List All Requests
Thanks dude, but when I try to run this, I get a fair few errors:
PHP Code:
Warning: array_combine() [function.array-combine]: Both parameters should have at least 1 element in /home/user/public_html/get_all_request.php on line 13
Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/user/public_html/get_all_request.php on line 13
Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/user/public_html/get_all_request.php on line 13
Warning: ksort() expects parameter 1 to be array, null given in /home/user/public_html/get_all_request.php on line 16
Warning: Invalid argument supplied for foreach() in /home/user/public_html/get_all_request.php on line 18
Line 3 starts of the code you gave me (ie line 3 = "$request_vars = array();")
-
Sep 7th, 2008, 07:59 AM
#7
Re: List All Requests
Oh... perhaps there are no cookies.
Try this:
PHP Code:
$request_vars = array();
foreach (array( 'get' => $_GET, 'post' => $_POST, 'cookie' => $_COOKIE ) as $source => $vars) { if (is_array($vars) && count($vars) > 0) $request_vars = array_merge($request_vars, array_combine( array_map(create_function('$k', 'return $k."('.$source.')";'), array_keys($vars)), array_values($vars) )); }
foreach ($request_vars as $k => $v) echo $k.' = '.$v."\n";
-
Sep 7th, 2008, 08:07 AM
#8
Thread Starter
Fanatic Member
Re: List All Requests
Perfect!
Thanks heaps penagate!
-
Sep 7th, 2008, 08:10 AM
#9
Thread Starter
Fanatic Member
Re: [Resolved] List All Requests
I would rep you, but it says I must spread it around a bit first!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|