大二学了一下PHP cURL,做了几个demo。
1、代码如下:
index.html
<html>
<head>
<title>普通话等级考试查询</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="description" content="普通话等级考试查询">
<style type="text/css">
*{margin: 0;padding: 0;border: 0;}
body{background-color: rgb(240,240,240);font-family: Microsoft YaHei;}
.mandarin_p{width: 100%;height: 50px;margin: 20px auto;background-color: rgb(255,255,255);}
.mandarin_input{width: 100%;height: 50px;float: left;display: block;padding-left: 10%;font-family: Microsoft YaHei;outline: none;}
.mandarin_sub{width: 100%;height: 50px;margin: 20px auto;}
.mandarin_btn{display: block;margin: 0 auto;width: 95%;height: 100%;font-family: Microsoft YaHei;background-color: rgb(90,215,0);color: #fff;font-size: 16px;}
</style>
</head>
<body>
<form method="post" action="mandarin_query.php">
<p align="center" style="font-size: 12px;margin-top: 20px;">请至少输入你的姓名、准考证号、身份证号中任意两项</p>
<p class="mandarin_p">
<input class="mandarin_input" name="name" type="text" placeholder="考生姓名" maxlength="30" value="">
</p>
<p class="mandarin_p">
<input class="mandarin_input" name="stuID" type="number" placeholder="准考证号" maxlength="30" value="">
</p>
<p class="mandarin_p">
<input class="mandarin_input" name="idCard" type="text" placeholder="身份证" maxlength="30" value="">
</p>
<p class="mandarin_sub">
<input id='show-toast' class="mandarin_btn" type="submit" value="查询" οnclick="return form_onsubmit(this.form)" />
</p>
</form>
<script type="text/javascript">
function form_onsubmit(obj)
{
if(obj.name.value == "" && obj.stuID.value =="" && obj.idCard.value == "") {
alert("亲~请至少输入任意两项!");
return false;
}
if(obj.name.value !== "" && obj.stuID.value =="" && obj.idCard.value == "") {
alert("亲~请至少输入任意两项!");
return false;
}
if(obj.name.value == "" && obj.stuID.value !=="" && obj.idCard.value == "") {
alert("亲~请至少输入任意两项!");
return false;
}
if(obj.name.value == "" && obj.stuID.value =="" && obj.idCard.value !== "") {
alert("亲~请至少输入任意两项!");
return false;
}
else{
// $(document).on("click", "#show-toast", function() {
// $.toast("操作成功", function() {
// console.log('close');
// });
// })
return true;
}
}
</script>
</body>
</html>
<p align="center" style="font-size: 12px;margin-top: 20px;">by 赛亚王子_Vegeta</p>
mandarin_query.php
<meta charset="utf-8">
<?php
header("Content-type:text/html,charset=utf8");
$url = 'http://www.cltt.org/StudentScore/ScoreResult';
$name = $_POST['name'];
$stuID = $_POST['stuID'];
$idCard = $_POST['idCard'];
$data = array (
'name' => $name,
'stuID' => $stuID,
'idCard' => $idCard
);
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt ($ch, CURLOPT_POST, 1 );//请求方式为post
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data );//post传输的数据
curl_setopt ($ch, CURLOPT_REFERER, 'http://www.cltt.org/studentscore');
$contents = curl_exec($ch);
curl_close($ch);
print_r($contents);
?>
2、效果截图
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/151243.html