473,573 Members | 2,627 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

several login attempts

15 New Member
hi i'm a newbie in php..
can you help me how to make several login attempt in php?
(if we put wrong password/username,, we will go back to the previous form and we can try 3 more attempts to input the correct password/username before appear an error message)
thanks before..
Mar 25 '08 #1
18 2706
4,258 Recognized Expert Specialist
Welcome to The Scripts.

We cannot help you if we see no code to help or work on. So, first you'll have to show us the code you have written so far. Then we can have a look at how to limit the number of logins.

And show any code within the appropriate code tags!

Mar 25 '08 #2
15 New Member
sorry I didn't write the code..
here's my code..

this is the form.html
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <title>form</title>
  4.     </head>
  5.     <body>
  6.         <form action="login.php" method="post">
  7.             <table border=1>
  8.                 <tr>
  9.                     <td colspan=2>
  10.                         Login
  11.                     </td>
  12.                 </tr>
  13.                 <tr>
  14.                     <td>
  15.                         User
  16.                     </td>
  17.                     <td>
  18.                         <input type="text" name="user" value="<user>">
  19.                     </td>
  20.                 </tr>
  21.                 <tr>
  22.                     <td>
  23.                         Password
  24.                     </td>
  25.                     <td>
  26.                         <input type="password" name="pass" value="<pass>">
  27.                     </td>
  28.                 </tr>
  29.                 <tr>
  30.                     <td colspan=2>
  31.                         <input type="hidden" name="ct" value="0">
  32.                         <input type="submit" value="login">
  33.                         &nbsp; &nbsp; &nbsp; &nbsp;
  34.                         <input type="reset" value="cancel">
  35.                     </td>
  36.                 </tr>
  37.             </table>
  38.         </form>
  39.     </body>
  40. </html>
this is the login.php
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <title>login</title>
  4.     </head>
  5.     <body>
  6.         <?
  7.             $nama=$_POST["user"];
  8.             $pswd=$_POST["pass"];
  9.             $count=$_POST["ct"];
  10.             if(($nama=="admin")&&($pswd=="admin")){
  11.                 echo "Selamat datang <b>admin</b>";
  12.             }
  13.             else{
  14.                 if(count<10){
  15.                     $_POST["ct"]++;
  16.                     echo "User atau password yang anda masukkan salah, anda memiliki kesempatan untuk mencoba ";
  17.                     echo 10-$_POST["ct"];
  18.                     echo " kali lagi ";
  19.                 }
  20.                 else{
  21.                     echo "User atau password yang anda masukkan salah, silakan coba lagi atau hubungi customer service";
  22.                 }
  23.             }
  24.         ?>
  25.     </body>
  26. </html>
I tried to changed the value of "ct" but it didn't work..
Sorry if my question & my code looks silly, I'm very newb with php..
Mar 25 '08 #3
6,050 Recognized Expert Expert
So you aren't using a database to store log in details, this may make things harder.

What is the purpose of this 'counting of attempts'? Is it so that, after so many tries, the user is blocked from logging in for a certain amount of time?

I mean, you could use sessions, or cookies, but the user could just delete them.. so they're not a great idea. The best bet would be to store the user's IP address in a database, but by the looks of it you havent had a go with MySQL yet.

I recommend you have a look at some php/mysql tutorials - it'll benefit you greatly in the long run.

Regards, markus.
Mar 25 '08 #4
15 New Member
thanks for you reply markus but I haven't learnt that far..
this is the first day study about php.. and the purpose of this is just for practice..

can we change the value of the input in html using php?
Mar 25 '08 #5
6,050 Recognized Expert Expert
can we change the value of the input in html using php?
Can you explain abit more please?
Mar 25 '08 #6
15 New Member
<input type="hidden" name="ct" value="0">
can we change the value="0" in form.html form login.php?
another idea that I got is by writing the counter to file.. (but I haven't learnt how to use file in php)
beside that, I haven't got any idea..
Mar 25 '08 #7
4,258 Recognized Expert Specialist
Since you do not use a database to log login attemps (could be done on IP address), you can store the count in the $_SESSION array and increment it each time the script is re-executed. Like[php]if (isset($_SESSIO N['count'])) {
if ($_SESSION['count'] > 3) {
// issue message
Mar 25 '08 #8
15 New Member
thanks ronald..
now I'm reading about $_SESSION from w3school..
I hope it will solve the problem..
I'll give my report if I've try this..
Mar 25 '08 #9
6,050 Recognized Expert Expert
thanks ronald..
now I'm reading about $_SESSION from w3school..
I hope it will solve the problem..
I'll give my report if I've try this..
Thing is, as soon as the user closes the browser, the sessions are lost.
Defeating the error.
Mar 25 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

by: koolyio | last post by:
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"); ?>
by: VJ | last post by:
Hi, IIS raises login dialog box prompt on browser for resources protected using basic authentication. That login prompt gives user 3 attempts to enter correct userid/password. IIS throw 401.1 error if third attempt fails. Does anyone know how to change this number of attempts. Is it possible or impossible to do ? Thanks
by: Matthew Louden | last post by:
I wrote ASP.NET application that access SQL Server database. When I run the application, it yields "Login failed for user '<COMPUTER_NAME>\ASPNET'" error message. I then did the following, but still didn't work. Any ideas?? 1. In IIS console, right click the virtual directory 2. click directory security tab 3. click edit button on...
by: dharmbhav | last post by:
Hi, I am designing a login mechanism for a website. Presently, I am blocking the user account for 1 hour if there are 3 failed login attempts with-in 1 hour. However, I want to know if there is any best practice that can be followed on failed login attempts. Any help would be greatly helpful. Thanks, Dharmesh
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
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...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
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...
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...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.