php


Multi level login by address


I'm struggling with the project I want to make. I need to do a multi level login by address, so if new user registers with its unique address, the mysql database would update. Also, few users (1-8 people) could register to the same address and could see the same information. I have set up the login and register forms successfully, it sends the information to the database.
The thing is, the information (the html pages) which user will see after they register can't be static, they needs to be created with every new address registered.
I hope I stated my problem as clearly as possible.
My codes:
Register.php
<?php
session_start();
if(isset($_SESSION['usr_id'])) {
header("Location: index.php");
}
include_once 'Dbconnect.php';
//set validation error flag as false
$error = false;
//check if form is submitted
if (isset($_POST['signup'])) {
$username = mysqli_real_escape_string($con, $_POST['username']);
$password = mysqli_real_escape_string($con, $_POST['password']);
$cpassword = mysqli_real_escape_string($con, $_POST['cpassword']);
$city = mysqli_real_escape_string($con, $_POST['city']);
$street = mysqli_real_escape_string($con, $_POST['street']);
$number = mysqli_real_escape_string($con, $_POST['number']);
//name can contain only alpha characters and space
if (!preg_match("/^[a-zA-Z ]+$/",$username)) {
$error = true;
$username_error = "Name must contain only alphabets and space";
}
if(strlen($password) < 6) {
$error = true;
$password_error = "Password must be minimum of 6 characters";
}
if($password != $cpassword) {
$error = true;
$cpassword_error = "Password and Confirm Password doesn't match";
}
if (!$error) {
if(mysqli_query($con, "INSERT INTO login(username,password,city,street,number) VALUES('" . $username . "', '" . md5($password) . "', '" .$city . "', '" .$street . "', '" .$number . "')")) {
$successmsg = "Successfully Registered! <a href='login.php'>Click here to Login</a>";
} else {
$errormsg = "Error in registering...Please try again later!";
}
}
}
?>
Login.php
<?php
session_start();
if(isset($_SESSION['usr_id'])!="") {
header("Location: ../index.php");
}
include_once 'Dbconnect.php';
//check if form is submitted
if (isset($_POST['login'])) {
$email = mysqli_real_escape_string($con, $_POST['email']);
$password = mysqli_real_escape_string($con, $_POST['password']);
$result = mysqli_query($con, "SELECT * FROM login WHERE username = '" . $username. "' and password = '" . md5($password) . "'");
if ($row = mysqli_fetch_array($result)) {
$_SESSION['usr_id'] = $row['id'];
$_SESSION['usr_name'] = $row['name'];
header("Location: ../index1.php");
} else {
$errormsg = "Incorrect Email or Password!!!";
}
}
?>
EDITED:
<?php
include "config.php";
if(isset($_POST['username']) && isset($_POST['password'])){
$username = $_POST['username'];
$password = md5($_POST['password']);
$stmt = $db->prepare("SELECT * FROM login WHERE username=? AND password=? ");
$stmt->bindParam(1, $username);
$stmt->bindParam(2, $password);
$stmt->execute();
$row = $stmt->fetch();
$user = $row['username'];
$pass = $row['password'];
$id = $row['id'];
$type = $row['type'];
if($username==$user && $pass==$password){
session_start();
$_SESSION['username'] = $user;
$_SESSION['password'] = $pass;
$_SESSION['id'] = $id;
$_SESSION['type'] = $type;
?>
<script>window.location='index.php'</script>
<?php
} else {
?>
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span></button>
<strong>Woops! </strong>Password is incorrect
</div>
<?php
}
}
?>

Related Links

includes php files from subfolder in the root
How to make local storage with laravel?
prestashop's live url redirecting to my localhost
website showing index.php file data
CodeIgniter upload fail no error logs no error reporting
How make long PHP script faster?
PHP - Parse XML
Linux Ubuntu PHP Version is different in CLI and in PHPINFO()
PHP curly braces inside strings colour in Notepad++
How to clean background captcha image using imagick
How can I get Magento Each Session values by using Magento frontend cookie value through Web Service?
WooCommerce displaying variable description after variable price
if else condition in jquery ajax response
php fastcgi is crashing if the url contains &start_debug=1
Having issue modifying theme code to replace logo URL
Combination of php_opcache and IIS causing intermittent 500 errors

Categories

HOME
php
svn
paypal-ipn
braintree
openlayers-3
hyperledger
position
mithril.js
phpseclib
scheduler
android-externalstorage
grocery-crud
heap-dump
rpmbuild
xsl-fo
nullreferenceexception
web-analytics
environment
hdmi
php-5.3
audit
intune
memory-fences
xcrun
rspec-rails
sca
apptentive
cmis
uivisualeffectview
classnotfoundexception
distributed-caching
notesview
type-inference
spongycastle
tinyioc
brightscript
head.js
visual-format-language
palindrome
portability
alertify
msxml
ltrace
ogg
elastic4s
libharu
seccomp
groovyfx
qpixmap
timestamping
xcopy
okta-api
diawi
outlook.com
decidable
android-studio-import
sqlbase
jnlp
unidata
tree-structure
shell-extensions
directorysearcher
vs-unit-testing-framework
igor
libgcc
csslint
incognito-mode
sql-function
jchartfx
jomsocial
compiler-flags
acitree
django-filebrowser
jquery-dialog
towers-of-hanoi
gitx
voice-recording
server-name
exponent
css-friendly
digiflow
downgrade
mongrel
activestate
motif
datagridcolumn
comment-conventions

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App