Home > Backend Development > PHP Tutorial > 这种怎么完整写出来求大神指教

这种怎么完整写出来求大神指教

WBOY
Release: 2016-06-13 12:00:44
Original
913 people have browsed it

这种如何完整写出来求大神指教
这种一般是双方约定一个key,然后md5后传过去验证
例:
发送方:
$key='123456789';//双方约定并保密
$time = time();
$token = md5($key.$time);
 file_get_contents("www.baidu.com/api/api.php?time=".$time."&token=".token);

接收方:
$time = $_GET['time'];
$token= $_GET['token'];
$key = '123456789';//与上面保持一样
if( md5($key.$time) == $token )
{ echo "true"; }
else{ echo "false"; }

怎么写服务端和客户端求大神写范例
------解决方案--------------------
client.php

<br />$key='123456789';//双方约定并保密<br />$time = time();<br />$token = md5($key.$time);<br />$data = file_get_contents("http://www.baidu.com/api/api.php?time=".$time."&token=".$token);<br />$result = json_decode($data, true);<br /><br />if($result['success']){<br />	echo 'success';<br />}else{<br />	echo 'fail';<br />}<br />
Copy after login


api.php
<br />$time = isset($_GET['time'])? $_GET['time'] : '';<br />$token= isset($_GET['token'])? $_GET['token'] : '';<br />$key = '123456789';//与上面保持一样<br /><br />$ret = array();<br /><br />if(md5($key.$time)==$token){<br />	$ret['success'] = true;<br />}else{<br />	$ret['success'] = false;<br />}<br /><br />header('content-type:application/json;charset=utf8');<br /><br />echo json_encode($ret);<br />
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template