Jump to content

display $first_name and $surname after logging in


MFA

Recommended Posts

Hey guys.

 

i'm new at coding and need some help. I'm tryin to get my site to say "Welcome, $first_name $surname ! .... etc etc" after the individual logs in and it's not working for some mysterious reason. Currently, it's saying everything else I want it to but it's ommiting the $first_name and $surname fields that i want it to show. Could someone please let me know why its not working and how I can fix it. Thanks.

 

Here's what I've got:

 

this file below is called checkuser.php

 

<?

/* Check User Script */

session_start(); // Start Session

 

include 'db.php';

// Conver to simple variables

$email_address = $_POST['email_address'];

$password = $_POST['password'];

 

if((!$email_address) || (!$password)){

echo "Please enter ALL of the information! <br />";

include 'login_form.html';

exit();

}

 

// Convert password to md5 hash

 

!!!!DELETED!!!! - for security reasons

 

// check if the user info validates the db

$sql = mysql_query("SELECT * FROM users WHERE email_address='$email_address' AND password='$password' AND email_activated='1'");

$login_check = mysql_num_rows($sql);

 

if($login_check > 0){

while($row = mysql_fetch_array($sql)){

foreach( $row AS $key => $val ){

$$key = stripslashes( $val );

}

// Register some session variables!

session_register('first_name');

$_SESSION['first_name'] = $first_name;

session_register('surname');

$_SESSION['surname'] = $surname;

session_register('email_address');

$_SESSION['email_address'] = $email_address;

session_register('special_userY1');

$_SESSION['account_type'] = $account_type;

 

mysql_query("UPDATE users SET last_login=now() WHERE userid='$userid'");

 

header("Location: login_success.php");

}

} else {

echo "You could not be logged in! Either the email_address and password do not match or you have not validated your membership!<br />

Please try again!<br />";

include 'login_form.html';

}

?>

 

this file below is called login_success.php

 

 

<?

session_start();

 

echo "Welcome ". $_SESSION['first_name'] ." ". $_SESSION['surname'] ."! You have made it to the members area!<br /><br />";

 

echo "Your user level is ". $_SESSION['account_type']." which enables you access to the following areas: <br />";

 

if($_SESSION['account_type'] == 1){

echo "- Forums<br />- Chat Room<br />";

}

if($_SESSION['account_type'] == 2){

echo "- Forums<br />- Chat Room<br />- Moderator Area<br />";

}

 

echo "<br /><a href=logout.php>Logout</a>";

 

?>

Link to comment
Share on other sites

That code is out of date by at least a decade, and is not at all secure. None of the form data is escaped before using it in the db query, there is no reason to use stripslashes() on data from the database except in the case it was improperly inserted to begin with, session_register() has been deprecated since the mid-1800s, I believe . . .

Link to comment
Share on other sites

Oh dear.. What do you mean by not being secure? - as in people will be able to login without registering or something worse?

 

Also, I get the impression I need to start all over again for creating my membership system. Could you please advise on a tutorial I could follow?

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.