Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

PHP Print Session Variable to screen

Posted on 2007-10-04
7
Medium Priority
?
15,948 Views
Last Modified: 2008-01-09
I'm just trying to echo the current session variables. Believe me Ive been reading and reading and still can get results. What am I missing?

session_start();  // Do I need to start a session if one is already started by the log in??
echo "The value of the session variable is: " . $_SESSION['username'];   // I get nothing with this.
print_r ($_SESSION);  // this give me --->   Array( )
0
Comment
Question by:Russelauto
7 Comments
 
LVL 13

Expert Comment

by:MasonWolf
ID: 20013995
echo $_SESSION['username'];

or if you want every value in the sessions:
var_dump($_SESSION);
0
 
LVL 14

Expert Comment

by:ygoutham
ID: 20014245
you need to set the path as to where the session values would be stored in the php.ini file

in linux, you would normally see this in the /etc/ directory and in windows within the php directory itself

the directory should be writeable by the httpd or the apache process.  check for owner and write permissions in that directory.  if that is there then you need to set some values first and then call it.  otherwise the session_start(); function normally initialises the $_SESSION array but nothing is stored.

in your php page  do the following

session_start();
echo $_SESSION['username'] . "is the user name from cookie<br>";
$_SESSION['username'] = "mickey mouse";


echo $_SESSION['username'] . "is the user name from cookie after setting the value<br>";  


and you would see the difference.  you can use anything like this in the $_SESSION variable

$_SESSION['myvariablename'] = "xxx_yyy_zzz";

$somevariable = $_SESSION['myvariablename'];  

and proceed to use that.  the variable values set through the session are also available in the second and subsequent pages till the session is closed.

You have to set the variables in the session and call them back.  they are not set by default over there
0
 
LVL 13

Expert Comment

by:MasonWolf
ID: 20014344
Sorry - I didn't read the question closely before posting.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Russelauto
ID: 20017662
I don't want to assign the variables, I want to display the variables that have already been assigned when the user logged in. It may be a matter of just knowing the variable name, but I've tried username, user, and id. I thought there may be a way to echo everything out to see what variables were actually assigned.
0
 
LVL 13

Accepted Solution

by:
MasonWolf earned 2000 total points
ID: 20017695
Yes there is. That would be "var_dump($_SESSION);"

If it comes back with "array(0)" then it means nothing is there.
0
 

Author Comment

by:Russelauto
ID: 20018982
That exactly right... I got    array(0)    I fail to understand why there are none. I assumed that the site worked off of session variables.
0
 

Expert Comment

by:bksaji
ID: 20499146
Check whether session_start() is given in the page where u assigned the session values.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question