本文主要是介绍PHP cURL学习-普通话等级考试查询,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
大二学了一下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">
<?phpheader("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 );//请求方式为postcurl_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、效果截图
这篇关于PHP cURL学习-普通话等级考试查询的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!