Re: Ok, next step/question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jacob,

  You must issue a session_start() prior to outputting any code to the
browser for sessions to work. There are tons of different ways to
configure things, but session_start() as the first thing in the script
should get you started. Here is a basic example:

index.php:
<?php
session_start();
$_SESSION['test_me'] = 'My test $_SESSION variable'; // stores a value
in the $_SESSION array
?>
<html><head>
<meta http-equiv="refresh" content="0;url=page2.php">
</head></html>
################## End of index.php ##################


page2.php:
<?php
session_start()
?>
<html><head><title>Page 2</title></head><body>
<?php
echo $_SESSION['test_me'];
?>
</body></html>
################# End of page2.php #######################

The index.php page simply stores a value in the $_SESSION super global
array and then immediately redirects to page2.php. page2.php retrieves
the value stored by index.php and displays it as the content of the web
page.

This code is all from memory so it might have a bug, but it is how I got
started working with session support in PHP.

Thanks,
James


On Fri, 2008-01-11 at 12:26 +0200, Jacob Kruger wrote:
> Now got that main page redirecting/spitting out the relevant JS code to get 
> it to move on to the next page, but there I was trying to ascertain if the 
> session variable/array element had actually been set, and, for whatever 
> reason, no PHP code seems to be executing in main.php.
> 
> Below is what I currently have inbetween the <body></body> tags:
> 
> <? php
> echo "testing...";
> ?>
> 
> Before I was trying to do something along the lines of:
> echo $_SESSION["admin"];
> 
> And that also did nothing.
> 
> I also tried changing the static HTML content to see if maybe the output was 
> just being cached or something, but that renders correctly.
> 
> Any ideas? (am I just not 'trying' correctly or something)
> 
> Stay well
> 
> Jacob Kruger
> Blind Biker
> Skype: BlindZA
> '...Fate had broken his body, but not his spirit...'
> 

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux