Jump to content

php problems (Undefined index: PHP_SELF)


chris_rulez001

Recommended Posts

hi ive made an admin panel and i tried to password protect it and im getting problems. i have got the session start at the very top of the page.

 

the php code:

 

<?php
if(isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == 1){
//They are logged in.
echo "Congratulations. You have logged in correctly!";
echo "<center>";
echo "<h2><you><b>";
echo "Chatroom Administration";
echo "</b></you></h2>";
echo "</center>";
echo "<A href='banip.php'>Ban IPS</a> | <A href='unbanip.php'>Unban IP</a> | <A href='editdelete.php'>Edit/Delete messages</a><br>";
}else{
if(isset($_POST['submit'])){
//They have posted something!
$username = "Administrator";
$password = "buzzer2242";
if($_POST['pass'] == $password && $_POST['user'] == $username){
//They have sent us the correct login information!
$_SESSION['loggedin'] = "1";
$_SESSION['user'] = $_POST['user'];
header('Location: '.$_SESSION['PHP_SELF']);
//The user has been redirected back to the main page and it should say they they have logged in!
}else{
//They failed to send us the correct username or password!
die('Incorrect username or password!');
}
}else{
echo "<form method=post action=".$_SERVER['PHP_SELF'].">Username: <input type=text name=user><br><br>Password: <input type=password name=pass><br><br><input type=submit name=submit value=\"Login!\"></form>";
}
}
?>

 

problems orrcuring:

 

Notice: Undefined index: PHP_SELF in /www/1111mb.com/c/h/are/chrisrulez/htdocs/chat/admin.php on line 31

 

Warning: Cannot modify header information - headers already sent by (output started at /www/1111mb.com/c/h/are/chrisrulez/htdocs/chat/admin.php:12) in /www/1111mb.com/c/h/are/chrisrulez/htdocs/chat/admin.php on line 31

Link to comment
https://forums.phpfreaks.com/topic/52469-php-problems-undefined-index-php_self/
Share on other sites

ive editted the section it now looks like:

 

$_SERVER['loggedin'] = "1";
$_SERVER['user'] = $_POST['user'];
header('Location: '.$_SERVER['PHP_SELF']);

 

but there is a problem it doesnt bring up the login form it just brings up what i want to protect

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.