Page 1 of 1
Help 'Undefined Index'
Posted: Fri Aug 13, 2004 10:02 am
by Getran
I keep getting an 'Undefined Index' error with my login.php file. this is the message:
Notice: Undefined index: terrastormlogin in *hidden*\login.php on line 2
this is the bit on line 2:
$checkcookie = $_COOKIE['terrastormlogin'];
Can someone tell me how to stop this error ?
Posted: Fri Aug 13, 2004 10:22 am
by d3ad1ysp0rk
Are you by chance setting is as "checkcookie", yet accessing it as "terrastormlogin"?
Posted: Fri Aug 13, 2004 10:27 am
by Getran
this is how i'm using it:
Code: Select all
<?php
$checkcookie = $_COOKIE['terrastormlogin'];
if (isset($checkcookie))
{
$loggedin = "1";
global $loggedin;
global $user;
$maincontent = "";
$maincontent .= "You are already logged in!<br>";
$maincontent .= "Would you like to <a href='logout.php'>Logout</a> ?";
}
else if (!isset($checkcookie))
{
$loggedin = "0";
global $loggedin;
$maincontent = "";
$maincontent .= "Enter your username and password to login!";
$maincontent .= "<form action='login.php' method='POST'>";
$maincontent .= "<input type='text' name='user' value='Username'><br>";
$maincontent .= "<input type='text' name='pass' value='Password'><br>";
$maincontent .= "<input type='submit' name='login' value='Login'><br>";
$maincontent .= "</form>";
}
?>
Posted: Fri Aug 13, 2004 10:33 am
by d3ad1ysp0rk
try..
Code: Select all
<?php
if (isset($_COOKIE['terrastormlogin']))
{
$loggedin = "1";
global $loggedin;
global $user;
$maincontent = "";
$maincontent .= "You are already logged in!<br>";
$maincontent .= "Would you like to <a href='logout.php'>Logout</a> ?";
}
else if (!isset($checkcookie))
{
$loggedin = "0";
global $loggedin;
$maincontent = "";
$maincontent .= "Enter your username and password to login!";
$maincontent .= "<form action='login.php' method='POST'>";
$maincontent .= "<input type='text' name='user' value='Username'><br>";
$maincontent .= "<input type='text' name='pass' value='Password'><br>";
$maincontent .= "<input type='submit' name='login' value='Login'><br>";
$maincontent .= "</form>";
}
?>
Posted: Fri Aug 13, 2004 10:42 am
by Getran
ok that worked lol thx man. I have a few more things i need help on (and i thought it's better to post here than make a new topic).
i get this error:
Notice: Undefined offset: 9 in *hidden*\random.php on line 9
line 9 = $RandomRotator1 = ereg_replace("\n","",$file[$randcount]);
This is the contents of the random.php file:
Code: Select all
<?php
$RandomRotator1 = "";
$filename = "random.txt";
$file = file($filename);
srand((double)microtime()*1000000);
while ($RandomRotator1 == "") {
if(!isset($sp)){
$randcount = rand(0,count($file));
$RandomRotator1 = ereg_replace("\n","",$file[$randcount]);
}else{
$RandomRotator1 = ereg_replace("\n","",$file[$sp]);
}
}
print "$RandomRotator1";
?>
I thought i solved this problem once, but it's come back to haunt me
And plus, with my login script, i have to login tiwce for it to actually show you "You have been logged in" message... i don't know why.
This is my login code:
Code: Select all
<?php
if (isset($login))
{
$login = "";
$user = $_POST['user'];
$pass = $_POST['pass'];
require("db_info.php");
mysql_connect("$host", "$username", "$password");
mysql_select_db("$database");
$loginquery = mysql_query("SELECT * from accounts WHERE username='$user'and password='$pass'") or die("ERROR: Username and password not found or not matched!");
$worked = mysql_fetch_array($loginquery);
$user = $worked['username'];
$pass = $worked['password'];
if ($worked)
{
setcookie("terrastormlogin", "$user", time() + 86400);
global $user;
$content = "Login Successful!<br>";
$content .= "Welcome, " . $user . ", you will be redirected in 2 seconds!";
$content .= "<meta http-equiv='refresh' content='2;url=portal.php'>";
}
else if (!$worked)
{
$maincontent .= "Login failed!";
$loggedin = "0";
}
else
{
$loggedin = "0";
}
}
else
{
$login = "";
$loggedin = "0";
$content = "";
}
$login = "";
?>