So i got a login page up and running But just a question How do i make it so when a person logins that it will Pull up there informatio?
Please Help
So i got a login page up and running But just a question How do i make it so when a person logins that it will Pull up there informatio?
Please Help
… cant find the edit button but heres my code for everything
Main Login
[code]
Untitled Document
|
Check Login
[code]<?php
include_once ‘config.php’;
// Connect to server and select databse.
mysql_connect("$host", “$user”)or die(“cannot connect”);
mysql_select_db("$db")or die(“cannot select DB”);
// username and password sent from form
$username=$_POST[‘username’];
$password=$_POST[‘password’];
// To protect MySQL injection (more detail about MySQL injection)
$username = stripslashes($username);
$mypassword = stripslashes($password);
$username = mysql_real_escape_string($username);
$mypassword = mysql_real_escape_string($password);
$sql=“SELECT * FROM $dbname WHERE username=’$username’ and password=’$password’”;
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched username and password, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file “login_success.php”
session_register(“username”);
session_register(“password”);
header(“location:login_success.php”);
}
else {
echo “Wrong Username or Password”;
}
?>
[/code]
Login pass
[code]<?
session_start();
if(!session_is_registered(myusername)){
header(“location:test.php”);
}
?>
then to test.php
[code]
<?php include_once 'config.php'; mysql_connect($host,$user); mysql_select_db("underworld") or die(mysql_error()); ?> Untitled DocumentLogin Successful
and config.php
[code]
<? $host="localhost"; $user="root"; $port="3306"; $db="underworld"; $dbname="account"; mysql_connect($host,$user); mysql_select_db("underworld") or die(mysql_error()); ?>[/code]The function session_register has been depreciated - it will be removed from PHP in a future release. Therefore, you should just use the $_SESSION array directly:
[php]session_register(“username”);
session_register(“password”);[/php]
Turns into:
[php]$_SESSION[‘username’] = ‘some value’;
$_SESSION[‘password’] = ‘some value’;[/php]
Also, on this line:
[php]if(!session_is_registered(myusername)){[/php]
You’re checking the session myusername when you’re actually setting the username session name above. As well as this, I wouldn’t recommend storing the users’ password in a session - on a shared server or one with insecure session storage, a person could read the passwords of your users. If you want to get the details of the user (other than their username) then you could use a query to get the user based upon what’s in the username session value:
[php]$query = mysql_query(“SELECT * FROM account WHERE account.username = '” . $_SESSION[‘username’] . “’”);
if(mysql_num_rows($query) == 1) {
$user = mysql_fetch_array($query);
echo $user[‘some-key’];
echo $user[‘favourite-sweet’];
} else {
die ‘Invalid user!’; // The username they’re logged in as does not exist
}[/php]
In the code I gave above (as a replacement to session_register), you would need to store the value of the username. In your code, you do not specify this value. I would assume you would use the $username variable:
[php]$_SESSION[‘username’] = $username;[/php]
sorry im still in the process of learning all about this so how would i set this up, like would it go under checklogin or Passlogin or the main login