Jump to content

Creating a password field and linking up?


Porkie

Recommended Posts

Ive used a bit of a script to help me with being able to post messages from my website to my twitter. The problem is a only want certain people to be able to access it with a password field. So if they were to get the password and type it it then they could post but without the password they couldnt.

 

So basically they type in there message and a password, if the password is correct then post is created otherwise error. Any help will be appreciated.

 

<?php
/* ---------------------------------------- */
// Change these parameters with your Twitter 
// user name and Twitter password.
/* ---------------------------------------- */
$twitter_username ='yourTwitterUserName';
$twitter_psw ='yourTwitterPassword';
/* ---------------------------------------- */

/* Don't change the code belove
/* ---------------------------------------- */
require('twitterAPI.php');
if(isset($_POST['twitter_msg'])){
$twitter_message=$_POST['twitter_msg'];
if(strlen($twitter_message)<1){ $error=1; } else { $twitter_status=postToTwitter($twitter_username, $twitter_psw, $twitter_message); } }
/* ---------------------------------------- */ 
?>

 

I have created the field on the form page. what would i need to do on this page to check the password field is correct before posting?

 

 

Link to comment
Share on other sites

<?php
  //Variables
  $twitter_username = 'yourTwitterUserName';
  $twitter_psw = $_POST['password'];
  $twitter_message=$_POST['twitter_msg'];

echo '<form method="post" action="">
      <input type="password" name="password">
      <input type="text" name="twitter_msg">
      <input type="submit" name="submit" value="Submit">
      </form>';

if (!empty($_POST['password']) && !empty($_POST['twitter_msg'])) {
   //Require the API
   require('twitterAPI.php');
   
   if(isset($_POST['twitter_msg'])){
       
        if(strlen($twitter_message)<1){
                    $error=1;
                } else { 
                    $twitter_status=postToTwitter($twitter_username, $twitter_psw, $twitter_message); 
        } 
    }

} else {
    echo 'Password and message cannot be left blank.';
}
?>

 

Something like that?

Link to comment
Share on other sites

i arent sure whether that will work because the code worked but now ive editted the form on this page to have a password field which will be pre set and if the password doesnt match up with the preset password then it will not post the comment otherwise it will.

 

 

<!-- Send message to Twitter -->
<?php 
if(isset($_POST['twitter_msg']) && !isset($error)){?>
<div class="msg"><?php echo $twitter_status ?></div>
<?php } else if(isset($error)){?>
<div class="msg">Error: please insert a message!</div>
<?php }?>
<p><strong>What are you doing?</strong></p>
<form action="insertTwitterMsg.php" method="post">
<input name="twitter_msg" type="text" id="twitter_msg" size="40" maxlength="140"/>
[b]<input name="password type="text" id="password" size="10"[/b]
<input type="submit" name="button" id="button" value="post" />
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.