bax 发表于 2013-2-11 09:44
這個下載了,但是得到的似乎是json,對json有興趣,但是不怎麽會用...能不能給個註冊會員的控制器跟視圖 ...
JSON是非常简单的,底下按照要求提供会员注册的控制器丶视图以及SDK类库。
https://github.com/a20968/UDSync_CI_SDK/blob/master/application/libraries/Udsync.php
PHP复制代码
protected $APP_ID = '' ; //Here's your APP_ID
protected $APP_KEY = '' ; //Your APP_KEY
protected $UDSync_Server = 'http://yourserver/index.php/api/' ; //HTTP Link to your UDSync application(Add /index.php/api)
protected static function curl_get_content ( $url )
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL , $url); //Set access url adress
curl_setopt($ch, CURLOPT_TIMEOUT , 5); //Set timeout
curl_setopt($ch, CURLOPT_RETURNTRANSFER , 1); //Ser return value
$r = curl_exec($ch); //Set $r
curl_close($ch); //Close curl function
return $r; //Return data
}
public function user_create ( $id , $email , $password )
{
$json = json_decode(self::curl_get_content( $this->UDSync_Server .'user/user_create/'.$id.'/'.urlencode($email).'/'.$password.'/'.$this->APP_ID.'/'.$this->APP_KEY ));
if ( $json->status == 0 )
{
return 1;
} else {
return 0;
}
}
复制代码
https://github.com/a20968/UDSync ... xample/register.php
PHP复制代码 function post_register ()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == FALSE)
{
$this->load->helper('form');
$this->load->view('register_form');
} else {
if ( $this->udsync->user_create( $this->input->post('username',TRUE) , $this->input->post('email',TRUE) , $this->input->post('password',TRUE) , md5($this->input->ip_address()) , md5($this->input->user_agent())) == 1 )
{
echo 'Register Success! <a href="/index.php/example/login">Get to Login</a>.';
} else {
echo 'Register Faild! <a href="/index.php/example/register">Try again?</a>';
}
}
} 复制代码
https://github.com/a20968/UDSync ... s/register_form.php
HTML复制代码 <html>
<?php echo form_open('/example/register/post_register'); ?>
<?php echo validation_errors(); ?>
<h5>Username </h5>
<input type="text" name="username" value="" size="50" />
<h5>Email </h5>
<input type="email" name="email" value="" size="50" />
<h5>Password </h5>
<input type="password" name="password" value="" size="50" />
<div><input type="submit" value="Submit" /></div>
</form>
</html> 复制代码
大概就是这样,JSON数据的部分可以参考这里。
https://github.com/a20968/UDSync ... A%E5%90%AB%E6%84%8F |