简体   繁体   中英

Load page and submit form inside PHP

I'm creating an system that uses online compiler. IDEONE give me this feature (throgh an Web Service), but with a price for an high volume of compilations.

Then I'm trying to use codepad , but it doesn't have an Web Service... codepad has an initial page, and clicking it's submit button, apparently the same page loads (the form's action is "/")...

I'm using curl to load page, but I'm getting "Internal Server Error". This is my code: pastebin Code , I'm using 000webhost, I don't know if i did something wrong or if my webserver doesn't support it.

Have you trued removing the TIMEOUT? or maybe extending it?

Try this maybe:

<html>
<div align="center">
    <form action="compilador.php" method="POST">
        <textarea id="source" name="source"></textarea>
        <input type="submit" value="Enviar" />
<?php
    if(isset($_POST['source']) && $_POST['source'] != "")
    {
       $ch = curl_init();

 /**
 * Set the URL of the page or file to download.
 */
 curl_setopt($ch, CURLOPT_URL, "http://codepad.org");

 /**
 * Ask cURL to return the contents in a variable instead of simply echoing them to  the browser.
 */
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$post_data=$_POST;

        $post_data['lang'] = 'C';
        $post_data['private'] = True;
        $post_data['run'] = True;

        foreach($post_data as $key => $value)
        {
            $post_items[] = $key . '=' . $value;
        }
        $post_string = implode ('&', $post_items);

        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);

        $result = curl_exec ($ch);

 /**
 * Close cURL session
 */
 curl_close($ch);

        echo "<br /><br />RESULT: {".$result."}";
    }

    ?>
    </form>
</div>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM