Jump to content

A poor understanding of sessions


GreenFanta

Recommended Posts

Basically, I've developed a basic registration and login code whereby it inserts and retrieves data from MySQL, however my login code is giving me problems in a sense that I don't understand the concept of the "session" feature, my understanding of it, is that it places a cookie on your computer and verifies it on each request called by the page with the start_session() function on it, if so, is this correct?

 

My Header for all pages:

<?php session_start(); ?>

 

When the client logs in successfully:

$_SESSION["myusername"] = $myusername;
$_SESSION["mypassword"] = $mypassword;
// Both Local variables ($myusername and $mypassword) are from the matching database and client entered values.

 

When the client navigates to a completely different page:

if (isset($_SESSION['myusername'])) {
// Do x
} else {
// Do y
}
// It is never doing X for me.

 

 

Thanks!

 

Regards

Matthew

 

Link to comment
Share on other sites

Well, it just displays HTML through if functions in PHP, all I'm really trying to do is when the user uses my login interface then it must register the session, I have used

session_start()

on every single page and (since its in the header which is included in every page) and the header also goes to an

if(isset($_SESSION['myusername']))

, so it's mainly the header that's checking whether the user is logged in or not and then it adjusts the menu buttons appropriately, and that's all I'm trying to do, and I've provided the only code that would logically make a difference to the session as nothing happens in between with any variables etc..

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.