Loading...
Не проходит авторизация через соц сети,где может быть ошибка?




<?php


if(!isset($_SESSION))
{

session_name('SESS');

session_start();
}

Class DB {

protected static $getInstance;

public static function run() {
if( !isset( self::$getInstance ) ) {
try {

define('HOST', 'localhost');
define('NAME', 'db1487185931');
define('USER', 'db1487185931');
define('PASS', 'пароль');

self::$getInstance = new \PDO('mysql:dbname=' . NAME . ';host=' . HOST, USER, PASS);

} catch( PDOException $error ) {
exit( $error->getMessage() );
}
}
return self::$getInstance;
}

final public function __destruct() {
self::$getInstance = null;
}

}


if (isset($_POST['token'])){
$s = file_get_contents('http://ulogin.ru/token.php?token=' . $_POST['token'] . '&host=' . $_SERVER['HTTP_HOST']);$_POST['loginAPI'] = true; }

if(isset($_POST['token'])) $users = json_decode($s, true);

if(isset($_POST['token']) && !isset($user) && $users['network'] && $users['identity'] && $_POST['loginAPI'] == true){

$stmt = DB::run()->prepare('SELECT `type_reg`, `identity` FROM `kolhoz_user` WHERE `type_reg` = :type_reg AND `identity` = :identity LIMIT 1');
$stmt->execute(
array(
':type_reg' => $users['network'],
':identity' => $users['identity'] ));
$fetch_users = $stmt->fetch();

if($fetch_users == false){

if ($users['network'] == 'odnoklassniki')
$idi = 'ok';
else
$idi = null;


$identity = $users['identity'];
$identity = str_replace('http://www.facebook.com', '', $identity);
$identity = str_replace('http://openid.yandex.ru', '', $identity);
$identity = str_replace('http://vk.com', '', $identity);
$identity = str_replace('http://odnoklassniki.ru', '', $identity);
$identity = str_replace('http://my.mail.ru/mail', '', $identity);
$identity = str_replace('/', '', $identity);
$identity = str_replace('.', '', $identity);
$identity = $idi . $identity;
$password = sha1(mt_rand(1111111,99999999).time());


$stmt = DB::run()->prepare('SELECT `nick` FROM `kolhoz_user` WHERE `nick` = :nick LIMIT 1');
$stmt->execute(
array(':nick' => $identity));

if($stmt->fetch() == true)
$identity = $identity . '_' . rand(0000, 9999);

$stmt = DB::run()->prepare('INSERT INTO `kolhoz_user` (`nick`, `password`, `money`, `rubies`, `identity`, `type_reg`) VALUES (:nick, :password, :money, :rubies, :identity, :type_reg) ');
$stmt->execute(
array(
':nick' => $identity,
':password' => $password,
':money' => '10000',
':rubies' => '10000',
':identity' => $users['identity'],
':type_reg' => $users['network']));


$_SESSION['id_user'] = DB::run()->lastInsertId();
header('Location: /');
exit;
} else {


$stmt = DB::run()->prepare('SELECT * FROM `kolhoz_user` WHERE `type_reg` = :type_reg AND `identity` = :identity LIMIT 1');
$stmt->execute(
array(
':type_reg' => $users['network'],
':identity' => $users['identity']));

$user = $stmt->fetch();

$_SESSION['id_user'] = $user['id'];
header('Location: /');
exit;

}
}
?>
ссылку прописал свою?
DR7777 (22.02.2017 в 01:45)
ссылку прописал свою?

Да
Онлайн: 3
Время:
Gen. 0.0658
(c) Bym.Guru 2010-2026