473,699 Members | 2,385 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

login session not behaving

27 New Member
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

Expand|Select|Wrap|Line Numbers
  1.            <div style="margin-bottom: 0px; margin-left: auto; margin-right: auto; margin-top: 0px; overflow: visible;">
  2.  
  3.  
  4.             <div align="center">
  5.             <table border="0">
  6.               <tr>
  7.                 <th>
  8.                 <span class="small">
  9.                 <?php if ($_SESSION["loggedInUser"] == $_SESSION["userCakeUser"]) { ?>Hi <strong><?php echo $_SESSION[$userdetails["Username"]]; ?>
  10.  
  11.             !
  12.  
  13.                 <?php } else { ?><a href="login.php">Login</a>
  14.                 <?php } ?>
  15.                 </span>  </th>
  16.  
  17.               </tr>
  18.               <tr>
  19.                 <td> 
  20.                 <span class="small">           
  21.                 <?php if ($_SESSION['loggedInUser'] == $_SESSION["userCakeUser"]) { ?><a href="logout.php">Logout</a>
  22.  
  23.                 <?php } else { ?>Register <a href="register.php" class="text_left">here </a>to download full mixes<?php } ?>
  24.                 </span>
  25.                    </td>
  26.               </tr>
  27.              </table>
  28.              </div>
  29.  
  30.             <hr width=600px>
  31.  
  32.             <a href="<?php echo $main_path; ?>index.php">Welcome</a><a href="
  33.             <?php echo $main_path; ?>Bio.php">Bio</a>
  34.  
  35.               <!--logged-in-->         
  36.             <?php if ($_SESSION['loggedInUser'] == $_SESSION["userCakeUser"]) { ?>
  37.  
  38.             <a href="<?php echo $main_path; ?>Mixes.php">Mixes</a>
  39.  
  40.  
  41.             <a href="<?php echo $main_path; ?>Production.php">Production</a>
  42.  
  43.             <?php } ?>
  44.  
  45.             <!--not-logged-in-->         
  46.             <?php if ($_SESSION['loggedInUser'] == NULL) { ?>
  47.  
  48.             <a href="<?php echo $main_path; ?>mixes_unlogged.php">Mixes</a>
  49.  
  50.             <a href="<?php echo $main_path; ?>production_unlogged.php">Production</a>
  51.  
  52.             <?php } ?>
  53.  
  54.             <a href="<?php echo $main_path; ?>Contact.php">Contact</a>
  55.             <a href="<?php echo $main_path; ?>links.php">Links</a>
  56.             <hr width=500px> 
Jan 6 '10 #1
22 2866
Dormilich
8,658 Recognized Expert Moderator Expert
obviously $_SESSION[$userdetails["Username"]] does not exist or is empty. try var_dump($_SESS ION); to see what’s going on.
Jan 6 '10 #2
macdalor
27 New Member
thx Dormilich. Sorry I'm really no expert in php, shall I put this instead of my query or after?
Jan 6 '10 #3
macdalor
27 New Member
I've added it within the query and it brings NULL back. Does it mean username isn't what I should be using then?
Jan 6 '10 #4
Dormilich
8,658 Recognized Expert Moderator Expert
what query? it doesn’t matter where you put this, as long as it is executed.

if var_dump($_SESS ION); brings up NULL, there is something wrong with the session.
Jan 6 '10 #5
macdalor
27 New Member
ok...what can I do to find out what's wrong with it?
Jan 6 '10 #6
Dormilich
8,658 Recognized Expert Moderator Expert
check out, where you set $_SESSION to NULL.
Jan 6 '10 #7
macdalor
27 New Member
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["userCakeUs er"] if logged in (see code below)

Am I not using this properly?

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     include("settings.php");
  3.  
  4.     //Dbal Support - Thanks phpBB ; )
  5.     include("classes/db/".$dbtype.".php");
  6.  
  7.     //Construct a db instance
  8.     $db = new $sql_db();
  9.     if(!$db->sql_connect($db_host, $db_user, $db_pass, $db_name, $db_port, false, false)) die("Unable to connect to the database");
  10.  
  11.     //Include classes
  12.     include("classes/class_newuser.php");
  13.     include("classes/class_newmail.php");
  14.     include("classes/class_loggedinuser.php");
  15.  
  16.     //Include Functions
  17.     include("functions/user-funcs.php");
  18.     include("functions/general-funcs.php");
  19.  
  20.  
  21.     session_start();
  22.  
  23.     //Global User Object Var
  24.     //loggedInUser can be used globally if constructed
  25.     if(isset($_SESSION["userCakeUser"]) && is_object($_SESSION["userCakeUser"])) $loggedInUser = $_SESSION["userCakeUser"]; else $loggedInUser = NULL;    
  26. ?>
Jan 6 '10 #8
Dormilich
8,658 Recognized Expert Moderator Expert
where do you set userCakeUser?
Jan 6 '10 #9
macdalor
27 New Member
userCakeUser is set in the mysql db table
Jan 6 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3565
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. one set of login ID cannot be used for twice except the logged in user's session has expired or he exited the system and terminate the session (Session.Clear();). Here is the C# code in my login cs file = obj; //I created a session here after...
19
2534
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 username and password again We have previously stored these in a session variable (encrypted) and retrieved from their - but are worried about the impact on performance if the number of users increases. Had thought about cookies but worried...
18
3389
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 relies on subscrption fees. Sessions ID's are matched between the browser and the server. So a users can login with same username and password and those sessions are tracked individually. Some suggest create table fields with the session ID...
6
4695
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 is to keep login.aspx page in a seperate Virtual director and apply SSL only on that directory but i dont know if it will have an impact on session (may be it will create two sessions due to two different virtual directories). If some one can...
0
1139
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 "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server">
5
1843
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, both admin panel and agent panel expires session and asks for re-login. What would be possible reason for this? Please anyone can help !!! platform: OS: windows 2000 server, IIS 6.0 Script : ASP, Javascript
9
3591
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 "myDB" with a table "myUsers" with fields "Username" and "Password". I also have the MySQL ODBC driver loaded with a DSN "dsnMySQL" setup. First question is can someone direct me to a site or provide a sample code for a login page that...
6
2278
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 they are redirected back to login with no errors or login failure. The same login account works fine from other machines at different locations. This client had no problem logging in before we switched. The login procedures are essentially the...
9
7806
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 in sessions? I can see active sessions in my mysql database, but is that the only place this information is stored? Sessions and cookies I know are related also, but how specifically (session info stored in cookies?)? Right now, when users...
0
8685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9172
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8880
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7745
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4374
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.