<?php
session_start();
if($_GET["log"] == "out") {
session_unset();
session_destroy();
echo "done";
}
$username = $_POST["user_login"];
$password = $_POST["user_pass"];
if($_SESSION['LoggedIn']) {
$_SESSION['LoggedIn'] = 1;
$_SESSION['user_login'] = $username;
$_SESSION['user_pass'] = $password;
echo $_SESSION['user_login']."<br />".$_SESSION['user_pass'];
$ftp_server = "127.0.0.1";
$gName = $_GET["name"];
require_once "ftp.class.php";
$ftp =& new FTP();
if ($ftp->connect($ftp_server)) {
if ($ftp->login($_SESSION['user_login'],$_SESSION['user_pass'])) {
echo "\n".$ftp->sysType() . "\n";
echo $ftp->pwd() . "\n";
if($gName)
$ftp->chdir("$gName");
else
$ftp->chdir("Downloads");
print_nice($ftp->nlist());
echo "\n";
} else {
echo "login failed: ";
print_r($ftp->error_no);
print_r($ftp->error_msg);
}
$ftp->disconnect();
print_r($ftp->lastLines);
} else {
echo "connection failed: ";
print_r($ftp->error_no);
print_r($ftp->error_msg);
}
}
else
{
?>
<form method="POST" style="margin: 20px 10px; padding: 15px 25px 25px 20px; border: 1px solid #EEE8E1; background: #FAF7F5;">
<p>Login Form</p>
<?php echo $_SESSION['user_login']."<br />".$_SESSION['user_pass']; ?>
<p>
<label for="name">Username</label><br />
<input id="name" name="user_login" value="" type="text" tabindex="97" />
</p>
<p>
<label for="email">Password</label><br />
<input id="email" name="user_pass" value="" type="password" tabindex="98" />
</p>
<p><input type="checkbox" value="1" name="rmb"> Remember Me <br /><a href="#">Forgot Password</a><br /><a href="index.php?page=register">Don't have an Account?</a></p>
<p class="no-border">
<input class="button" name="submit" type="submit" value="Submit" tabindex="14" />
<input class="button" type="reset" value="Reset" tabindex="15" />
</p>
<?php
}
?>
views:
110answers:
7
A:
Did you add a check for if the user was already logged in?
if (isset($_POST['submit']) || (isset($_SESSION['LoggedIn']) && $_SESSION['LoggedIn']))
MiffTheFox
2009-11-23 12:26:50
A:
Change first line with this:
if (isset($_POST['submit']) || (isset($_SESSION['user_login']) && $_SESSION['user_login'] != '')
{
dfilkovi
2009-11-23 12:27:27
if you do something like this, youll have problems with $_POST
Cem Kalyoncu
2009-11-23 12:30:01
+1
A:
Maybe you can first check whether it is login or not:
if(isset($_SESSION['LoggedIn']) &&$_SESSION['LoggedIn']==1)
{
// proceed to do the login stuff
}
else if (isset($_POST['submit']))
{
$username = $_POST["user_login"];
$password = $_POST["user_pass"];
$_SESSION['LoggedIn'] = 1;
$_SESSION['user_login'] = $username;
$_SESSION['user_pass'] = $password;
// some coding about ftp login
}
else
{
}
Ngu Soon Hui
2009-11-23 12:27:35
A:
I dont use sessions but you can use like this
if (isset($_POST['submit'])) {
//....
}
if($_SESSION['LoggedIn']) {
//actual coding
}
Cem Kalyoncu
2009-11-23 12:28:19
+1
A:
Try
if ((isset($_POST['submit'])) OR ($_SESSION['LoggedIn'] == 1)) {
// Logged in stuff...
}
Andrew Phillips
2009-11-23 12:29:28
A:
I tend to do a check to see if there's a logged in session present then redirect to the main content for the user (ie. page.php) or show you the login box if you need to log in, I have a similar thing (only redirect to login.php or show content) for all other log in requiring pages as an include on so that it constantly checks that you're meant to be logged in or not and send you to login if you need to, stops you going to page.php and seeing nothing.
andy-score
2009-11-23 12:32:05
A:
You need to call session_start(); on the first line of each page.
Antony Carthy
2009-11-23 12:58:58