AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Off-Topic (https://forums.alliedmods.net/forumdisplay.php?f=15)
-   -   [PHP] Login Help (https://forums.alliedmods.net/showthread.php?t=140009)

shuttle_wave 10-08-2010 04:59

[PHP] Login Help
 
PHP Code:

<?php include("header.php"); ?>

<?php
$User 
"Shuttle_Wave";
$Pass "testing";
?>

<center>

<h1>Admin Login Panel</h1>


<form action='checklogin.php' method='post'>

Username: <input type="text" name="username" />
Password: <input type="password" name="password" />
<input type="submit" name="Submit" value="Login" /></form>

</center>

<?php

if($_POST["username"] == $User && $_POST["password"] == $Pass)
{
    
session_register("username");
    
session_register("password");
    
header("location:main_system.php");
}
else
{
    echo 
"Incorrect Username or Password";
}

?>

<body>
</body>
</html>

i seem to be having problems with my php login i coded. it doesnt work and also it shows the Incorrent ... b4 i even login.

Sorry i am PHP coding beginner

minimiller 10-08-2010 07:11

Re: [PHP] Login Help
 
it might be easier to make 2 pages
1 for login.php which contains the login form and aims at checklogin.php
checklogin.php can then contain the checks and redirect or echo instructions on what they got wrong

fysiks 10-08-2010 12:10

Re: [PHP] Login Help
 
PHP Code:

if($_POST["username"] == $User && $_POST["password"] == $Pass

This is ALWAYS false on first load.

Exolent[jNr] 10-08-2010 16:48

Re: [PHP] Login Help
 
PHP Code:

<?php

if(isset($_POST["username"]) && isset($_POST["password"]))
{
    if(
$_POST["username"] == $User && $_POST["password"] == $Pass)
    {
        
session_register("username");
        
session_register("password");
        
header("location:main_system.php");
    }
    else
    {
        echo 
"Incorrect Username or Password";
    }
}

?>


shuttle_wave 10-08-2010 20:31

Re: [PHP] Login Help
 
PHP Code:

<?php include("header.php"); ?>

<?php
$User 
"Shuttle_Wave";
$Pass "test";
?>

<center>

<h1>Admin Login Panel</h1>


<form action='#' method='post'>

Username: <input type="text" name="username" id="username" />
Password: <input type="password" name="password" id="password" />
<input type="submit" name="Submit" value="Login" /></form>

</center>

<?php 

if(isset($_POST["username"]) && isset($_POST["password"])) 

    if(
$_POST["username"] == $User && $_POST["password"] == $Pass
    { 
        
session_register("username");
        
session_register("password");
        
header("location:system.php");
    } 
    else 
    { 
        echo 
"Incorrect Username or Password"
    } 


?>

<body>
</body>
</html>

i did that. it wrks but when i enter the correct user and password i get this error

PHP Code:

Warningsession_register() [function.session-register]: Cannot send session cookie headers already sent by (output started at C:\xampp\htdocs\header.php:12in C:\xampp\htdocs\login.php on line 27

Warning
session_register() [function.session-register]: Cannot send session cache limiter headers already sent (output started at C:\xampp\htdocs\header.php:12in C:\xampp\htdocs\login.php on line 27

Warning
Cannot modify header information headers already sent by (output started at C:\xampp\htdocs\header.php:12in C:\xampp\htdocs\login.php on line 29 


codes below is my system.php

PHP Code:

<?php include("header.php"); ?>
<?php 
include("databases.php"); ?>

<?
session_start
();
 
if(!
session_is_registered(username))
{
  
header("location:login.php");
}
?>

<center>

<h1>Login System Information</h1>

<?php

echo "<table border='1'>
    <tr class=\"table_head\">
        <th class=\"number\" style=\"min-width:20px;\">#</th>
        <th>&nbsp; Name &nbsp;</th>
        <th>&nbsp; UserName &nbsp;</th>
        <th>&nbsp; Password &nbsp;</th>
        <th>&nbsp; Status &nbsp;</th>
    </tr>"
;
    
    while(
$row mysql_fetch_array($result))
    {
        echo 
"<tr>";
        echo 
"<td class=\"number\">&nbsp;" $row['num'] .  "&nbsp;</td>";
        echo 
"<td class=\"center\">&nbsp;" $row['name'] . "&nbsp;</td>";
        echo 
"<td class=\"center\">&nbsp;" $row['username'] . "&nbsp;</td>";
        echo 
"<td class=\"center\">&nbsp;" $row['password'] . "&nbsp;</td>";
        echo 
"<td class=\"center\">&nbsp;" $row['status'] . "&nbsp;</td>";
        
        echo 
"</tr>";
    }

echo 
"</table>";

mysql_close($database);
?>

</center>

<body>
</body>
</html>


8088 10-08-2010 20:51

Re: [PHP] Login Help
 
Is Google broken? Move session_start(); to the beginning of your code. By the way, a warning is not an error.

platzpatrone 10-08-2010 21:11

Re: [PHP] Login Help
 
and so many open and closing php tags in order they dont needed :)

PHP Code:

<?php 
session_start
(); 
  
if(!
session_is_registered(username)) 

  
header("location:login.php"); 


include(
"header.php");
include(
"databases.php");
 
echo 
"<body>";
echo 
"<center>";
echo 
"<h1>Login System Information</h1>";

echo 
"<table border='1'> 
    <tr class=\"table_head\"> 
        <th class=\"number\" style=\"min-width:20px;\">#</th> 
        <th>&nbsp; Name &nbsp;</th> 
        <th>&nbsp; UserName &nbsp;</th> 
        <th>&nbsp; Password &nbsp;</th> 
        <th>&nbsp; Status &nbsp;</th> 
    </tr>"

     
    while(
$row mysql_fetch_array($result)) 
    { 
        echo 
"<tr>"
        echo 
"<td class=\"number\">&nbsp;" $row['num'] .  "&nbsp;</td>"
        echo 
"<td class=\"center\">&nbsp;" $row['name'] . "&nbsp;</td>"
        echo 
"<td class=\"center\">&nbsp;" $row['username'] . "&nbsp;</td>"
        echo 
"<td class=\"center\">&nbsp;" $row['password'] . "&nbsp;</td>"
        echo 
"<td class=\"center\">&nbsp;" $row['status'] . "&nbsp;</td>"
         
        echo 
"</tr>"
    } 

echo 
"</table>"

mysql_close($database); 

echo 
"</center>";
echo 
"</body>";
echo 
"</html>";
?>


shuttle_wave 10-08-2010 21:43

Re: [PHP] Login Help
 
Quote:

Originally Posted by platzpatrone (Post 1319566)
and so many open and closing php tags in order they dont needed :)

PHP Code:

<?php 
session_start
(); 
  
if(!
session_is_registered(username)) 

  
header("location:login.php"); 


include(
"header.php");
include(
"databases.php");
 
echo 
"<body>";
echo 
"<center>";
echo 
"<h1>Login System Information</h1>";

echo 
"<table border='1'> 
    <tr class=\"table_head\"> 
        <th class=\"number\" style=\"min-width:20px;\">#</th> 
        <th>&nbsp; Name &nbsp;</th> 
        <th>&nbsp; UserName &nbsp;</th> 
        <th>&nbsp; Password &nbsp;</th> 
        <th>&nbsp; Status &nbsp;</th> 
    </tr>"

     
    while(
$row mysql_fetch_array($result)) 
    { 
        echo 
"<tr>"
        echo 
"<td class=\"number\">&nbsp;" $row['num'] .  "&nbsp;</td>"
        echo 
"<td class=\"center\">&nbsp;" $row['name'] . "&nbsp;</td>"
        echo 
"<td class=\"center\">&nbsp;" $row['username'] . "&nbsp;</td>"
        echo 
"<td class=\"center\">&nbsp;" $row['password'] . "&nbsp;</td>"
        echo 
"<td class=\"center\">&nbsp;" $row['status'] . "&nbsp;</td>"
         
        echo 
"</tr>"
    } 

echo 
"</table>"

mysql_close($database); 

echo 
"</center>";
echo 
"</body>";
echo 
"</html>";
?>


Quote:

Originally Posted by 8088 (Post 1319556)
Is Google broken? Move session_start(); to the beginning of your code. By the way, a warning is not an error.

ty vm

shuttle_wave 10-08-2010 22:14

Re: [PHP] Login Help
 
i get this error now. I get that when i log in.

PHP Code:

Warningsession_register() [function.session-register]: Cannot send session cache limiter headers already sent (output started at C:\xampp\htdocs\header.php:12in C:\xampp\htdocs\login.php on line 27

Warning
Cannot modify header information headers already sent by (output started at C:\xampp\htdocs\header.php:12in C:\xampp\htdocs\login.php on line 29 

line 27 28 and 29 is
PHP Code:

        session_register("username");
        
session_register("password");
        
header("location:system.php"); 


platzpatrone 10-08-2010 22:33

Re: [PHP] Login Help
 
PHP Code:

<?php 
$User 
"Shuttle_Wave"
$Pass "test"

if(isset(
$_POST["username"]) && isset($_POST["password"]))  
{  
    if(
$_POST["username"] == $User && $_POST["password"] == $Pass)  
    {  
        
session_register("username"); 
        
session_register("password"); 
        
header("location:system.php"); 
    }  
    else  
    {  
        
$errormsg "Incorrect Username or Password";  
    }  
}  
include(
"header.php");
 
?> 
 <body>
<center> 

<h1>Admin Login Panel</h1> 

<?php if(!empty($errormsg)) echo $errormsg?>

<form action='#' method='post'> 

Username: <input type="text" name="username" id="username" /> 
Password: <input type="password" name="password" id="password" /> 
<input type="submit" name="Submit" value="Login" /></form> 

</center> 

</body> 
</html>



All times are GMT -4. The time now is 09:24.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.