Login & session problem
Posted: Mon Sep 01, 2008 1:02 pm
Hi! I'm new to the world of PHP, so in the start it's only normal, that I don't understand something
The problem is, that I'm working on a login page combined with the option to add new messages, but something isn't going right - maybe I'm trying to check the sessions incorrectly. I'd be very thankful if you could help me with this code.
So this is a normal HTML login (the file is called admin.php):
and this is my news.php file - the file, which checks my password and starts a session - I have a suspicion that it's the session, which I don't understand completely.
Somehow after I press add, it throws me back to the login page, to be exact, it does this:
else{
include("admin.php");
exit;
Does anyone know what the problem is?
So this is a normal HTML login (the file is called admin.php):
Code: Select all
<table border=1 align=middle>
<form method="post" action="news.php"><td>Password:</td><td><input type="password" name="password"><input type="submit" value="Enter"></td></form></table>
Code: Select all
<?
session_start();
if($_POST['password'] == 'pass'){
$_SESSION['loged_in'] = true;
}
else{
include("admin.php");
exit;
}
?>
<form method="post" action="news.php">
<table>
<tr>
<td>
<select name="number">
<option value ="1">1</option>
<option value ="2">2</option>
<option value ="3">3</option>
<option value ="4">4</option>
</select>
<textarea name="news" wrap="virtual" rows="10" cols="40" style="color: #800000">New message</textarea></td></tr><tr><td>
<a href="admin.php?logout=1">Iziet</a>
<? if(isset($_REQUEST['logout'])) session_destroy();?>
</td></tr><tr align="right"><td>
<input type="submit" name="submit" value="Add">
</form>
</td>
</tr></table>
<?
@$news=$_POST['news'];
@$number=$_POST['number'];
$connection=mysql_connect('127.0.0.1','*','*') or die ("Unable to connect...");
mysql_select_db('*',$connection);
if(strlen($news)>0){
$query=mysql_query("INSERT INTO `info`(`message`, `number`) VALUES ('$news', '$number')",$connection);
}
mysql_close($connection);
?>
else{
include("admin.php");
exit;
Does anyone know what the problem is?