Unstoppable Domains

Simple login system

Spaceship Spaceship
Watch

craigb

New Member
Impact
0
Hi,

i have just created a simple login system but would like to expand on for users to be directed to a specific page.

for example if John logins in then his username and password will direct him to john.php

if mary logins in then her username and password will direct him to mary.php

do any of you know of any tutorials or scripts that could help me set this up?

cheers
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
If you want to go for a really simple solution, after login:

include($username.".php")
 
0
•••
cheers for the reply but i'm still trying to get my head around programming so i'm not sure how to immplement your sugestion. My login form is located on index.php which posts the information to checklogin.php where the following code is. At the moment if the login is successful it directs to index_investors.php

<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");



$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);


// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername and redirect to file "index_investors.php"
session_register("myusername");
header("location:index_investors.php");
}
else {
header("location:sorry.php");
}
?>
 
0
•••
that code doesn't look like a login script to me.

That is just seeing if there is an entry in a table of the database, if there is it redirects if not then it redirects to the sorry page.
 
0
•••
i've added this to line 10 to check if a user is listed in the database. any suggestions on how to finish off the code to redirect a user to there specific page, thanks

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
 
0
•••
header("location:$myusername.php");
 
0
•••
i put in header("location:$myusername.php"); (see below) and under the user name 'john' i created a page called john.php but when trying to login it's throwing up an error, could you check the code for me, thanks



<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);


// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername and redirect to each users login
session_register("myusername");
header("location:$myusername.php");
}
else {
header("location:sorry.php");
}
?>
 
0
•••
what was the error it gave you?
 
0
•••
I've sorted out the errors and i've added a logout and this allows the next user to login to their page, this isn't ideal as if somebody closes their browser without logging out then the next person to login may end up on the wrong page.

what bit of code could i add to john.php to prevent other people from visiting the page? thanks
 
Last edited:
0
•••
If someone closes their browser then the sessions variables are forgot about. Meaning someone will have to log in again. Also for extra precaution you could take a look at setting sessions lifetime. Have a search on google for that if you really want it.

Generally all that is needed for a login script is to set the sessions as user dont tend to use the same computer.
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99
Appraise.net

We're social

Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back