i have problem to go to link when i selected option from form that i created parser in php: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>PHP form select box example</title> <!-- define some style elements--> <style> </style> </head> <body> <form id="form_country" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post"> <label for="urlSel">Select url:</label> <select id="urlSel" name="urlSelected"> <option selected value="">Select url</option> <?php echo "--------------------------------------"."\n"; echo "<br>"; echo "\n Parser coded by kriss"."\n"; echo "<br>"; echo "\n parser website http://www.fbi.gov/ \n" ; echo "<br>"; echo "--------------------------------------"."\n"; ini_set('memory_limit','1000M'); ini_set('max_execution',0); $website="http://www.fbi.gov/"; function parse($Page){ global $website; global $fd; global $i; global $links_found; $i=1; $content=file_get_contents($website); //echo $content."<br>"; $dom=new DOMDocument(); $dom->loadhtml($content); $links=$dom->getElementsByTagName("a"); foreach ($links as $link) { $links_found=$link->getAttribute("href"); $text_found=$link->getAttribute("title"); // echo $links_found; //echo $text_found; echo "<option value='$links_found'>$links_found</option>\n"; } } parse (1); if(isset($_POST["urlSelected"])){ $goto = $_POST["urlSelected"]; if($goto!="") { header('location:' . $goto); } } ?> </select><br> <p> <input type="submit" value="Go"> </p> </form> </body> </html> PHP:
That isn't very good code, and if you had looked at the output, you'd have seen that it outputs a lot of errors, due to malformed HTML in the source (fbi.gov) - hence, to suppress errors, you'll have to include the following line right after the $dom = new DOMDocument(); libxml_use_internal_errors(true); That will prevent libxml from outputting the errors to the console (in this case, that would be the HTML-code) and the form will work. However, there are other issues with this code, which might be present due to some formatting done to shorten it for this question, but... First off, you're using a lot of globals for nothing inside the function. Globals are usually bad, and not needed. Second, you're declaring $Page, which isn't used, at all. You're also instatiating a counter inside the function, which isn't used either. Switching between single quote and double quote on variables, echoes and such is bound to come back and bite you. Avoid that. Stick with single quote on echo, and concoct strings, either using . or , Also, you shouldn't be using a transitional DOCTYPE. Stick with 4.01 Strict, or just use HTML5s <!DOCTYPE html> - it's a lot shorter and easier to remember.