我怎么能修复这个自动增量?

时间:2014-01-30 03:56:41

标签: php pdo auto-increment steam-web-api

所以,这是我通过steam id登录的问题,它在我的网站上创建了一个帐户,但它也决定在下一次登录时跳过自动增量,导致下一个注册会员获得大量的自动增量会员ID

Database layout

<?php
require ("common.php");

class SteamSignIn
{
const STEAM_LOGIN = 'https://steamcommunity.com/openid/login';

public static function genUrl($returnTo = false, $useAmp = true)
{
    $returnTo = (!$returnTo) ? (!empty($_SERVER['HTTPS']) ? 'https' : 'http') .  '://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] : $returnTo;

    $params = array(
        'openid.ns'         => 'http://specs.openid.net/auth/2.0',
        'openid.mode'       => 'checkid_setup',
        'openid.return_to'  => $returnTo,
        'openid.realm'      => (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'],
        'openid.identity'   => 'http://specs.openid.net/auth/2.0/identifier_select',
        'openid.claimed_id' => 'http://specs.openid.net/auth/2.0/identifier_select',
    );

    $sep = ($useAmp) ? '&amp;' : '&';
    return self::STEAM_LOGIN . '?' . http_build_query($params, '', $sep);
}

public static function validate()
{
    $params = array(
        'openid.assoc_handle'   => $_GET['openid_assoc_handle'],
        'openid.signed'         => $_GET['openid_signed'],
        'openid.sig'            => $_GET['openid_sig'],
        'openid.ns'             => 'http://specs.openid.net/auth/2.0',
    );

    $signed = explode(',', $_GET['openid_signed']);
    foreach($signed as $item)
    {
        $val = $_GET['openid_' . str_replace('.', '_', $item)];
        $params['openid.' . $item] = get_magic_quotes_gpc() ? stripslashes($val) : $val; 
    }

    $params['openid.mode'] = 'check_authentication';

    $data =  http_build_query($params);
    $context = stream_context_create(array(
        'http' => array(
            'method'  => 'POST',
            'header'  => 
                "Accept-language: en\r\n".
                "Content-type: application/x-www-form-urlencoded\r\n" .
                "Content-Length: " . strlen($data) . "\r\n",
            'content' => $data,
        ),
    ));

    $result = file_get_contents(self::STEAM_LOGIN, false, $context);


    preg_match("#^http://steamcommunity.com/openid/id/([0-9]{17,25})#", $_GET['openid_claimed_id'], $matches);
    $steamID64 = is_numeric($matches[1]) ? $matches[1] : 0;

    return preg_match("#is_valid\s*:\s*true#i", $result) == 1 ? $steamID64 : '';
}
}

$steam_login_verify = SteamSignIn::validate();
if(!empty($steam_login_verify))
{
// Grab Data From Steam API
    $json = file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' .  $sapik . '&steamids='. $steam_login_verify .'&format=json');
//Decode Data From Steam API
    $data = json_decode($json);
foreach($data->response->players as $player)
{
    $query = "INSERT INTO steam (steamid, personaname, profileurl, avatar, avatarmedium, avatarfull ) VALUES ( :steamid, :personaname, :profileurl, :avatar,   :avatarmedium, :avatarfull) "; 
    $query_params = array( 
        ':steamid' => $player->steamid, 
        ':personaname' => $player->personaname, 
        ':profileurl' => $player->profileurl, 
        ':avatar' => $player->avatar, 
        ':avatarmedium' => $player->avatarmedium, 
        ':avatarfull' => $player->avatarfull, 
        );

}

                try 
    { 
        $stmt = $db->prepare($query); 
        $result = $stmt->execute($query_params); 
    } 
    catch(PDOException $ex) 
    { 
    switch( $ex->errorInfo[1] )
 {
     case 1062:
        $ps = $db->prepare("SELECT * FROM `steam` WHERE steamid = :sid");
        $ps->bindParam(':sid', $steam_login_verify);
        $ps->execute();
        $ps->setFetchMode(PDO::FETCH_ASSOC);
        foreach ($ps as $row)
            {
                $_SESSION['sid'] = $row['steamid'];
            }

            header('Location:'.$basedir);
            die('redirecting to'.$basedir);
        ;

}
    }
    $ps = $db->prepare("SELECT * FROM `steam` WHERE steamid = :sid");
    $ps->bindParam(':sid', $steam_login_verify);
    $ps->execute();
    $ps->setFetchMode(PDO::FETCH_ASSOC);
    foreach ($ps as $row)
    {
        $_SESSION['sid'] = $row['steamid'];
    }

    header('Location:'.$basedir);
    die('redirecting to'.$basedir);
} else { 

$steam_sign_in_url = SteamSignIn::genUrl();
}

0 个答案:

没有答案