how to put header authentication into a form using php?

Posted by SkyWookie on Stack Overflow See other posts from Stack Overflow or by SkyWookie
Published on 2009-07-02T19:31:17Z Indexed on 2010/05/25 6:11 UTC
Read the original article Hit count: 224

Filed under:
|
|
|
|

Hey guys, for the page I am doing needs a login authentication using Twitter (using tweetphp API). For test purposes I used this code below to do a successful login:

if (!isset($_SERVER['PHP_AUTH_USER'])){
header('WWW-Authenticate: Basic realm="Enter your Twitter username and password:"');
header('HTTP/1.0 401 Unauthorized');
    echo 'Please enter your Twitter username and password to view your followers.';
   exit();
   }

$username = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];

The problem now is, I want to integrate it into a form, so far I have the following:

<form action="logincheck.php" method="post" class="niceform"  >
    <fieldset>
        <legend>Twitter Login:</legend>
        <dl>
            <dt><label for="email">Twitter Username:</label></dt>
            <dd><input type="text" name="username" id="username" size="32" maxlength="128" /></dd>
        </dl>
        <dl>
            <dt><label for="password">Password:</label></dt>
            <dd><input type="password" name="password" id="password" size="32" maxlength="32" /></dd>
        </dl>
            </fieldset>

            <fieldset class="action">
        <input type="submit" name="submit" id="submit" value="Submit" />

I am sending it to logincheck.php, this is where I think I get stuck. I am not sure how to compare the form data with Twitter's login data. I was trying a similar if statement as I used in the first code (box that pops up before page loads), but I couldn't wrap my head around it. Thanks again guys!

© Stack Overflow or respective owner

Related posts about php

Related posts about html