<?php
header("content-type:text/html;charset=utf-8");
session_start();
error_reporting(0);
require "../myadmin/sql.php";
if(isset($_POST['user2'])){$username=$_POST['user2'];}else{exit;}
if(isset($_POST['password2'])){$pass=$_POST['password2'];}else{exit;}
isset($_SERVER['HTTP_X_FORWARDED_FOR'])?$ip = $_SERVER['HTTP_X_FORWARDED_FOR']:$ip = $_SERVER['REMOTE_ADDR'];
if($ip=="127.0.0.1"){
    $dizhi="欢迎测试的朋友！";
}else{
     $ch = curl_init();
     curl_setopt($ch,CURLOPT_URL,"http://ip.taobao.com/service/getIpInfo.php?ip=$ip");
     curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
     curl_setopt($ch,CURLOPT_HEADER,0);
     $ip2=curl_exec($ch);
     $ip_js=json_decode($ip2,true);
     $dizhi="欢迎来自".$ip_js['data']['region'].$ip_js['data']['city']."的朋友";
     curl_close($ch);
}
$sql2="select * from user where username='{$username}' and password='{$pass}'";
if(mysql_num_rows(mysql_query($sql2))>0){
    $_SESSION['username']=$username;
    $_SESSION['dizhi']=$dizhi;
    echo "<script>alert('登陆成功');location='user_index.php';</script>";
}else{
    echo "<script>alert('登陆失败');location='../index.php';</script>";
}
?>