Re: Session with microtime

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

 



On 20/04/07, Panquekas <panquekas@xxxxxxxxx> wrote:



On 19/04/07, Richard Lynch <ceo@xxxxxxxxx> wrote:
>
> On Thu, April 19, 2007 11:32 am, Panquekas wrote:
> > I'm writting a script where I use the function microtime with sessions
> > and I
> > have a problem.
> >
> > This is my code:
> >
> > if( $_SESSION['uperm'] == '1' ){
> >   $t_start = microtime(1);
> > }
> >
> > (....)
> >
> > if( $_SESSION['uperm'] == '1' ){
> >   $t_end = microtime(1) - $t_start;
> >   $time .= "\n      " . '<P>This page was loaded in ' .
> > number_format($t_end, 3) . ' seconds.</P>';
> > }
> >
> > And when I log with any account (admin or user) is "echoed" to me
> > something
> > like this:
> > "This page was loaded in 1,177,003, 846.594 seconds."
> >
> > This is too much because the page isn't loaded in this time. And when
> > I
> > refresh the page it appears:
> > "This page was loaded in 0.012 seconds."
> >
> > Why is this? I can't explain.
> >
> > And this started to appear when I put the "if" to check the user
> > permissions. If I "turn off" the "if" it'll run normally.
> >
> > Can anyone explain why is that?
>
> You've messed up and put the session_start() inside the if( )block.


No I don't. I used the session_start() outside the if( ), but the
session_start() was before the login script and was registering the
$_SESSION's after the if( ) block. I moved that to the top of the page and
all that errors disappeared.


I'm sorry, my mistake. What I tried to say is that the session_start() was
on the top of the page, and the if( ) block was after that and the login
script was even after the if( ), so the first thing to ran was the
session_start() then the if( ) block and after that the login script
registering the $_SESSION's. I moved the login script to the middle of the
session_start() and the if( ).

If you didn't understand I'm sorry, my english is very rusted, but tell me
your doubt's, I'll try to say in another way.

Put session_start at the very top of the file, *BEFORE* the $_SESSION
> variable is used for anything at all.


I use only on page index.php, inside of that I use if( ) block to switch
between the various pages I made. It's better to me like that. I use
include_once( ) to don't saturate the server from loading every time the
page. But yeah, I used the session_start in the top of the page.

--
> Some people have a "gift" link here.
> Know what I want?
> I want you to buy a CD from some indie artist.
> http://cdbaby.com/browse/from/lynch
> Yeah, I get a buck. So?
>
>

Thanks once again.


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux