Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP login/registration help

Featured Replies

Right im a bit of a beginner at this so please me gentle and try and help me as much as possible

 

Ive got a login & registration system currently in place which:

-users enter their details (they must check T&A before they can register)

-this data is then sent to a database

-A 'registration successful' is displayed and then gives them button to return home

-They can then log in and if sucessful displays 'login successful return home' or is not displays 'incorrect username/password' on another page

-It also then shows them logged in too

 

I have a couple of questions....

-Can anyone aid me on a system to send a email to confirm registration

-To get 'incorrect unsername/password' to display in an alert box

-if possible a forgotten password

 

Now before you say i have searched the net and found some tutorials but it doesnt really make sense to me. These toturials are starting from scratch and i want to add it to my current system.

 

PLEASE remember i am a BEGINNER

 

I have included some of my code

 

thanks

 

<form method="post" name="form1" action="checklogin.php"> Login: <input id="myusername" size="14" name="myusername"/> Password: <input id="mypassword" size="14" type="password" name="mypassword"/> <input value="Login" type="submit" name="mysubmit"/></form>New users? <a href="Untitled7.php">click here</a><a href="Untitled8.html">Forgotten password?<br/></a></font>

 

<?php
error_reporting(-1); 
ini_set('display_errors', true); 

function exit_with_error($message){ 
 echo $message; 
 exit; 
} 

function escape($value){ 
 return mysql_real_escape_string($value); 
} 

if('POST' !== $_SERVER['REQUEST_METHOD']){ 
 exit_with_error('No form submission'); 
} 

$con = mysql_connect('localhost', 'root', ''); 

if(false === is_resource($con)){ 
 exit_with_error('Cannot connect: ' . mysql_error()); 
} 

if(!mysql_select_db('test')){ 
 exit_with_error('Cannot select database: ' . mysql_error()); 
} 

$sql = sprintf( 
 "SELECT username FROM members WHERE username = '%s' AND password = '%s' LIMIT 1;", 
 escape($_POST['myusername']), 
 sha1($_POST['mypassword']) 
); 

$res = mysql_query($sql); 

if(false === is_resource($res)){ 
 exit_with_error('Cannot execute query: ' . mysql_error()); 
} 

if(1 !== mysql_num_rows($res)){ 
 exit_with_error('Incorrect username/password'); 
} 

session_start(); 
$_SESSION['myusername'] = $_POST['myusername']; 
$_SESSION['mypassword'] = $_POST['mypassword']; 
header('location:login_success.php'); 
exit;


?>

 

<?php 
error_reporting(-1); 
ini_set('display_errors', true); 

function exit_with_error($message){ 
 echo $message; 
 exit; 
} 

if($_POST['password'] !== $_POST['password2']){ 
 exit_with_error('Your passwords must match'); 
}

function escape($value){ 
 return mysql_real_escape_string($value); 
} 

if('POST' !== $_SERVER['REQUEST_METHOD']){ 
 exit_with_error('No form submission'); 
} 

$con = mysql_connect('localhost', 'root', '');


if(false === is_resource($con)){ 
 exit_with_error('Cannot connect: ' . mysql_error()); 
} 

if(!mysql_select_db('test')){ 
 exit_with_error('Cannot select database: ' . mysql_error()); 
} 

$sql = sprintf( 
 "INSERT INTO members (firstname, lastname, username, email, password, home_number, home_address1, home_address2, County, postcode ) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');", 
 escape($_POST['firstname']), 
 escape($_POST['lastname']), 
 escape($_POST['username']), 
 escape($_POST['email']), 
 sha1($_POST['password']),
 escape($_POST['house_number']),
 escape($_POST['home_address1']),
 escape($_POST['home_address2']),
 escape($_POST['County']),
 escape($_POST['postcode']) 
); 

if(!mysql_query($sql)){ 
 exit_with_error('Cannot save record: ' . mysql_error()); 
} 

echo 'Record saved!';

?>

 

<?php
// Check if session is not registered , redirect back to main page. 
// Put this code in first line of web page.  
session_start();
if (!$_SESSION['myusername']) {  
header("location:main_login.php");
}
?>

<p align="center">
               <font size="5" face="Tempus Sans ITC">
                 <strong>Login Sucessfull!</strong> </font>
             </p>

just like youve inserted the rest of the data into the database

make a new row called confirmid and give set it to INT and legnth as 7

then in the php use the RANDOM function to create a number between 1000000 and 9000000 or something

 

then in the email theyll have a link to your website with that random number and then you could edit it so that the php checks that number and then confirms the email if its correct

 

if you need any more help just ask :D, oh and dont forget when you create the new unique id you check it doesnt already exist before you set it :D

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.