News:

Click here for Toll-Free Service for your business starting at $2.00 per month

Main Menu

PHP Scripting

Started by ghost, November 27, 2005, 07:11:40 AM

Previous topic - Next topic

ghost

I have two three questions, the first is, how long does a 'session' in php last before it times out?

and:

          $timeactive="Update users set active=". time() .", logoff='0' where ID='{$_SESSION['ID']}'";

          $timeactive2=@mysql_query($timeactive);


why does the above code need the '@' symbol to function properly? All my other mysql_query's dont need it. (That line was used in a script written by someone else, which I use in my own site)

and lastley, with the timestamps, on my site they are determined by the time set on the server, right? So there is no way to set it to my time (+15 min) without altering the timestamp itself?
- Ghost -

sixthcrusifix

1. Sessions are funny. If you do them through cookiesit depends on how long people keep cookies and when you set them to expire, if it's a server held session I honestly think they have the possibility to last for quite a while. In fact I logged into my favorite PHP forum once a few months ago and I've never had to log back in manually since.

2. Um. . . it should always have @ I've never seen it not have @. But I don't know WHY it has @.

3. Sorry I know nothing of timestamps.
Visite me website at http://www.sixthcrusifix.com

Guide

#2
1.
The Session timeout should be written somewhere on the phpinfo(), I believe.
It depends on the server's configuration. Default value is around twenty minuts, I think. (sixthcrusifix -> a month? 'must have been cookies, then...)

2.
The @ isn't usually necessary, it's just used to tell mysql not to report any errors. It's used when you know there can be an error occuring, but you know that error isn't important for the rest of your code and you still want your code to run the rest of the way.

3.
The time() function accepts no parameter, so you'll have to modify the integer it returns.
As it returns a value in seconds, you'll just have to do something like :
$timestamp = time() + (15*60); to add your 15 min...

neosquared

Quote from: Guide on November 27, 2005, 12:23:56 PM
The @ isn't usually necessary, it's just used to tell mysql not to report any errors. It's used when you know there can be an error occuring, but you know that error isn't important for the rest of your code and you still want your code to run the rest of the way.
Another reason to do that is if you want to do custom error reporting, like so:
<?php
$query 
= @mysql_query('SELECT * FROM table');
if (
$query) {
echo 
'query successful';
} else {
echo 
'query unsuccessful';
}
// If you only want to output a message on failure, you could do something like this:
$query = @mysql_query('SELECT * FROM table') OR echo 'query unsuccessful';
?>

Naturally, you could always replace the echo with something else.  (exit(), mysql_error(), etc.)
Don't take servers for granted.
Everything is flammable, if you get it hot enough.
Visit my website!  It'll make you cooler!

sixthcrusifix

Quote from: neosquared on November 30, 2005, 09:22:13 AM
Quote from: Guide on November 27, 2005, 12:23:56 PM
The @ isn't usually necessary, it's just used to tell mysql not to report any errors. It's used when you know there can be an error occuring, but you know that error isn't important for the rest of your code and you still want your code to run the rest of the way.
Another reason to do that is if you want to do custom error reporting, like so:
<?php
$query 
= @mysql_query('SELECT * FROM table');
if (
$query) {
echo 
'query successful';
} else {
echo 
'query unsuccessful';
}
// If you only want to output a message on failure, you could do something like this:
$query = @mysql_query('SELECT * FROM table') OR echo 'query unsuccessful';
?>

Naturally, you could always replace the echo with something else.  (exit(), mysql_error(), etc.)

or die works too.  I use or die(mysql_error())
Visite me website at http://www.sixthcrusifix.com

Ben

die and exit are aliases for the same function. They'll work exactly the same.
--Ben
Ben@freepgs.com