Jump to content

Recommended Posts

I created a Log in with password and all that good stuff

and You can log on to the web site and autheticate.... That is all cool now here is the issue....

I can Log in and I carry a variable saying display the name "John  Doe"..

Then I click and  go to another page ... and i can test the session is active ...

session(): that is okay ....BUT !!!!!!!!

The session does not test to show that the session is "JOHN DOE" session....



Example:

1.Log in page

JOHN DOE AUTHENTICATES

2.Confirmation or welcome page...

        Session is True
        JOHN DOE YOU ARE LOG IN

3.Page X

        Session is True
        "Blank - Nothing displays" you are log in



So i can not probe in that page that John Doe is the one log in ????

can some one help i have check all the books and I can find a explanation ....
I also try passing a variable but i guess i did it wrong.



Link to comment
https://forums.phpfreaks.com/topic/32572-solved-session-and-id/
Share on other sites

okay here is my code...

the Authetication page is HTML

Name and password you know thw basic stuff...

then you get this cheking if you indded logged-in sucessfully

CODE:
[code]
<?php
session_start();
include("LOGINFO.php");

///////////////Variables///////////////////////////////////////////////////////
$table = 'md_user_main';
$email = $_POST['email'];
$password = md5($_POST['password']);
$wtd = "relogin";

///////////////////////////////database connection and array//////////////////
 
    $tc = mysql_connect ($host, $user, $pass);
    $db = mysql_select_db ($database, $tc);

$query = "SELECT * FROM $table WHERE (email=\"$email\") ";
$result = mysql_query($query);
$row = mysql_fetch_array($result);

                $fname= $row['first_name'];

//////////////////////////Re Log In///////////////////////////////////////////// 

if($_SESSION['session_var'] == "skipLogin"){
    echo "$fname is Log-In";
echo "<br>If you like to end the session, Click here to Log-Off";
  }else if($wtd == "relogin"){
 
    if($password == $row['password']){
          echo "You are loged In $fname";
      $_SESSION['session_var'] = "skipLogin";
    }else{
          echo "You are not log-In try again";
//session_destroy();
//unset($_SESSION);
    }
    }
?>
[/code]
Then I created this test to check if the session and user are log-in in a 3rd page ...here is where the session is active but I can't ID the user....
before i try passing  a variable but it didn't work so this is what i have now...

what i will like is to say who is Loged In

[code]
<?php
session_start();
 
  if($_SESSION['session_var'] == "skipLogin"){
  echo "You are loged-In";
echo "<br>Session still active";
  }else{
    echo "You stinky";
  }

?>
[/code]



Link to comment
https://forums.phpfreaks.com/topic/32572-solved-session-and-id/#findComment-151465
Share on other sites

You need to put the name into a session variable too...

[code=php:0]
if($password == $row['password']){
  echo "You are loged In $fname";
  $_SESSION['session_var'] = "skipLogin";
  $_SESSION['fname'] = $fname; // I added this line
}else{
  echo "You are not log-In try again";
  //session_destroy();
  //unset($_SESSION);
}[/code]

Then when you echo [code=php:0]$_SESSION['fname'][/code] you get their name.

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/32572-solved-session-and-id/#findComment-151468
Share on other sites

one more ?


I put this on my session test ... but it won't show the name,  if I put the $_SESSION['fname'] in a variable

if i do           """"       echo $_SESSION['fname'];      """""  that display the name
but when i do a variable like below it just show """""   You are loged In """""

<?php
session_start();
   
    if($_SESSION['session_var'] == "skipLogin"){
           $_SESSION['fname'] = $fname;
           echo "You are loged In $fname";      
   
    }else{
          echo "You stinky";
    }

?>
Link to comment
https://forums.phpfreaks.com/topic/32572-solved-session-and-id/#findComment-151572
Share on other sites

[quote author=Jay2391 link=topic=120690.msg495465#msg495465 date=1167761750]
one more ?


I put this on my session test ... but it won't show the name,  if I put the $_SESSION['fname'] in a variable

if i do           """"       echo $_SESSION['fname'];      """""  that display the name
but when i do a variable like below it just show """""   You are loged In """""

<?php
session_start();
   
    if($_SESSION['session_var'] == "skipLogin"){
           $_SESSION['fname'] = $fname;
           echo "You are loged In $fname";      
   
    }else{
          echo "You stinky";
    }

?>

[/quote]

You have to remember how variable assignment works.  The left side of the statement is assigned the value of the right side.  So, if you haven't defined $fname in your script, you're merely overwriting your session variable with an empty local variable, hence no output.  Since it looks like you're trying to assign a local variable the contents of your session variable, switch the statement around.  In other words:

$fname = $_SESSION['fname'];
Link to comment
https://forums.phpfreaks.com/topic/32572-solved-session-and-id/#findComment-151600
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.