php登陆其他网站查看数据是否正确

php login on other website and see if data is correct

我正在做一个网站,遇到了很多问题。

小说明(带假地址),

我有一个网站,www.website1.com,里面有很多好的编码内容;)。现在您可以登录此网站,但使用 www.website2.com。因此,当您登录时,您看到的是 www.website1.com 登录页面,但您是在 www.website2.com 上登录的。

现在我研究了一下,发现了cURL。但是有我的问题。 不仅我希望人们登录 www.website2.com。我还保存用户名,邮箱地址,以便在 www.website1.com.

上使用

这在 HTML/PHP/cURL 内可能吗?如果是,怎么做?

提前致谢。

PS:这是我关于Whosebug的第一个问题。我希望一切都好:D.

编辑: 我自己使用 cURL 做了一些东西,但它有一些问题。 index.php(网站 1)

<?php
$username="user1"; 
$password="password1"; 
$url="http://localhost/AAWebsite/test/action.php"; 
$cookie="cookie.txt"; 

$postdata = "email=".$username."&password=".$password."&submit=submit"; 

$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt ($ch, CURLOPT_REFERER, $url); 

curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$result = curl_exec ($ch); 

echo $result;  
curl_close($ch);
?>

login.php(网站 2)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Login</title>
    </head>
    <body>
        <?php if(isset($_SESSION['username'])): ?>
            <p>You are logged in as <?=$_SESSION['username']?></p>
            <p><a href="?logout=1">Logout</a></p>
        <?php endif; ?>
<form method='post' action='action.php'>
    Email Address: <input type='text' name='email'>
    Password: <input type='password' name='password'>
    <button name="submit" value="submit">Submit</button>
</form>
    </body>
</html>

action.php(网站 2)

<?php
    $user = $_POST['email'];
    $pass = $_POST['password'];

    if($user == ''){
        header("Location: index.php?error=email_missing");
    };

    if($pass == ''){
        header("Location: index.php?error=password_missing");
    };


    $result = filter_var( $user, FILTER_VALIDATE_EMAIL );
    if(!$result == $user){
        header("Location: index.php?error=email");

    } else { 


        header("Location: index.php"); }
?>

zindex.php(网站 2)

index site

现在的问题是,您是从 index.php 登录的。但是你卡在 action.php 上了。有什么办法可以解决这个问题?

如果我没看错,我会使用 PHP:

我要使用一些示例代码

登录php:

<form action="http://www.domain1.com/test/redirect.php"  method="post">
Login Details:</br>
<input type="text" name="name" value="<?=$name?>" /></br>
<input type="text" password="password" value="<?=$password?>" /></br>
<button name="Submit" value="Submit">login</button>
</form>

并在重定向页面中将登录功能从 site1 登录到 site1,重定向到 site2 登录验证页面以在 site2 上登录并返回 site1(如果您愿意或留在 site2 由您决定)

在重定向时我会使用 GET 将数据发送到 site2 (最好先加密数据)

redirect.php

if(!empty($_POST) && isset($_POST['user']) && isset($_POST['password'])){
    $user= query("SELECT * FROM ".USERS." WHERE user = '".$_POST['user']."' AND password= '".$_POST['password']."'");
    if($user->num_rows == 1){
        $_SESSION['uid'] = $user->fetch_assoc();
        header("Location: http://www.site2.com/getsite1.php?user=$_POST['user']&&password=$_POST['password']");
    }
    else{
        unset($_SESSION['uid']);
        header("Location: index.php?msg=Invalid Username or Password.");
    }
}

on getsite1.php in site2 我将使用一些类似的代码登录 site2,然后重定向回 site1 或留在 site2

不是最好的解决方案,但我会在找到更永久的解决方案之前使用它