2012-11-09 2 views
0

lightopenid를 사용하는 Google 오픈 ID 로그인 - 가입 시스템을 구현했습니다. 사용자가 한 번만 가입해야하는 기능을 추가하고 싶습니다. 자신의 정보에 액세스 할 수있게하려면 로그인 정보를 데이터베이스에 저장해야합니다.정보가있는 정보와 함께 정보를 입력 한 다음 데이터베이스 정보로 로그인하십시오.

정보 (신원, 이름, 전자 메일)를 받으면 데이터베이스에 다시 저장하여 정보를 액세스 할 수 없도록 사용자를 건너 뛰는 것을 제외하고는 동일한 프로세스를 통해 나중에 로그에 저장합니다.

즉 사용자가 가입하여 정보에 대한 액세스 권한을 부여받은 경우 다음 번 이후에 사용자가 로그인 할 때마다 액세스 권한을 부여하지 않아도됩니다.

구현하려면 데이터베이스에 로그인하려고 시도 할 때 ID를 확인합니다. ID가 존재하면 Lightopenid에 정보를 묻지 않고 로그인합니다. ID가 데이터베이스에 저장할 정보를 한 번 묻지 않으면 로그인하십시오. 나중에 로그인 사용.

데이터베이스에서 신원을 확인할 수 있지만 로그인 할 때 lightopenid의 정보를 요청하지 않았기 때문에 신원이 자신의 정보가 아닌 경우 해당 정보를 묻는 방법은 파트에 갇혀 있습니다.

한 번에 정보를 저장하는 코드입니다. (회원 가입)

$openid = new LightOpenID('localhost'); 
    if(!$openid->mode) { 
    if(isset($_GET['login'])) { 
     $openid->identity = 'https://www.google.com/accounts/o8/id'; 
     $openid->required = array('namePerson/first', 'namePerson/last', 'contact/email'); 
     header('Location: ' . $openid->authUrl()); 
    } 
} 
if($openid->validate()) { 
    require_once('../connect.php'); 
    $identity = $openid -> identity; 
    $info = $openid->getAttributes(); 
    $username = $info['namePerson/first'].'.'.$info['namePerson/last']; 
    $open_id = explode('=', $identity); 
    $identity_hash = $open_id[1]; 
    $email = $info['contact/email']; 

    $query = "INSERT INTO user_login (username, identity_hash, email) VALUES ('$username', '$identity_hash', '$email')"; 
    $create_user = mysqli_query($connection, $query) or trigger_error(mysqli_error($connection), E_USER_ERROR); 
} 

의 신원을 확인하는 코드입니다. (로그인)

if(!$openid->mode) { 
    if(isset($_GET['login'])) { 
     $openid->identity = 'https://www.google.com/accounts/o8/id'; 
     header('Location: ' . $openid->authUrl()); 
    } 
} 
if($openid->validate()) { 
    require_once('../connect.php'); 
    $identity = $openid -> identity; 
    $open_id = explode('=', $identity); 
    $identity_hash = $open_id[1]; 
    $query = "SELECT * FROM user_login WHERE identity_hash='$identity_hash'"; 
    $result = mysqli_query($ulconnection, $query) or trigger_error(mysqli_connect_error(), E_USER_ERROR); 

    if($result){ 
    $row = mysqli_fetch_assoc($result); 
    $username = $row['username']; 
    $email = $row['email']; 
    echo $username.'<br />'; 
    echo $email.'<br />'; 
    } 
    else{ 
    // how to ask for info here. 
    } 
} 

가보고 할 모든 가능한 방법을 제안하십시오 그것.

감사합니다.

답변

0

이렇게하면됩니다.

if($result){ 
    $row = mysqli_fetch_assoc($result); 
    $username = $row['username']; 
    $email = $row['email']; 
    echo $username.'<br />'; 
    echo $email.'<br />'; 
    } 
    else{ 
    header("Location: signup.php?login"); 
    } 

다른 사람들에게도 도움이되기를 바랍니다.

관련 문제