HI,
I hope someone can help. I'm trying to show the username of the logged in user on this menu.inc page and certain pages only when logged in.
The result I have with the code below is no username showing, just "Hi !" (the "login" link disappear as planned) and all pages showing (logged and un-logged)
thank you for your help - <div style="margin-bottom: 0px; margin-left: auto; margin-right: auto; margin-top: 0px; overflow: visible;">
-
-
-
<div align="center">
-
<table border="0">
-
<tr>
-
<th>
-
<span class="small">
-
<?php if ($_SESSION["loggedInUser"] == $_SESSION["userCakeUser"]) { ?>Hi <strong><?php echo $_SESSION[$userdetails["Username"]]; ?>
-
-
!
-
-
<?php } else { ?><a href="login.php">Login</a>
-
<?php } ?>
-
</span> </th>
-
-
</tr>
-
<tr>
-
<td>
-
<span class="small">
-
<?php if ($_SESSION['loggedInUser'] == $_SESSION["userCakeUser"]) { ?><a href="logout.php">Logout</a>
-
-
<?php } else { ?>Register <a href="register.php" class="text_left">here </a>to download full mixes<?php } ?>
-
</span>
-
</td>
-
</tr>
-
</table>
-
</div>
-
-
<hr width=600px>
-
-
<a href="<?php echo $main_path; ?>index.php">Welcome</a><a href="
-
<?php echo $main_path; ?>Bio.php">Bio</a>
-
-
<!--logged-in-->
-
<?php if ($_SESSION['loggedInUser'] == $_SESSION["userCakeUser"]) { ?>
-
-
<a href="<?php echo $main_path; ?>Mixes.php">Mixes</a>
-
-
-
<a href="<?php echo $main_path; ?>Production.php">Production</a>
-
-
<?php } ?>
-
-
<!--not-logged-in-->
-
<?php if ($_SESSION['loggedInUser'] == NULL) { ?>
-
-
<a href="<?php echo $main_path; ?>mixes_unlogged.php">Mixes</a>
-
-
<a href="<?php echo $main_path; ?>production_unlogged.php">Production</a>
-
-
<?php } ?>
-
-
<a href="<?php echo $main_path; ?>Contact.php">Contact</a>
-
<a href="<?php echo $main_path; ?>links.php">Links</a>
-
<hr width=500px>
22 2830
obviously $_SESSION[$userdetails["Username"]] does not exist or is empty. try var_dump($_SESSION); to see what’s going on.
thx Dormilich. Sorry I'm really no expert in php, shall I put this instead of my query or after?
I've added it within the query and it brings NULL back. Does it mean username isn't what I should be using then?
what query? it doesn’t matter where you put this, as long as it is executed.
if var_dump($_SESSION); brings up NULL, there is something wrong with the session.
ok...what can I do to find out what's wrong with it?
check out, where you set $_SESSION to NULL.
ok, I've checked this out and this is the "config.php" file, where the $_SESSION is set to NULL if not logged in and to $_SESSION["userCakeUser"] if logged in (see code below)
Am I not using this properly? - <?php
-
include("settings.php");
-
-
//Dbal Support - Thanks phpBB ; )
-
include("classes/db/".$dbtype.".php");
-
-
//Construct a db instance
-
$db = new $sql_db();
-
if(!$db->sql_connect($db_host, $db_user, $db_pass, $db_name, $db_port, false, false)) die("Unable to connect to the database");
-
-
//Include classes
-
include("classes/class_newuser.php");
-
include("classes/class_newmail.php");
-
include("classes/class_loggedinuser.php");
-
-
//Include Functions
-
include("functions/user-funcs.php");
-
include("functions/general-funcs.php");
-
-
-
session_start();
-
-
//Global User Object Var
-
//loggedInUser can be used globally if constructed
-
if(isset($_SESSION["userCakeUser"]) && is_object($_SESSION["userCakeUser"])) $loggedInUser = $_SESSION["userCakeUser"]; else $loggedInUser = NULL;
-
?>
where do you set userCakeUser?
userCakeUser is set in the mysql db table
sorry I'm getting confused now ;-)
you might mean this here in the "login.php" page...
do you start the session anywhere?
yes in the "config.php" file (attached earlier on in the post)
I doubt var_dump($_SESSION); prints NULL …
I wish it didn't but unfortunately it does...see attached file
a var_dump() output looks different.
this is where I entered the var_dump in the menu.inc: - <?php if ($_SESSION['loggedInUser'] == $_SESSION["userCakeUser"]) { ?>Hi <strong><?php echo $_SESSION[$userdetails["Username"]]; var_dump($_SESSION);?>
Atli 5,058
Expert 4TB
Hey.
Try creating a new PHP file int he same directory your other PHP files are and do: -
<?php
-
header('content-type: text/plain');
-
session_start();
-
var_dump($_SESSION);
-
?>
-
This tells you whether the session is working, and what is in it.
Post the output here so we can see what data you are actually working with.
here is the output:
array(0) {
}
I'm no expert but it doesn't look good does it... ;-)
that means, that there is an empty session*
* which also means undefined == undefined (post #17)
ok, is there anything you can suggest for me to get this sorted at all? apologies for my ignorance on the subject...
not very much, I fear. I’d look, where and why the assignment didn’t work.
for everyone's info, this was sorted by replacing $_SESSION["userCakeUser"] by "1"
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Tom |
last post by:
Hi
I have a web application using asp.net and c#. User has to login to the application with his username and pwd. However, I do not allow other user uses the same username and pwd to login, i.e....
|
by: Siobhan |
last post by:
Hi
What is the recommended way to store a user's database credentials across
the pages of a web application so that each time the database is accessed the
system doesn't have to ask them for their...
|
by: Gleep |
last post by:
I've searched google intensely on this topic and it seems noone really knows how to approch this.
The goal I don't want clients to give out their usernames and passwords to friends, since the site...
|
by: BizWorld |
last post by:
Hi,
I have a scenario where i need to configure only Login.aspx page to use
SSL. All other application will run on HTTP protocol. If someone can
guide me how to accomplish this. One of my idea...
|
by: John Meyer |
last post by:
index:
<%@ Page Language="VB" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<!DOCTYPE html PUBLIC...
|
by: simon |
last post by:
well i have admin panel and agent panel.
when i open admin panel and log in it works fine. but when agent opens
agent panel in different pc and login and acts something like open a
page or so,...
|
by: Ben |
last post by:
Hello, I'll bet this has been asked a million times but I can't seem to find
a thread that gives the clear example I need.
This PC has MySQL and IIS configured and running. The MySQL database is...
|
by: =?Utf-8?B?S2VsbHk=?= |
last post by:
We just switched our web application from .NET 1.1 to 2. Once client can't
login out of several that have been successful. They enter a correct user
name and password, click the login button and...
|
by: Josh |
last post by:
I run a Joomla website and am familiar with php in some but not all
aspects. Currently I am trying to find some solutions related to
session handling.
Am I correct in saying that "login" is kept...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |