All,
I'm getting the following error when I work with a class:
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /webspace/httpdocs/offers/form_key.php on line 5
The complete code for this is class is:
<?php
class Form_Key
{
protected $oldKey;
public function __construct()
{
// Ensure we have an available session
if ( NULL == session_id() )
{
session_start();
}
// Grab our former key for validation
if ( isset( $_SESSION['form_key'] ) )
{
$this->oldKey = $_SESSION['form_key'];
}
// Assign the new key
$_SESSION['form_key'] = md5( uniqid( mt_rand(), TRUE ) );
}
public function isValid()
{
return 'POST' == $_SERVER['REQUEST_METHOD']
&& isset( $_POST['form_key'] )
&& '' != trim( $_POST['form_key'] )
&& '' != trim( $this->oldKey )
&& $_POST['form_key'] === $this->oldKey;
}
public function getKey()
{
return $_SESSION['form_key'];
}
public function getOldKey()
{
return $this->oldKey;
}
public function render()
{
return '<input type="hidden" name="form_key" value="' . $_SESSION['form_key'] . '" />';
}
public function __toString()
{
return $this->render();
}
}
?>
The line that is giving the issue is this line:
protected $oldKey;
Is it ok just to remove this line?? If I comment it out it gives me the same message but for line 7, which is this one:
public function __construct()
Anyone have any ideas? Thanks in advance.