Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 17th, 2005, 09:41 AM
BlueFrog
Guest
 
Posts: n/a
Default 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


  #2  
Old July 17th, 2005, 09:41 AM
Gert
Guest
 
Posts: n/a
Default Re: Session not available in Include file

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

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

Gert.


  #3  
Old July 17th, 2005, 09:41 AM
BlueFrog
Guest
 
Posts: n/a
Default Re: Session not available in Include file

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" <gert@mellak.com> wrote in message
news:cilu5c$18n$1@newsreader1.utanet.at...[color=blue][color=green]
>> Anyone got any ideas why I wouldn't be able to output a value stored in[/color]
> the[color=green]
>> session array in a particular include file - I am using session_start()[/color]
> but[color=green]
>> to no avail.[/color]
>
> please post some code to make it easier to help you!
>
> Gert.
>
>[/color]


  #4  
Old July 17th, 2005, 09:41 AM
BlueFrog
Guest
 
Posts: n/a
Default Re: Session not available in Include file

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" <bluefrog@hyper-typer.com> wrote in message
news:gNt3d.31491$Z14.10316@news.indigo.ie...[color=blue]
> 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
>[/color]


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles