Hey, could you please tell me what is wrong with my login script. I
just started learning php.
CODE:
login.php
<?
session_start() ;
header("Cache-Control: private");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Please Login</title>
</head>
<body>
<form action="script. php" method="get">
<table summary="Login Table">
<tr>
<td>username: </td>
<td><input type="text" name="login"></td>
</tr>
<tr>
<td>password: </td>
<td><input type="password" name="pass"></td>
</tr>
<tr>
<td><input type="submit" value="login"></td>
</tr>
</table>
</body>
</html>
script.php
<?
session_start() ; //start session
header("Cache-Control: private");
if (!$_GET["login"] || !$_GET["login"])
{
print<<<END
I'm sorry, but your not logged in or there was an error logging you
in. Please<br>
<a href="login.php ">go here</a> to try again. Sorry for any
inconvienince.
END;
}
else
{
//register session variable: 'login' and 'pass'
$_SESSION["login"] = $_GET["login"];
$_SESSION["pass"] = $_GET["pass"];
if ($_SESSION["login"] == "Koolyio" && $_SESSION["pass"] == "wow")
//if credentials are true
{
$_SESSION["access"] = true;
}
else
{
$_SESSION["access"] = false;
}
}
if ($_SESSION["access"] == true)
{
print<<<END
<html>
<script language="JavaS cript" type="text/javascript">
<!--
location.href = "main.php";
//-->
</script>
<noscript>Sorry , but your browser doesn't support JavaScript, ergo you
cannot
login</noscript></html>
END;
}
else
{
print<<<END;
I'm sorry, but one or more of the credentials you supplied were
incorrect. Please
try to login again <a href="login.php ">here</a>.
END;
?>
logout.php
<?
session_start() ; //start session
header("Cache-Control: private");
if ($_SESSION["access"] == true)
{
$_SESSION = array();
session_destroy ();
print("<a href=/"login.php/">log in</a>
}
?>
main.php
<?
session_start() ; //start session
header("Cache-Control: private");
if ($_SESSION["access"] == true)
{
print<<<END
<html>
<head>
<title>Member s Only</title>
</head>
<body>
You have succesfully logged in. You can now <a href="logout.ph p">log
out</a>
</body>
</html>
END;
}
else
{
print<<<END
Sorry, You have not logged in correctly. Please try again <a
href="login.php ">here</a>.
END;
}
?> 3 2875
Hi,
looks great. Does it fulfill any requirements, ie. any error messages
not showing up ;-)
HTH, Jochen
P.S.: What is the error message?
On 21 Apr 2004 19:16:33 -0700, km****@hotmail. com (koolyio) wrote: Hey, could you please tell me what is wrong with my login script. I just started learning php. CODE:
login.php
<? session_start( ); header("Cach e-Control: private"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> <head> <title>Pleas e Login</title> </head> <body> <form action="script. php" method="get"> <table summary="Login Table"> <tr> <td>username :</td> <td><input type="text" name="login"></td> </tr> <tr> <td>password :</td> <td><input type="password" name="pass"></td> </tr> <tr> <td><input type="submit" value="login"></td> </tr> </table>
</body> </html>
script.php
<? session_start( ); //start session header("Cach e-Control: private"); if (!$_GET["login"] || !$_GET["login"]) { print<<<END I'm sorry, but your not logged in or there was an error logging you in. Please<br> <a href="login.php ">go here</a> to try again. Sorry for any inconvieninc e. END; } else { //register session variable: 'login' and 'pass' $_SESSION["login"] = $_GET["login"]; $_SESSION["pass"] = $_GET["pass"]; if ($_SESSION["login"] == "Koolyio" && $_SESSION["pass"] == "wow") //if credentials are true { $_SESSION["access"] = true; } else { $_SESSION["access"] = false; } } if ($_SESSION["access"] == true) { print<<<END <html> <script language="JavaS cript" type="text/javascript"> <!-- location.hre f = "main.php"; //--> </script> <noscript>Sorr y, but your browser doesn't support JavaScript, ergo you cannot login</noscript></html> END; } else { print<<<END; I'm sorry, but one or more of the credentials you supplied were incorrect. Please try to login again <a href="login.php ">here</a>. END; ?>
logout.php
<? session_start( ); //start session header("Cach e-Control: private"); if ($_SESSION["access"] == true) { $_SESSION = array(); session_destro y(); print("<a href=/"login.php/">log in</a> } ?>
main.php
<? session_start( ); //start session header("Cach e-Control: private"); if ($_SESSION["access"] == true) { print<<<END
<html> <head> <title>Membe rs Only</title> </head> <body> You have succesfully logged in. You can now <a href="logout.ph p">log out</a> </body> </html> END; } else { print<<<END Sorry, You have not logged in correctly. Please try again <a href="login.ph p">here</a>. END; } ?>
--
Jochen Daum - Cabletalk Group Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces. http://sourceforge.net/projects/phpdbedittk/
I noticed that Message-ID:
<59************ *************@p osting.google.c om> from koolyio contained
the following: if (!$_GET["login"] || !$_GET["login"])
if (!$_GET["login"] || !$_GET["pass"])
{ print<<<END I'm sorry, but your not logged in or there was an error logging you
you're
in. Please<br> <a href="login.php ">go here</a> to try again. Sorry for any inconvieninc e.
inconvenience
Got fed up after this because I don't know what I'm looking for.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
"koolyio" <km****@hotmail .com> wrote in message
news:59******** *************** **@posting.goog le.com... Hey, could you please tell me what is wrong with my login script. I just started learning php. CODE:
login.php
<? session_start() ; header("Cache-Control: private"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> <head> <title>Please Login</title> </head> <body> <form action="script. php" method="get"> <table summary="Login Table"> <tr> <td>username: </td> <td><input type="text" name="login"></td> </tr> <tr> <td>password: </td> <td><input type="password" name="pass"></td> </tr> <tr> <td><input type="submit" value="login"></td> </tr> </table>
</body> </html>
script.php
<? session_start() ; //start session header("Cache-Control: private"); if (!$_GET["login"] || !$_GET["login"]) { print<<<END I'm sorry, but your not logged in or there was an error logging you
"you're".
in. Please<br> <a href="login.php ">go here</a> to try again. Sorry for any inconvienince. END; } else { //register session variable: 'login' and 'pass' $_SESSION["login"] = $_GET["login"]; $_SESSION["pass"] = $_GET["pass"]; if ($_SESSION["login"] == "Koolyio" && $_SESSION["pass"] == "wow")
I'm hoping that, one day, this goes to a database or something with md5()'d
passwords. 8)
//if credentials are true { $_SESSION["access"] = true; } else { $_SESSION["access"] = false; } } if ($_SESSION["access"] == true) { print<<<END <html> <script language="JavaS cript" type="text/javascript"> <!-- location.href = "main.php"; //--> </script> <noscript>Sorry , but your browser doesn't support JavaScript, ergo you cannot login</noscript></html> END; } else { print<<<END;
Semicolon is wrong here - heredoc not only doesn't require them, it breaks
it. But you know that, because you got it right elsewhere.
I'm sorry, but one or more of the credentials you supplied were incorrect. Please try to login again <a href="login.php ">here</a>. END;
Missing } here.
?>
logout.php
<? session_start() ; //start session header("Cache-Control: private"); if ($_SESSION["access"] == true) { $_SESSION = array(); session_destroy (); print("<a href=/"login.php/">log in</a>
Aside from the lack of a closing quote, bracket and semi-colon, /" is wrong,
use \" to escape double quotes. Better still, put your quoted string in
single quotes and use the unescaped version (since you don't have any
variable substitution in there).
} ?>
main.php
<? session_start() ; //start session header("Cache-Control: private"); if ($_SESSION["access"] == true) { print<<<END
<html> <head> <title>Member s Only</title> </head> <body> You have succesfully logged in. You can now <a href="logout.ph p">log out</a> </body> </html> END; } else { print<<<END Sorry, You have not logged in correctly. Please try again <a href="login.php ">here</a>. END; } ?>
See embedded comments. I'm sure there's more than I found, but I got it
working at least.
For forms, use method="POST" unless you want your username and password of
your failed attempts appearing in your browser's address history. Then use
$_POST instead of $_GET (or better yet, $_REQUEST).
Otherwise, nice first attempt, and I'm pleased you produced a simple example
(no functions or classes, globals that aren't superglobals, databases, etc)
to reduce the problem set.
Garp This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: knot2afrayed |
last post by:
I am trying to fix error- object does not exist- I want it possible to
allow object not to exist.
I am writing a script on a page that may or may not include a login
form. For example-after a visitor logs in, the login form is no longer
on the page, but other content is still there.
I want to bring focus to the login form using the onLoad in the body
tag.....but if the login form does not exist, I do not want to perform
this function.
|
by: ilockett |
last post by:
The background:
I have a web app with a simple master page that contains just one
content placeholder.
I have created a web form that then uses this master page. Within the
content placeholder, I have placed a Login control (Login1) and a
ValidationSummary control.
I have set the ValidationSummary's ValidationGroup property equal to
"Login1".
|
by: Kivak Wolf |
last post by:
Hi,
I am currently trying to make a website that requires an account to use
so it can disply the data according to the account. I have ASP.NET 2.0
installed and working fine. However, it is not my server, I am having a
company host it. I know that you can use the "Login" control right in
VS2005, but it won't work unless the website is on localhost.
Where can I find a good place to get or find out how to make a login
control from...
|
by: bull1099 |
last post by:
I designed a simple site which has a login for users to access their account page. When i had my files uploaded on a terrible hosting service site, my website I designed was fully functional. I moved my site to this newsit.es host service because it is ten times better but my login script wont work anymore. I believe it has to do with the settings not allowing sessions. Does this sound right?
I tried hundreds of times and it kept sending me...
|
by: kang jia |
last post by:
hi
i am currently learning Django framework and i have to do a login page at the moment. i have used the code like following:
from django.contrib.auth import authenticate, login
def my_view(request):
username = request.POST
password = request.POST
| |
by: kang jia |
last post by:
hi
i have small problems occurred in my login function, which i use Django to build,
in my template which is login.html, the code is like the following:
<html>
<head>
<title>Login</title>
|
by: muppetjones |
last post by:
I'm really new to the whole networking side of things, so I don't know the backend very well. I wrote a series of PHP/AJAX scripts to allow a user to create a login account, but apparently my script is doing much much more than I imagined as I received an email from my admin this morning:
I think a core dump means my program had a fatal error, and I know my program is supposed to email me when there is an error. Granted, I was debugging...
|
by: harsh9892991141 |
last post by:
every time enter my login id and password in my index page it shows me the error 404
Object not found!
The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
If you think this is a server error, please contact the webmaster.
Error 404
127.0.0.1
|
by: satishknight |
last post by:
Hi,
Can some one tell me how to change the validation sequence for the code pasted below, actually what I want it when any one enters the wrong login information (already registered users) then it has to tell then them its wrong information but currently it takes then to a next page and then tells them its incorrect information. This is tedious as every time they enter wrong they will be redirected to a different page and then they have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |