如何实现PHP代码到HTML按钮?

时间:2015-04-15 16:36:20

标签: php html

$no = $_POST['no'];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "http://www.example.com");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $exec = curl_exec ($ch);

请参阅我要将此代码实现为此html代码<p><input name="submit" id="submit" type="submit" value="Submit" /></p></form>当用户按提交时,该程序应该启动..

我尝试使用此if(isset($_POST['submit'])&&isset($_POST['no'])) ($ch); 但它没有工作它只是重复没有$ no。 任何帮助,将不胜感激。 感谢。

1 个答案:

答案 0 :(得分:1)

我在您发布的代码中添加了评论,以使其更加清晰。虽然谷歌搜索中很容易找到很多这样的内容。

 //Call a function called error_reporting with a parameter with the value of 0.
error_reporting(0); 

//If the user does not have a cookie with the name 'count'
if (!isset($_COOKIE['count'])) {
    //set the cookie 'count' to equal 1
    $cookie = 1;
    setcookie("count", $cookie);
//If the user does have the cookie
} else {
    //increase the number value of the cookie by one
    $cookie = ++$_COOKIE['count'];
    setcookie("count", $cookie);
    //assign the number to the $count variable
    $count = $_COOKIE['count'];
}

//Get the value of the post variable, and assign it to $no
$no = $_POST['no'];
//Create a new session (http://php.net/manual/en/function.curl-init.php)
$ch = curl_init();
//Set some options for the session (http://php.net/manual/en/function.curl-setopt.php)
curl_setopt($ch, CURLOPT_URL, "http://www.example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//execute the session (http://php.net/manual/en/function.curl-exec.php)
$exec = curl_exec ($ch);

//immediately redirect a user to http://example.com/index.php
//the url has a get parameter with the value of the $no variable
header ("Refresh: 0;url=http://example.com/index.php?m=$no");