Jump to content

Using SESSION to store IMAP details??


gaza165

Recommended Posts

I have created a login form for users to log into their IMAP email account, I am using sessions to store log in credientials to make connection to IMAP in other instances.

 

<?php
session_start();

Function ShowLoginForm() {

echo "<form action='$PHP_SELF?what=login' method='POST'>";
echo "Username: <input type='text' name='user'>";
echo "Password: <input type='password' name='pass'>";
echo "<input type='submit' value='Login'>";
echo "</form>";

}

Function ProcessLogin() {

$user = $_POST['user'];
$pass = $_POST['pass'];

$_SESSION['username'] = $user;
$_SESSION['password'] = $pass;

$mailbox = "imap.gmail.com:993/imap/ssl";
$conn = @imap_open("{" . $mailbox . "}INBOX", $user, $pass) or header("Location:./");

if($conn) { 
header("Location: $PHP_SELF?what=inbox"); 
}

}

Function ShowInbox() {

$mailbox = "imap.gmail.com:993/imap/ssl";
$conn = @imap_open("{" . $mailbox . "}INBOX", $_SESSION['username'], $_SESSION['password']);

$headers = @imap_headers($conn) or die("Couldn't get emails");
$numEmails = sizeof($headers); 

for($i = 1; $i < $numEmails+1; $i++)
{
$mailHeader = @imap_headerinfo($conn, $i);
$from = $mailHeader->fromaddress;
$subject = strip_tags($mailHeader->subject);
$date = $mailHeader->date;
echo "Email from $from, subject $subject, date $date<br>";
}

}
?>

 

My question is... is it safe to store the username and password like this in SESSIONS??

 

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.