Jump to content

A simple autorization system. Why Errors?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
19 replies to this topic

#1
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 127 posts
I have write a simple autorization system in PHP but I have some mistakes in Check_login.php and in adminpanel.php.

I dont know what mistakes I have made. could you help me, please?


login.php


<form action="admin.php" method="post">

<input type="text" name="username" id="username" /><br />

<input type="password" name="password" id="password" /><br />

<input type="submit" name="submit" value="Login" id="submit" /><br />

</form>



Check_login.php


<?php

$cms_username = "vakho";

$cms_password = "123";

$_POST['username'];

$_POST['password'];


if($username == "" || $password == "") 

{

echo  "INPUT IS NULL. PLASE ENTER USER AND PASSWORD";

exit();

}


if($username != $cms_username || $password != $cms_password) 

{

echo  "YOUR NAME OR PASSWORD IS NOT CORRECT";

exit();

}


if($username == $cms_username && $password == $cms_password)

{

session_start();

$_SESSION['cms_key'] = 'openSession';

header("Location:AdminPanel.php");

}

?>



adminpanel.php


<?php

session_start();

if ($_SESSION['cms_key'] == "openSession")

{

header("Location: Check_login.php");

}


else

{

exit();  

}

?>

<body>

// where I'm going to Add, edit and information

</body>






ERRORS:


Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at F:\Program Files\VertrigoServ\www\admin\Check_login.php:11) in F:\Program Files\VertrigoServ\www\admin\Check_login.php on line 32


Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at F:\Program Files\VertrigoServ\www\admin\Check_login.php:11) in F:\Program Files\VertrigoServ\www\admin\Check_login.php on line 32


Warning: Cannot modify header information - headers already sent by (output started at F:\Program Files\VertrigoServ\www\admin\Check_login.php:11) in F:\Program Files\VertrigoServ\www\admin\Check_login.php on line 34



#2
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 127 posts
I change code. firstly, i wrote:
if($username == $cms_username && $password == $cms_password)

than:
if($username == "" || $password == "")

than:
if($username != $cms_username || $password != $cms_password)

<?php

$_POST['username'];

$_POST['password'];

$cms_username = "vakho";

$cms_password = "123";



if($username == $cms_username && $password == $cms_password)

{

session_start()

$_SESSION['cms_key'] = 'openSession';

header("location:Admin_panel.php");

}


if($username == "" || $password == "") 

{

echo  "INPUT IS NULL. PLASE ENTER USER AND PASSWORD";


exit();

}


if($username != $cms_username || $password != $cms_password) 

{

echo  "USER OR PASSWORD IS NOT CORRECT";

exit();

}



And now i have this ERROR:

Parse error: syntax error, unexpected T_VARIABLE in F:\Program Files\VertrigoServ\www\admin\Check_login.php on line 22


line 22 is
 $_SESSION['cms_key'] = 'openSession';

 



can you tell me what hapen?

#3
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
replace all of these :
header("Location: XXXXXX");

in your script

with this :
echo '<meta http-equiv="refresh" content="0;url=XXXXXXX">';

:D You should rep+ me so that I can win :D

My Blog | Ask me!
Error : Satan did it

#4
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
For the seccond error, you forgot to add a ';' after session_start() on the previous line, ie line 21

:D You should rep+ me so that I can win :D

My Blog | Ask me!
Error : Satan did it

#5
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 127 posts
no. it isnot work.

Parse error: syntax error, unexpected T_VARIABLE in F:\Program Files\VertrigoServ\www\admin\Check_login.php on line 23


#6
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
<?php
$_POST['username'];
$_POST['password'];
$cms_username = "vakho";
$cms_password = "123";


if($username == $cms_username && $password == $cms_password)
{
session_start();
$_SESSION['cms_key'] = 'openSession';
header("location:Admin_panel.php");
}

if($username == "" || $password == "") 
{
echo  "INPUT IS NULL. PLASE ENTER USER AND PASSWORD";

exit();
}

if($username != $cms_username || $password != $cms_password) 
{
echo  "USER OR PASSWORD IS NOT CORRECT";
exit();
}

:D You should rep+ me so that I can win :D

My Blog | Ask me!
Error : Satan did it

#7
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
Umm..
$_POST['username'];
$_POST['password'];
is supposed to be this?:
$username = $_POST['username'];
$password = $_POST['password'];

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#8
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 127 posts

<?php

$_POST['username'];

$_POST['password'];

$cms_username = "vakho";

$cms_password = "123";



if($username == $cms_username && $password == $cms_password)

{

session_start();

$_SESSION['cms_key'] = 'openSession';

header("location:Admin_panel.php");

}


if($username == "" || $password == "") 

{

echo  "INPUT IS NULL. PLASE ENTER USER AND PASSWORD";


exit();

}


if($username != $cms_username || $password != $cms_password) 

{

echo  "USER OR PASSWORD IS NOT CORRECT";

exit();

}


?>







Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at F:\Program Files\VertrigoServ\www\admin\Check_login.php:10) in F:\Program Files\VertrigoServ\www\admin\Check_login.php on line 19


Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at F:\Program Files\VertrigoServ\www\admin\Check_login.php:10) in F:\Program Files\VertrigoServ\www\admin\Check_login.php on line 19


Warning: Cannot modify header information - headers already sent by (output started at F:\Program Files\VertrigoServ\www\admin\Check_login.php:10) in F:\Program Files\VertrigoServ\www\admin\Check_login.php on line 21




#9
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 127 posts
Nullw0rm

don't work .... that is not important

#10
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
Why are you not using the advice we gave you?

A) You cannot send content BEFORE using header();, ensure you are not echoing anything, and ensure there is no whitespace before the <?php tag
B) You did not declare $username and $password, like in my post, hense the T_VARIABLE error. It does matter if you are relying on register_globals, as that is not in any means a proper method to access POST data.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#11
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 127 posts
DEViANT

i think we should make script without meta code
echo '<meta http-equiv="refresh" content="0;url=Admin_panel.php">';


what mistakes are i dont know....

#12
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 127 posts
Nullw0rm
ok, thanks for your advices. now i write code as you tell me. :)




<?php
$username = $_POST['username'];
$password = $_POST['password'];
$cms_username = "vakho";
$cms_password = "123";


if($username == $cms_username && $password == $cms_password)
{
session_start();
$_SESSION['cms_key'] = 'openSession';
header("location:Admin_panel.php");
exit();

}

if($username == "" || $password == "") 
{
echo  "INPUT IS NULL. PLASE ENTER USER AND PASSWORD";
exit();
}

if($username != $cms_username || $password != $cms_password) 
{
echo  "USER OR PASSWORD IS NOT CORRECT";
exit();
}
?>

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at F:\Program Files\VertrigoServ\www\admin\Check_login.php:10) in F:\Program Files\VertrigoServ\www\admin\Check_login.php on line 19

Warning: Cannot modify header information - headers already sent by (output started at F:\Program Files\VertrigoServ\www\admin\Check_login.php:10) in F:\Program Files\VertrigoServ\www\admin\Check_login.php on line 21