Forum Moderators: coopster

Message Too Old, No Replies

parse error, unexpected T_VARIABLE

$c_min = date('i'); becomes unexpected T_VARIABLE

         

zio_shaitan

11:17 pm on Dec 3, 2003 (gmt 0)

10+ Year Member



The error occured after entering all the time variables, before that I only had "$timestamp = date('YmdHis');" and that worked fine. I've tried both double and single quotes on this and still doesn't work. If anyone knew a solution for this it would be greatly apreciated.

Here's the code, the unexpected T_VARIABLE error lies on $c_min

if($logged_in == 1)
{

$refresh_time = 1;
$c_hour = date('H');    //Current Hour
$c_min = date('i');    //Current Minute
$c_sec = date('s');    //Current Second
$c_mon = date('m');    //Current Month
$c_day = date('d');    //Current Day
$c_year = date('Y');    //Current Year

$timestamp = mktime($c_hour,$c_min,$c_sec,$c_mon,$c_day,$c_year);

$old_timestamp = $_SESSION['timestamp'];

if ($oldtime & $timestamp > $old_timestamp)
{
unset($_SESSION['username']);
unset($_SESSION['password']);
// unset session variables
$_SESSION = array(); // reset session array
session_destroy(); // destroy session.
header('Location: login.php');// redirect to login
die;
} else {$_SESSION['timestamp'] = mktime($c_hour,$c_min+$refresh_time,$c_sec,$c_mon,$c_day,$c_year);} // update the timestamp

?>
<h1>Logged in</h1>
<p>Welcome <? echo $_SESSION['username'];?></p>
<a href="logout.php">logout</a>
<?
die;

}

Thanks in advance ;)

zio_shaitan

11:19 pm on Dec 3, 2003 (gmt 0)

10+ Year Member



And i have a closing?> in the end, just forgot to include it in the copy/paste procedure ;)

jatar_k

11:38 pm on Dec 3, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld zio_shaitan,

You don't mention what line it says the error is on but ...

if ($oldtime & $timestamp > $old_timestamp)

looks a little strange, not quite sure what you are tryin to do there. Is it supposed to be a + or do you want to compare both?

<added>alright you did mention it I just didn't read the desc ;)

why not just
$timestamp = mktime();
[ca.php.net...]

Arguments may be left out in order from right to left; any arguments thus omitted will be set to the current value according to the local date and time.

therefore, if you leave them all out you get NOW.

amd you shouldn't need to redo the mktime here
$_SESSION['timestamp'] = .....

since you could do

$_SESSION['timestamp'] = $timestamp;

you already got it earlier and can reuse it.

zio_shaitan

11:52 pm on Dec 3, 2003 (gmt 0)

10+ Year Member



Thanks.
The error lies on line 6 and the if statment checks if $timestamp is bigger than $old_timestamp, and it olny does so if $old_timestamp contains a value. $old_timestamp is set on another page.

Now when i think of it it is always going to contain a value so I'm removing it from the if statement but the problem still remains.

zio_shaitan

12:36 am on Dec 4, 2003 (gmt 0)

10+ Year Member



thanks alot!
just using mktime(); worked great.