get information after login

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
arbitter
Forum Newbie
Posts: 24
Joined: Tue Dec 29, 2009 10:04 am

get information after login

Post by arbitter »

So my problem is, I want to get information of the user after logging in and store it in a $_SESSION().
I want to get the name of the person and the emailadress, to be stored in $_SESSION('name') or something.
I'm quite new to php, so please try to explain carefully... I've read through the whole $_SESSION() explanation

Code: Select all

<?php
session_start();
                        $_SESSION["email"] = $email;
                        $_SESSION["wachtwoord"] = $wachtwoord;
                        $_SESSION["name"] = $row['name'];
 
if (isset($_POST['actie'])) {
    $emailadres = $_POST['e'];
    $paswoord = $_POST['w'];
    $emailadres = strip_tags($emailadres); 
    $paswoord = strip_tags($paswoord); 
    $paswoord = trim($paswoord); 
    $emailadres = trim($emailadres);
    $melding = "give in a good emailadress";
        if (strlen($emailadres) > 50) {
            $melding = "wrong adress ";}        
        else {
            require_once('is_email.inc.php');
            if (is_email($emailadres)) {
                $actie = $_POST['actie'];
                if ($actie === "Login" ) {
                    
                    if ($actie == "Login") {
                        $sql = "SELECT * FROM users WHERE email='" . $_POST["e"] ."' AND password='". $_POST["w"]. "'"; 
                    }
                    
                    require_once('mysql_connect.inc.php');
                    
                    $verbinding = mysql_connect(MYSQL_SERVER, MYSQL_GEBRUIKERSNAAM, MYSQL_WACHTWOORD) or die("Verbinding mislukt: " . mysql_error());
                    
                    mysql_select_db("users") or die("couldn't open: " . mysql_error());
                    // Query zonder resultaatset uitvoeren:
                    $result = mysql_query($sql) or die("Query failed: " . mysql_error());
                    $row=mysql_fetch_array($result);
                    if(!empty($row)){
                        
                        $email = $_POST["e"];
                        $password = $_POST["w"];
 
 
                        
                        header("Location: upload.php");
                        exit(); }   } 
                if(empty($row)){
                    $melding = "blablabla, you have to register and stuff";}
                
                mysql_close($verbinding);} 
            else {
                $emailadres = htmlentities($emailadres, ENT_QUOTES);
 
                if (strlen($emailadres) < 1) {
                    $melding = "input an email ";} 
                else {
                    $melding = "this email isn't legit ";
                    $melding .= "type another emailadress";}}}} 
else {
    $emailadres = "";
 
    $melding = "input legit pass and email";}
?>
jaiswarvipin
Forum Commoner
Posts: 32
Joined: Sat Sep 12, 2009 3:43 pm
Location: India

Re: get information after login

Post by jaiswarvipin »

Pelase refer you updated code.

Code: Select all

<?php
session_start();
$_SESSION["email"] = "";
$_SESSION["wachtwoord"] = "";
$_SESSION["name"] = "";
 
if (isset($_POST['actie'])) {
    $emailadres = $_POST['e'];
    $paswoord = $_POST['w'];
    $emailadres = strip_tags($emailadres); 
    $paswoord = strip_tags($paswoord); 
    $paswoord = trim($paswoord); 
    $emailadres = trim($emailadres);
    $melding = "give in a good emailadress";
        if (strlen($emailadres) > 50) {
            $melding = "wrong adress ";}        
        else {
            require_once('is_email.inc.php');
            if (is_email($emailadres)) {
                $actie = $_POST['actie'];
                if ($actie === "Login" ) {
                    
                    if ($actie == "Login") {
                        $sql = "SELECT * FROM users WHERE email='" . $_POST["e"] ."' AND password='". $_POST["w"]. "'"; 
                    }
                    
                    require_once('mysql_connect.inc.php');
                    
                    $verbinding = mysql_connect(MYSQL_SERVER, MYSQL_GEBRUIKERSNAAM, MYSQL_WACHTWOORD) or die("Verbinding mislukt: " . mysql_error());
                    
                    mysql_select_db("users") or die("couldn't open: " . mysql_error());
                    // Query zonder resultaatset uitvoeren:
                    $result = mysql_query($sql) or die("Query failed: " . mysql_error());
                    $row=mysql_fetch_array($result);
                    if(!empty($row)){
                        
                        $_SESSION["email"] = $_POST["e"];
                        $_SESSION["wachtwoord"] = $wachtwoord;
                        $_SESSION["name"] = $row['name'];
 
                                          
                        header("Location: upload.php");
                        exit(); }   } 
                if(empty($row)){
                    $melding = "blablabla, you have to register and stuff";}
                
                mysql_close($verbinding);} 
            else {
                $emailadres = htmlentities($emailadres, ENT_QUOTES);
 
                if (strlen($emailadres) < 1) {
                    $melding = "input an email ";} 
                else {
                    $melding = "this email isn't legit ";
                    $melding .= "type another emailadress";}}}} 
else {
    $emailadres = "";
 
    $melding = "input legit pass and email";}
?>
in the code

Code: Select all

$_SESSION["wachtwoord"] = $wachtwoord;
what is not clear,. so pelase put at appropriate place
arbitter
Forum Newbie
Posts: 24
Joined: Tue Dec 29, 2009 10:04 am

Re: get information after login

Post by arbitter »

Sorry for the mess... But thank you for the explanation.
I tried it but it didn't work for the name; the problem was that I had forgotten to re-login using my login page so that that data would be stored.

Thanks for the help, this will get me a lot further!
Post Reply