473,372 Members | 825 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

PHP Session and variable question...

Hello,

I have a really easy (I hope) question but have come you a blocking point
and need some help...

My web page contains both standard HTML and PHP code. No problem there... On
one page after the user logs in I set a session variable $_SESSION['fName']
= $fName // $fName is passed to the function. When I draw this page the
variable in $_SESSION['fName'] echo's correctly and I can go to other pages
and it will still be there correctly. However, I need more than one variable
$_SESSION['account']=$eMailAddr where $eMailAddr = their email address. If I
add this to the code where I set $_SESSION['fName] it all echoes correctly
on the first page, however, if I got to another page only the ['fName]
echoes, ['account] does not. Any suggestions? Remember this php code is
imbedded in an HTML page.

Thanks,
Jul 16 '05 #1
6 14103
Rob @ Home wrote:
Hello,

I have a really easy (I hope) question but have come you a blocking point
and need some help...

[...]

try putting these statements at the very top of your pages:

<?php
ini_set('display_errors', 1);
ini_set('log_errors', 0);
ini_set('error_reporting', E_ALL);
?>

What they do is set your php to display all errors, warnings and
notices on the browser (and not log them). After you find the error
(if it is found this way), remove the lines ...

....

.... or let them in and remove all errors, all warnings, and all
notices that show up when you run your scripts.

Happy Coding :-)

--
"Yes, I'm positive."
"Are you sure?"
"Help, somebody has stolen one of my electrons!"
Two atoms are talking:
Jul 16 '05 #2
Pedro,

I did this and got "Notice: Undefined index: fName in
/home/blah/public_html/userFuncs.php line 10"

line 10 is:
echo $_SESSION['fName'];

at the top of the function I call global $_SESSION;

Does this shed any light?
Rob
"Pedro" <he****@hotpop.com> wrote in message
news:gm********************************@4ax.com...
Rob @ Home wrote:
Hello,

I have a really easy (I hope) question but have come you a blocking point
and need some help...

[...]

try putting these statements at the very top of your pages:

<?php
ini_set('display_errors', 1);
ini_set('log_errors', 0);
ini_set('error_reporting', E_ALL);
?>

What they do is set your php to display all errors, warnings and
notices on the browser (and not log them). After you find the error
(if it is found this way), remove the lines ...

...

... or let them in and remove all errors, all warnings, and all
notices that show up when you run your scripts.

Happy Coding :-)

--
"Yes, I'm positive."
"Are you sure?"
"Help, somebody has stolen one of my electrons!"
Two atoms are talking:

Jul 16 '05 #3
Rob @ Home wrote:
Pedro,

I did this and got "Notice: Undefined index: fName in
/home/blah/public_html/userFuncs.php line 10"

line 10 is:
echo $_SESSION['fName'];

at the top of the function I call global $_SESSION;

Does this shed any light?


You don't need to 'globalize' the _SESSION array

<?php
function print_test() {
echo $_SESSION['test'];
}

session_start();
$_SESSION['test'] = 'test ok';
print_test();
?>

will work very nicely.
My guess is you have variable names mixed up somewhere in your code.
Hopefully, seeing all the errors, warnings and notices, would let you
find the misnamed variables.

As for your specific error (fName undefined) are you sure you set the
_SESSION index as "fName" (capitalization matters!!!)

try outputting all of the _SESSION array right after line 10

<?php
// ...
// line 9
echo $_SESSION['fName'];
foreach ($_SESSION as $k => $v) echo $k, ' = ', $v, '<br />';
// etc. ...
?>

and check the names of the indices you have set versus what you think
you should have :)

Pay attention to l, 1, O, 0, ... and capitalization

--
"Yes, I'm positive."
"Are you sure?"
"Help, somebody has stolen one of my electrons!"
Two atoms are talking:
Jul 16 '05 #4
The trick was not including the global $_SESSION

Thanks

"Pedro" <he****@hotpop.com> wrote in message
news:ih********************************@4ax.com...
Rob @ Home wrote:
Pedro,

I did this and got "Notice: Undefined index: fName in
/home/blah/public_html/userFuncs.php line 10"

line 10 is:
echo $_SESSION['fName'];

at the top of the function I call global $_SESSION;

Does this shed any light?


You don't need to 'globalize' the _SESSION array

<?php
function print_test() {
echo $_SESSION['test'];
}

session_start();
$_SESSION['test'] = 'test ok';
print_test();
?>

will work very nicely.
My guess is you have variable names mixed up somewhere in your code.
Hopefully, seeing all the errors, warnings and notices, would let you
find the misnamed variables.

As for your specific error (fName undefined) are you sure you set the
_SESSION index as "fName" (capitalization matters!!!)

try outputting all of the _SESSION array right after line 10

<?php
// ...
// line 9
echo $_SESSION['fName'];
foreach ($_SESSION as $k => $v) echo $k, ' = ', $v, '<br />';
// etc. ...
?>

and check the names of the indices you have set versus what you think
you should have :)

Pay attention to l, 1, O, 0, ... and capitalization

--
"Yes, I'm positive."
"Are you sure?"
"Help, somebody has stolen one of my electrons!"
Two atoms are talking:

Jul 16 '05 #5
Well it should work!

page1:
<?
session_start();
$_SESSION['fName'] = $fName;
$_SESSION['account'] = $eMailAddr;
?>

page2:
<?
session_start();
echo $_SESSION['fName'];
echo $_SESSION['account'];
?>

logically, that works fine. so if it does not on yours then the problem is
elsewhere.. you may find that its not even being set because it never
reaches that part of the code.

*paste code*
pasting code makes replies likely to be more accurate :)

bai bai

Petey

Jul 17 '05 #6
Well it should work!

page1:
<?
session_start();
$_SESSION['fName'] = $fName;
$_SESSION['account'] = $eMailAddr;
?>

page2:
<?
session_start();
echo $_SESSION['fName'];
echo $_SESSION['account'];
?>

logically, that works fine. so if it does not on yours then the problem is
elsewhere.. you may find that its not even being set because it never
reaches that part of the code.

*paste code*
pasting code makes replies likely to be more accurate :)

bai bai

Petey

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nate Spillson | last post by:
I have an asp.net web application that uses session variables to store user information (username, security areas, configuration data). When the user logs into the system I store all of this...
4
by: John Kraft | last post by:
Hi all, My question is more of a phylisophical one here, but I am wondering what the difference is (effectively and performance wise) between using a shared variable/static variable and using a...
2
by: Joe Molloy | last post by:
Hi, This isn't a mission critical question but I thought I'dl throw it out there for your feedback as it's a bit curious. I have developed a shopping cart for an application I'm working on...
2
by: +The_Taco+ | last post by:
I already use session variable in my project to set a session timeout when the user doesn't do anything for 10 minutes. When I call other pages, I often use parameters in HREF link. I was...
5
by: Andy G | last post by:
I have a registration page that captures 75% of the users data. After they enter that info they are redirected to one of two pages depending on how they answered a question on the registation...
1
by: Vidyadhar Joshi | last post by:
I have the following scenario in a true load balanced environment (without sticky sessions): There are 2 ASPX pages. I want to pass an object from the first page to the second page. On the...
0
by: sweetpotatop | last post by:
Hi, I have an aspnet applicaiton which uses session variable. But I don't think I use it correctly. On page_load, the current session is given an ID, e.g. session("CurID") = 1234 When the...
17
by: Control Freq | last post by:
Hi, Not sure if this is the right NG for this, but, is there a convention for the variable names of a Session variable? I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any...
11
by: Dave | last post by:
I have a site with an App_Code folder that has Global.asax.cs and a file named Upload.cs. I want to pass Upload.cs a Session variable (username) that is set in default.aspx. Setting up a...
5
by: Twayne | last post by:
Hi, If ever a newbie wants to know how much he has to learn yet, he only has to look here<g>!! ANYway: PHP 5.2.5; XP Pro SP2+, local Apache Server My actual question is: How do I get a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.