Results 1 to 9 of 9

Thread: [Resolved] List All Requests

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    [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.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    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.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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_varsarray_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.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: List All Requests

    Thanks dude, but when I try to run this, I get a fair few errors:

    PHP Code:
    Warningarray_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

    Warningarray_merge() [function.array-merge]: Argument #1 is not an array in /home/user/public_html/get_all_request.php on line 13

    Warningksort() 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();")

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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_varsarray_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"

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: List All Requests

    Perfect!

    Thanks heaps penagate!

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    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
  •  



Click Here to Expand Forum to Full Width