View Full Version : Login Code Error
Titan85
09-12-2006, 11:07 AM
hey, i have been working on getting a login script working, but always get an error. Here is my code:
<?php
if (($_POST['username']=="")) {
echo"
<html>
<title>Login Page</title>
<body>
Please fill out the form below to acces that page
<form method=\"post\" action=\"process.php\">
Username: <input type=\"text\" name=\"username\" />
<br />
Password: <input type=\"text\" name=\"password\" />
<br />
<input type=\"button\" value=\"Submit\" />
</form>
</body>
</html>";
} else {
$username = $_POST['username'];
$passowrd = $_POST['password'];
session_start();
if ($username == "kyle" && $password == "price") {
$permission == "yes"
$username = $_POST['username'];
session_register("permission");
session_register("username");
if ($permission == "yes") {
echo"
<html>
<title>Login Page</title>
<body>
You are now logged in, feel free to navigate the protected pages
<br />
<a href=\"page1.html\">Page 1</a>
<br />
<a href=\"page2.html\">Page 2</a>
</body>
</html>";
} else {
echo "The username or password you entered was incorrect, please retry.";
}
?>
the error i get is this "Parse error: syntax error, unexpected T_VARIABLE in /home/echodesi/public_html/testing/login/test1.php on line 27"
I would appreciate any help :)
codeexploiter
09-12-2006, 11:32 AM
I've modified your code on certain locations now it works correctly. Plz compare your code with mine to find the difference
<?php
if ($_POST['username'] == "")
{
echo "<html><title>Login Page</title><body>Please fill out the form below to acces that page<form method=\"post\" action=\"process.php\">sername: <input type=\"text\" name=\"username\" /><br />Password: <input type=\"text\" name=\"password\" /><br /><input type=\"submit\" value=\"Submit\" /></form></body></html>";
}
else
{
$username = $_POST['username'];
$password = $_POST['password'];
echo "$username";
echo "$password<br>";
session_start();
if ($username == "kyle" && $password == "price")
{
$permission = "yes";
$username = $_POST['username'];
session_register("permission");
session_register("username");
echo "$permission<br>";
if ($permission == "yes")
{
echo"<html><title>Login Page</title><body>You are now logged in, feel free to navigate the protected pages<br /><a href=\"page1.html\">Page 1</a><br /><a href=\"page2.html\">Page 2</a></body></html>";
}
else
{
echo "The username or password you entered was incorrect, please retry.";
}
}
}
?>
Plz note that according to your code the file name must be process.php
--------------------------------------------------------------------------
Problems in your code
1.
Posted by Titan85
$permission == "yes"
This is an assignment operation you missed two things:
(a) You need only single = for assigning a value
(b) You missed the ; in that line
2. The {} used in the nested if statement are not ordered some mismatch were there. I've corrected it.
3. In your form section you used button instead of submit button.
Titan85
09-12-2006, 04:04 PM
thanks a lot codeex, got it all working after fixing the errors you pointed out. However, i did run into some other errors. I am new to this so I do not know what his means error is telling me:
"Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/echodesi/public_html/testing/login/process.php:24) in /home/echodesi/public_html/testing/login/process.php on line 28
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/echodesi/public_html/testing/login/process.php:24) in /home/echodesi/public_html/testing/login/process.php on line 28".
I know it has something to do with the code on line 28 which is my session_start(); area. What I did was i actually named the code i gave before "process.php" and then used another page called "login.html" to login. Here is the code for login.html incase you need it:
<html>
<title>Login Page</title>
<body>
Please fill out the form below to login.
<form method="post" action="process.php">
Username: <input type="text" name="username" />
<br />
Password: <input type="text" name="password" />
<br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
Thanks again
ItsMeOnly
09-12-2006, 05:02 PM
it means you tried to send cookie and "pragma: no-cache" header after part of HTML content was sent to client (process.php, line 24- I suspect that's "echoing" of username and password, remove it): the cookie needs to be sent BEFORE anything on page (like HTML with nested PHP code).
BTW, I see you're using nested html code in PHP, you can use alternate PHP syntax to enclose "unescaped" html content:
<?php if ($_POST['username'] == "") : ?>
I'm an unescaped HTML with all the ""'s and ''s
<?php else : ?>
I'm another html content with unescaped ""s and ''s, <?php=$variable?> me
<?php endif ?>
Titan85
09-12-2006, 05:19 PM
it means you tried to send cookie and "pragma: no-cache" header after part of HTML content was sent to client (process.php, line 24- I suspect that's "echoing" of username and password, remove it): the cookie needs to be sent BEFORE anything on page (like HTML with nested PHP code).
BTW, I see you're using nested html code in PHP, you can use alternate PHP syntax to enclose "unescaped" html content:
<?php if ($_POST['username'] == "") : ?>
I'm an unescaped HTML with all the ""'s and ''s
<?php else : ?>
I'm another html content with unescaped ""s and ''s, <?php=$variable?> me
<?php endif ?>
Thanks man, I did that and it worked out great :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.