1

同時に 2 つの場所にログインできるフォームを作成するにはどうすればよいですか?

http://img577.imageshack.us/img577/3127/calendarlogin.jpg http://img94.imageshack.us/img94/1567/joomlalogin.jpg

これら 2 つのログイン フォームは、カレンダーと joomla サイト用です。それらは別々に機能します。それらは同じ public_html ディレクトリにあります。ログイン フォームは、2 つの個別の index.php ファイルに送信されます。フォームに一度送信するだけで、ユーザーが両方に別々にログインできるようになるといいのですが。どうやってやるの。フォーム内の 2 つにリンクする中間の php ファイルを使用することを考えていますが、方法がわかりません。

両方のフォームのユーザー名とパスワードの両方のフィールドは、すべてのユーザーに対して同じ値を使用します。

編集:うわー、簡単な解決策があるかもしれないと思いました。ログイン機能を変更してみました。十分に機能していません。カレンダーを joomla と統合するというアイデアは、少し難しいように思えます。ただし、これは、セッション タイムアウトなどを処理するための最良の方法です。

これ以上の回答はありません。もう一度質問する前に、もう少し時間をかけて何かを試してみようと思います。

編集: 問題は、サイトの両方の領域にアクセスするために 2 回ログインする必要がないことです。

4

1 に答える 1

2

私はこれを避けたいと思いますが、学術的な演習のためにこれが答えです。

<?php
$logged_in = false;
$site1_url = 'http://google.com';
$site2_url = 'http://redis.io';

if(array_key_exists('username', $_POST)
        and array_key_exists('password', $_POST)) {

    // Assume the text input fields are named the same in all three forms
    $fields = array(
        'username' => $_POST['username'],
        'password' => $_POST['password'],
    );

    // Access the first site
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $site1_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    $output1 = curl_exec($ch);
    curl_close($ch);

    // Access the second site
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $site2_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    $output2 = curl_exec($ch);
    curl_close($ch);

    if(strpos($output1, 'Logged In') and
            strpos($output2, 'Signed In')) {
        // set logged_in to true only when the appropriate strings are found
        // in the pages we have just posted onto so that we know that the logins
        // were actually successful.
        $logged_in = true;
    }
}
if(false === $logged_in):
    ?>
    <form action="" method="post">
        <label for="username">Username</label>
        <input type="text" name="username" id="username" value="" />

        <label for="password">Password</label>
        <input type="password" name="password" id="password" />

        <input type="submit" />
    </form>
<?php else: ?>
    <p>You are now logged into the website.</p>
    <p>To access the sites try:</p>
    <ul>
        <li><a href="<?php htmlentities($site1_url); ?>"><?php htmlentities($site1_url); ?></a>
        <li><a href="<?php htmlentities($site2_url); ?>"><?php htmlentities($site2_url); ?></a>
    </ul>
<?php endif; ?>
于 2011-07-28T14:10:27.987 に答える