PHP login/registartion help XAMPP

Problems with the Windows version of XAMPP, questions, comments, and anything related.

PHP login/registartion help XAMPP

Postby louismoore18 » 26. June 2011 10:43

Hello, im using XAMPP so i thought it would be able to ask you friendly guys for help

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

Code: Select all
<form method="post" name="form1" action="checklogin.php">&nbsp;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>


Code: Select all
<?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;


?>


Code: Select all
<?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>


Code: Select all
<?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!';

?>
louismoore18
 
Posts: 5
Joined: 14. June 2011 10:29

Re: PHP login/registartion help XAMPP

Postby Sharley » 26. June 2011 11:19

Not really in the scope of this XAMPP forum - someone may help but...

...why reinvent the wheel - there are many quality free php scripts already written if you know where to find them.

Here are a few places that have these types of PHP scripts:

All free here.
http://www.scriptdungeon.com/free_php_s ... cripts.php
From this site:
http://www.scriptdungeon.com/php_scripts.php


Mostly free but some commercial offerings here.
http://www.hotscripts.com/category/php/ ... anagement/
http://www.hotscripts.com/category/php/ ... ntication/
From this site:
http://www.hotscripts.com/category/php/ ... -programs/
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Re: PHP login/registartion help XAMPP

Postby JonB » 26. June 2011 17:57

This might work for you -

http://www.locked-area.com/?dp

The Lite version is free

I use their DIrectoryPass authentication management (also free) and its a superior product.

Good Luck
8)
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 85 guests