Jump to content

PHP Login Question / Need Help!


Eliasam13

Recommended Posts

Hello, Iv searched everywhere trying to find the answer to my problem...

 

Im trying to make a login form (Username / Password Authentication) and for each user that has a login / password they will be redirected to a specific page..

 

for example if the user "Mike" log's in he will be directed to page1.  If the user "Jon" log's in he will be directed to page2.

 

And really the only login i know how to do is to direct all users to one location...

 

I hope someone can help me!!

Link to comment
Share on other sites

This is what im trying to do... My customer will have there own username and password.

 

Each of the customers will go to a specific page relating to there information.

 

Page 1 Will Have information regarding customer "Mike".  Having information such as his Name and address, his recent purchase, etc..

 

Page 2 Will be the same thing but information related to "Jon".

 

thats what im trying to do..

 

How can I redirect all my cutomers to there OWN specific page in php?

Link to comment
Share on other sites

Why don't you just make the account page dynamic by calling from a database.

 

e.g.

 

When the user logs in, start a session calling the username from the form..

 

 

Login process:

 

<?php
session_start();

$username = $_POST['username'];
$password = $_POST['password'];

$sql = mysql_query(sprintf("SELECT * FROM `users` WHERE `username` = '%s' AND `password` = '%s' LIMIT 1", $username, $password)) or die('Error: ' . mysql_error());

if($obj = mysql_fetch_object($sql))
{
  $_SESSION['valid'] = true;
  $_SESSION['username'] = $username;
  echo '<script type="text/javascript">window.location = "account.php";</script>';
}
else
{
  echo 'Your credentials appear to be invalid.';
}
?>

 

 

 

Then for the account page:

 

<?php
session_start();

if($_SESSION['valid'])
{
  $username = $_SESSION['username'];
  $sql = mysql_query(sprintf("SELECT * FROM `users` WHERE `username` = '%s' LIMIT 1", $username)) or die('Error: ' . mysql_error());

  if($obj = mysql_fetch_object($sql))
  {
    echo 'Username: ' . $username;
    echo 'E-Mail Address: ' . $obj->email;
  }
}
else
{
  echo 'You are not logged in.';
}
?>

 

This is a very basic example.

Link to comment
Share on other sites

yes indeed. it would be much easier to extend your existing users table like this

 

as it is now (i'm guessing)

user_id | name | password

 

as it should be

 

user_id | name | password | a | field | for | everything | you | want | to | save.

 

And then in your code when the user has entered the correct login and password, you should add smth like $_SESSION['userid'] = $id (where $id could be fetched from the database).

 

Next, you redirect them all to the same page which has a table like

<?php

$userid = $_SESSION['userid'];

$userdata = mysql_fetch_assoc(mysql_query("SELECT * FROM users WHERE user_id = $userid));

echo "<ul>\n<li>Name: $userdata['name']</li>\n<li>Field: $userdata['field']</li>\n</ul>";

?>

Something like that...

Link to comment
Share on other sites

Header wouldn't be able to be used along with starting a session at the beginning.

ob_start; workaround?

 

You don't need output buffering. Yes, you cannot send headers after output to the browser without using output buffering, but starting a session and assigning session variables does not output anything to the browser.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.