473,382 Members | 1,165 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,382 software developers and data experts.

Session not available in Include file

Hey,

Anyone got any ideas why I wouldn't be able to output a value stored in the
session array in a particular include file - I am using session_start() but
to no avail.

Joe
Jul 17 '05 #1
3 2298
> Anyone got any ideas why I wouldn't be able to output a value stored in
the
session array in a particular include file - I am using session_start() but to no avail.


please post some code to make it easier to help you!

Gert.
Jul 17 '05 #2
Well, I know the code to set the session is working because if it's not I am
redirected from my secure url

Anyway, for what it's worth here's the code

User logs in by posting credentials to login.php which checks the database
to make sure he's registered and then if he is executes the following code
to set the session

session_start();
header("Cache-control: private");
$_SESSION["auth"] = trim($_POST["username"]);

logged in user is then redirected to a protected page
the protection code resides in an include and says

session_start();
header("Cache-control: private");

if (!isset($_SESSION["auth"]))
{
header("Location: ".$myWwwPath."login.php");
}

This works fine - if the user tries to access the page without logging in
they are successfully redirected

On all pages on the site I want to have an include file
which when a user is logged in displays a table with their login info - i.e.
$_SESSION['auth'] so I made and included the file

<?php include("config.php");?>
<?php
session_start();

if (isset($_SESSION["auth"]))
{
?>
<table border="0" cellpadding="4" cellspacing="0">
<tr>
<td align="center">
<img src="<?php echo $myWwwPath; ?>resources/images/key_icon.gif"
align="absmiddle"/>
<span>Logged In As:</span><br/>
<span><?php echo $_SESSION["auth"];?></span>
</td>
</tr>
</table>
<?php }
else{
}

Incidentally, config.php doesn't make any output to the browser or contain
any blank lines.

echoing $_SESSION['auth'] in the include produces nothing!

I'm a php newbie as ASP and ASP.NET is my normal environment. Could it be
something to do with scope as the include is included in another include?

Joe
"Gert" <ge**@mellak.com> wrote in message
news:ci**********@newsreader1.utanet.at...
Anyone got any ideas why I wouldn't be able to output a value stored in

the
session array in a particular include file - I am using session_start()

but
to no avail.


please post some code to make it easier to help you!

Gert.

Jul 17 '05 #3
Hmmm, I've just noticed something else that may be important to diagnosing
the problem here - when I try to access my include directly in the browser
on it's onw the code works fine. (the include has a php extension which is
why I can access it). So it would appear that it's because it's an include
that there's a problem - I am using require_once to include it.

Joe

"BlueFrog" <bl******@hyper-typer.com> wrote in message
news:gN*******************@news.indigo.ie...
Hey,

Anyone got any ideas why I wouldn't be able to output a value stored in
the session array in a particular include file - I am using
session_start() but to no avail.

Joe

Jul 17 '05 #4

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

Similar topics

1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
27
by: mrbog | last post by:
Tell me if my assertion is wrong here: The only way to prevent session hijacking is to NEVER store authentication information (such as name/password) in the session. Well, to never authenticate...
0
by: james | last post by:
I am new to php and need some help getting the session variables into include files. (after-thought, Sorry for the drawn out post but I really, really need help....;) Here's what I'm doing.. ...
1
by: Sean Pinto | last post by:
Ok, you all are going to have to bear with me on this one as it is kinda complicated to explain. I am implementing a company management suite that requires Role-Based authentiations (ie. users are...
13
by: Mimi | last post by:
Hello, I am having trouble using the session vars in PHP 4.3.9 OS: Win XP Prof Web Server IIS (is local and there are no links to other servers from the web pages I work on) Browser: IE 6.0 ...
2
by: Amit D.Shinde | last post by:
Hello Experts.. I need some help regarding cookies and session objects and also global.asa file I am creating one cookie when a user logs in on my website. The cookie stores the login name of...
2
by: Eric | last post by:
Hi, I've a problem with trying to retrieve a session variable in an include file. Basically, the main asp creates a session variable: <% Session("var1") = "Hello" %> And then when I click...
0
by: Nabani Silva | last post by:
Hi, hope someone could help I need to share session state (and contents) through differente web applications. I'm trying to get it done by using StateServer session state, below I paste code...
4
by: spectre | last post by:
Hello, I first create a session variable 'client' in the login.asp file The login.asp file opens a file (xxx.asp) with an include file .. If I write <!--#include file="../../../data/" &...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: 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.