473,788 Members | 2,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to use session variables throughout all pages

254 Contributor
hello

i want to maintain the session of particular user throughout the webpage after login.

it should display the login name on each and every page.

i tried it in this way:
Expand|Select|Wrap|Line Numbers
  1. session_start()
  2. $_SESSION['username']=$name;
  3.  
it works for only this page.

and for next pages i tries like
Expand|Select|Wrap|Line Numbers
  1. session_start()
  2. $_SESSION['usename']=$_POST['$_SESSION[username]'];
  3. echo "Welcome ".$_SESSION['username'];
but it is not working

please help me out. <Email removed>
Nov 16 '07 #1
1 1627
Atli
5,058 Recognized Expert Expert
Hi.

Check out this article on Sessions in PHP.

In short, you can put something like this on one page:
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2. $_SESSION['UserName'] = "Atli";
  3.  
And something like this on some other page:
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2. echo "Your name is ". $_SESSION['UserName'];
  3.  
And it will print "Your name is Atli";

If that doesn't work, it is probably a problem with the Session support on your server. You may want to call and yell at your host :)

P.S.
I have removed the email in your post. Our Posting Guidelines strictly forbid posting of email addresses in the technical forums.

Also, please use [code] tags when posting code
[code=php]PHP code goes here[/code]

Thank you.
Nov 16 '07 #2

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

Similar topics

9
2993
by: Xizor | last post by:
Let's say I run a server. I have two people using the server. Bill and Joe. Bill is at address.com/bill and Joe is at address.com/joe. Let's say Joe and Bill are both using PHP with sessions on their web pages. Let's say they both create the session variable $_SESSION. Each uses yo for a different purpose. Now we have a user accessing address.com. He goes to Bill's site and his session his started with the $_SESSION created.
3
9161
by: StinkFinger | last post by:
Hello all, I am working on some simple pages that pass non-critical information (i.e. no passwords, usernames, etc.) to and from different pages. Currently, I am using FORMs w/the POST method. I am not using any cookies or anything stored on the client end, simply passing data. Should I read up on SESSIONS and use those instead of POST ? What are the benefits/drawbacks by switching to SESSIONS ?
5
367
by: RA | last post by:
Hi If I use session variables does this depends on cookies being sent to the client browser? If yes then what happens if the user disable cookies? Thanks
8
1730
by: Anthony P. Mancini | last post by:
I'm working on a proof of concept that will ultimately be deployed on a load balancer. For the sake of a preliminary demonstration I created a C# object and marked it's attributes as Public Shared Static. I also set the EnableSessions and EnableViewState Page directives to false. Here's the part that stumped me : as I was moving from page to page within the demo, I accidently realized the data I dropped
7
4499
by: Mike | last post by:
Hi, I have an ASP.NET solution in which I need to store some information, such as DB user and password. So far, I have used the Context object to share information between the various pages, but I after having read some material, I have had the impression that the Cache object is better, since my variables are used throughout the entire application. Is that correct? If not, what is the best method for storing application variable (used...
1
1129
by: mike.dershowitz | last post by:
Hello All! Do the major browsers (IE primarily) have sesion variables that are specific to the browser, and that would have no server interface? I need to store data in a session variable and access it throughout a number of pages as long as the browser is active. What is the object in the browser that can do this? Thank you very much in advance!
3
1959
by: Alex Maghen | last post by:
I want to create an object which is attached to the specific user session and I want to be able to access that object directly throughout the Pages, Page Controls, and Master Pages of the site. I'm assuming that the best way to do that is to create the object and then put it into the Session? If so, a few questions about the best way to do that: 1. If I want to reliably access that object on any and every page, how do I make sure that...
14
2934
by: Martin Walke | last post by:
Hi all, Is there any limit to the number of session variables a site can have? And is that affected by global.asa at all? The reason why i ask is that i have a relatively simple site that relies on about 40 sesion variables and a mixture of vbs and js files. One of the session variables is an id number that gets incremented to point to the next piece of data to be displayed. This variable is initialised on the first page of the site...
8
3025
by: Eddie | last post by:
I am having difficulty in setting variables in a session, and then accessing those variables throughout the web pages that they click on. After having them set a user name and password, successfully authenticating against Active Directory, I send them from the login.php page to the index.php page. But when I get to the index.php page, the session ID is visible, but the session variables and values are not. Can you help me out? Also,...
0
9656
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
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10373
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
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10118
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
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
5403
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...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
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

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.