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

Searching using mySql together with PHP
Symfony - Override sf_format when calling get_partial
Code Addition is Slowing Page Down
PHP 2-dimensional array -> how to convert to HTML table syntax?
Identify development vs. production server in PHP
How do I programmatically check whether a GIF image is animated?
How do you prevent inline <?= text ?> statement from messing up the displayed source code?
What character replacements should be performed to make base 64 encoding URL safe?
Using ajax to send GET to php file after change to input
Run Apache / PHP / MySQL (CakePHP) application on a USB stick?
PHP Debugging with Expressions?
Get wan ip address using php [closed]
PHP Sort array by month then year
which is the better way to get the ip
Why would rand() return a negative value when min and max values are positive?
Sanitize $_GET parameters to avoid XSS and other attacks

Categories

HOME
rust
office365
powerbi
automapper
adfs3.0
windows-10
mosquitto
angular-meteor
u-boot
elastic-load-balancer
siesta
lc3
webstore
dma
boomi
http-authentication
parceler
android-custom-view
jitsi
yii2-basic-app
weex
el
eclipse-emf
unordered-multimap
unrar
background-color
points
docx4j
tilemill
es6-modules
progid
steam-web-api
plantuml
universal
osx-lion
counting
image-optimization
apptentive
bean-validation
jfxtras
cups
mars-simulator
hidden-markov-models
flowchart
vungle-ads
morphline
zend-form
bit-shift
realstudio
head.js
watir-webdriver
http-basic-authentication
dynamics-crm-4
mpmovieplayercontroller
ternary-operator
tsqlt
node-glob
frame-grab
swiffy
android-expansion-files
ui4j
variable-length-array
http.client
android-studio-import
blockquote
google-gdk
embeddedwebserver
cache-manifest
textscan
tidyr
pass-by-value
operands
dos2unix
juttle
flurry-analytics
ildasm
jini
ivalueconverter
jms-serializer
mft
acitree
non-ascii-characters
clrprofiler
voice-recording
zotonic
pcspim
kobold2d
dynamic-c
nsrangeexception
space-partitioning
dip
ccnet-config
icicles
j2mepolish
google-translator-toolkit
stretchblt
gui-designer

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App