Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

A simple autorization system. Why Errors?


  • Please log in to reply
17 replies to this topic

#1 VakhoQ

VakhoQ

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 126 posts

Posted 04 October 2010 - 06:32 AM

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

  • 0

#2 VakhoQ

VakhoQ

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 126 posts

Posted 04 October 2010 - 07:13 AM

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?
  • 0

#3 DEViANT

DEViANT

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 265 posts

Posted 04 October 2010 - 07:14 AM

replace all of these :
header("Location: XXXXXX");

in your script

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

  • 0

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

My Blog | Ask me!
Error : Satan did it

#4 DEViANT

DEViANT

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 265 posts

Posted 04 October 2010 - 07:18 AM

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

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

My Blog | Ask me!
Error : Satan did it

#5 VakhoQ

VakhoQ

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 126 posts

Posted 04 October 2010 - 07:19 AM

no. it isnot work.

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

  • 0

#6 DEViANT

DEViANT

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 265 posts

Posted 04 October 2010 - 07:21 AM


<?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();

}


  • 0

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

My Blog | Ask me!
Error : Satan did it

#7 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 04 October 2010 - 07:38 AM

Umm..
$_POST['username'];
$_POST['password'];
is supposed to be this?:
$username = $_POST['username'];
$password = $_POST['password'];

  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#8 VakhoQ

VakhoQ

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 126 posts

Posted 04 October 2010 - 07:39 AM

<?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


  • 0

#9 VakhoQ

VakhoQ

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 126 posts

Posted 04 October 2010 - 07:43 AM

Nullw0rm

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

#10 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 04 October 2010 - 07:44 AM

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

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#11 VakhoQ

VakhoQ

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 126 posts

Posted 04 October 2010 - 07:47 AM

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

#12 VakhoQ

VakhoQ

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 126 posts

Posted 04 October 2010 - 07:50 AM

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


  • 0