You are here: Re: session_start issue « PHP Programming Language « IT news, forums, messages
Re: session_start issue

Posted by jody.mickey on 10/09/06 21:07

Well first off I see that you are calling sessionStart() a few times
but the function you have written is called startSession(), which looks
like your session would never get started.

Be warned that sessions won't work unless the user has cookies enabled,
and a clever user could modify cookies as they see fit. If your
hosting provider allows htaccess files, I would suggest using
auto_prepend_file. It will allow you to include a file at the top of
any page that is requested and it can be applied at the directory
level. See http://httpd.apache.org/docs/1.3/howto/htaccess.html for
how to set this up, and you might have to search around for
auto_prepend_file, but the syntax is like this:

php_value auto_prepend_file prepend.php

That's it.

prepend.php might look like this:

<?php

session_start();
if(empty($_SESSION))
{
// it's a new session, do your thing
}

?>

Also note that even by setting session.gc_maxlifetime, your session
might expire earlier or later than you planned. See this article:
http://blog.centresource.com/2006/05/23/php-session-lifetime-an-adventure/

paladin.rithe@gmail.com wrote:
> I'm running into an issue with session_start(). I see that you can't
> run it twice, otherwise it causes an issue. That's fine, and makes
> sense. I also saw some ideas on how to get around this if you need to
> run it more than once, and I get those as well, but none are working
> for me.
> Here's a mockup of what I have:
>
> index.php
> info.php
> lib/common.php
> lib/output.php
>
> index.php
> <?php
> require_once('lib/common.php');
> require_once('lib/output.php');
>
> sessionStart();
>
> runout();
> ?>
>
> info.php
> <?php
> require_once('lib/common.php');
> require_once('lib/output.php');
>
> sessionStart();
>
> output("Hello World");
>
> outputStop();
> ?>
>
> lib/common.php
> <?php
> ob_start();
>
> function startSession()
> {
> if(!isset($_SESSION))
> {
> session_start();
> }
> }
>
> ?>
>
> lib/output.php
> <?php
> require_once('lib/common.php');
> sessionStart();
>
> function output($out)
> {
> $_SESSION['output'] .= $out;
> }
>
> function outputStop()
> {
> header("Location: index.php");
> }
>
> function outrun()
> {
> echo $_SESSION['output'];
> }
> ?>
>
> As near as I can tell (I have other session variables that this is
> happening to) the sessionStart function in output.php is interfearing
> with the one in info.php. When I comment the one from output.php out,
> my scripts run fine, but with it I get errors, usually something about
> a class not being fully defined (from another lib/*.php file).
> Can anyone see anything wrong with what I'm doing? The only reason I'm
> doing it this way is so users can't use the back button (I'm working on
> a game, and would rather not have people hit back to try and get around
> stuff, but that would be to their detrememnt probably anyway) so all
> the output is done by index.php (in this example at least). I am
> storing the output info in the session variable so index.php can
> actually use it.
> Of course, on the other hand, if someone has an idea for getting around
> the "Back" issue without doing it this way, I'm open to suggestions.
> Although I'd probably have to run stuff through a filter of some sort
> still, just for security purposes, but that's another story.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация