0

I'm getting Message: Invalid argument supplied for foreach()

on this line foreach($element->action as $URI){ // find action="" attr of <form> element

My code is a nested foreach() loop:

           $siteToSearch = file_get_html($prefix.$sss);
                foreach($siteToSearch->find('form') as $element){ // find <form> element
                    foreach($element->action as $URI){ // find action="" attr of <form> element
                        $submit_vars["name"] = "' OR ''='";                     
                        $submit_vars["passwd"] = "' OR ''='";                   
                        $submit_vars["submit"] = "Submit";  
                        $snoopy->submit($URI,$submit_vars);
                        echo "response code: ".$snoopy->response_code."<br>\n";
                        print $snoopy->results;
                    }
   }

I tried defining $URI on the first line as $URI = $element->action; but this doesnt seem to fix it

2
  • Why is this nested loops? The outer loop seems to be looping through all the <form> elements, but the inner loop only makes sense if you're assuming each <form> might have multiple actions. Commented Feb 14, 2013 at 5:02
  • Great point john. Could you post this as an answer ? Commented Feb 14, 2013 at 14:43

2 Answers 2

1

You get the "Invalid argument supplied for foreach()" message when the argument (here it's, $element->action) isn't an array (or something array-like).

I think the problem here is that you really don't need the inner foreach loop at all. $element->action seems to be representing the "action" attribute of an HTML form element. Each form will only have one action, which will probably be represented in PHP as a string, not an array.

Taking out the inner loop and simply adding a line like you mentioned, $URI = $element->action, should fix this problem.

Sign up to request clarification or add additional context in comments.

1 Comment

Great idea, got confused in my own logic here.Thanks!!
0

please check that $element->action have some value or not please use print_r( $element); after the first loop and please put the inner loop in the contion ==>if($element->action) { }

the code will be something like given below

$siteToSearch = file_get_html($prefix.$sss); foreach($siteToSearch->find('form') as $element){ // find <form> element if($element->action) { foreach($element->action as $URI){ // find action="" attr of <form> element $submit_vars["name"] = "' OR ''='";
$submit_vars["passwd"] = "' OR ''='";
$submit_vars["submit"] = "Submit";
$snoopy->submit($URI,$submit_vars); echo "response code: ".$snoopy->response_code."<br>\n"; print $snoopy->results; } } }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.