Parse error: syntax error, unexpected T_VARIABLE, expecting '(' in /

Discussion in 'PHP' started by Functional, Jan 11, 2012.

  1. #1
    I have this error to resolve:

    Parse error: syntax error, unexpected T_VARIABLE, expecting '(' in /includes/functions/sessions.php on line 70


    I believe I'm missing something. Fairly new to PHP. Would greatly appreciate any help!
    Here is the code:

    function tep_$_SESSION($variable) {
    global $session_started;

    if ($session_started == true) {
    return $_SESSION($variable);
    } else {
    return false;
    }
     
    Functional, Jan 11, 2012 IP
  2. PsyHost

    PsyHost Well-Known Member

    Messages:
    641
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    110
    #2
    its throwing an error on line 70 and you've posted 7 lines of code?
     
    PsyHost, Jan 11, 2012 IP
  3. Functional

    Functional Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    OK, well it's the very first line: function tep_$_SESSION($variable) {

    Hope u can help. Thanks
     
    Functional, Jan 11, 2012 IP
  4. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #4
    its your function name.. '$' sign are reserved character that would instantiate a variable. remove that. and add extra '}' at the end of the function
     
    bartolay13, Jan 11, 2012 IP
  5. metheew

    metheew Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Post your complete coding then, I can try to solve it because I think the variable you use has been changed in the last row of coding.
     
    metheew, Jan 11, 2012 IP
  6. Functional

    Functional Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The upgrade to PHP 5.3 has ruined our web site.
    Here is the entire code:

    <?php
    /*
    $Id: sessions.php,v 1.19 2003/07/02 22:10:34 hpdl Exp $


    Copyright (c) 2003 osCommerce

    Released under the GNU General Public License
    */

    if (STORE_SESSIONS == 'mysql') {
    if (!$SESS_LIFE = get_cfg_var('session.gc_maxlifetime')) {
    $SESS_LIFE = 1440;
    }

    function _sess_open($save_path, $session_name) {
    return true;
    }

    function _sess_close() {
    return true;
    }

    function _sess_read($key) {
    $value_query = tep_db_query("select value from " . TABLE_SESSIONS . " where sesskey = '" . tep_db_input($key) . "' and expiry > '" . time() . "'");
    $value = tep_db_fetch_array($value_query);

    if (isset($value['value'])) {
    return $value['value'];
    }

    return false;
    }

    function _sess_write($key, $val) {
    global $SESS_LIFE;

    $expiry = time() + $SESS_LIFE;
    $value = $val;

    $check_query = tep_db_query("select count(*) as total from " . TABLE_SESSIONS . " where sesskey = '" . tep_db_input($key) . "'");
    $check = tep_db_fetch_array($check_query);

    if ($check['total'] > 0) {
    return tep_db_query("update " . TABLE_SESSIONS . " set expiry = '" . tep_db_input($expiry) . "', value = '" . tep_db_input($value) . "' where sesskey = '" . tep_db_input($key) . "'");
    } else {
    return tep_db_query("insert into " . TABLE_SESSIONS . " values ('" . tep_db_input($key) . "', '" . tep_db_input($expiry) . "', '" . tep_db_input($value) . "')");
    }
    }

    function _sess_destroy($key) {
    return tep_db_query("delete from " . TABLE_SESSIONS . " where sesskey = '" . tep_db_input($key) . "'");
    }

    function _sess_gc($maxlifetime) {
    tep_db_query("delete from " . TABLE_SESSIONS . " where expiry < '" . time() . "'");

    return true;
    }

    session_set_save_handler('_sess_open', '_sess_close', '_sess_read', '_sess_write', '_sess_destroy', '_sess_gc');
    }

    function tep_session_start() {
    return session_start();
    }

    function tep_session_register($variable) {
    return isset($_SESSION[$variable]);
    }

    function tep_session_unregister($variable) {
    return unset($_SESSION[$variable]);
    } else {
    return false;
    }
    }

    function tep_session_is_registered($variable) {
    return isset($_SESSION($variable));
    }

    function tep_session_unregister($variable) {
    return unset($_SESSION($variable));
    }

    function tep_session_id($sessid = '') {
    if (!empty($sessid)) {
    return session_id($sessid);
    } else {
    return session_id();
    }
    }

    function tep_session_name($name = '') {
    if (!empty($name)) {
    return session_name($name);
    } else {
    return session_name();
    }
    }

    function tep_session_close() {
    if (PHP_VERSION >= '4.0.4') {
    return session_write_close();
    } elseif (function_exists('session_close')) {
    return session_close();
    }
    }

    function tep_session_destroy() {
    return session_destroy();
    }

    function tep_session_save_path($path = '') {
    if (!empty($path)) {
    return session_save_path($path);
    } else {
    return session_save_path();
    }
    }

    function tep_session_recreate() {
    if (PHP_VERSION >= 4.1) {
    $session_backup = $_SESSION;

    unset($_COOKIE[tep_session_name()]);

    tep_session_destroy();

    if (STORE_SESSIONS == 'mysql') {
    session_set_save_handler('_sess_open', '_sess_close', '_sess_read', '_sess_write', '_sess_destroy', '_sess_gc');
    }

    tep_session_start();

    $_SESSION = $session_backup;
    unset($session_backup);
    }
    }
    ?>
     
    Functional, Jan 12, 2012 IP
  7. phpdoctor22

    phpdoctor22 Peon

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    What is on line 70 ?
     
    phpdoctor22, Jan 12, 2012 IP
  8. Functional

    Functional Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    It's line 75
    Parse error: syntax error, unexpected T_UNSET in /includes/functions/sessions.php on line 75

    Line 75: return unset($_SESSION[$variable]);
     
    Functional, Jan 12, 2012 IP
  9. phpdoctor22

    phpdoctor22 Peon

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    It's probably because your returning unset. Unset the variable and return true.
     
    phpdoctor22, Jan 12, 2012 IP
  10. Functional

    Functional Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I'm pretty new to PHP. Could you show me the code please?
     
    Functional, Jan 12, 2012 IP
  11. SchmitzIT

    SchmitzIT Member

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    40
    #11
    
    unset($_SESSION[$variable]);
    return true;
    
    Code (PHP):
     
    SchmitzIT, Jan 12, 2012 IP
  12. Functional

    Functional Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Thank You. It's been really difficult since server upgraded to PHP 5.3 If we can through session.php we might be OK

    I put in the code and this new error appeared:
    Fatal error: Can't use function return value in write context in /includes/functions/sessions.php on line 81

    Line 81 code is: return isset($_SESSION($variable));

    Is this where I would ad a next line?: return false;
     
    Functional, Jan 12, 2012 IP
  13. phpdoctor22

    phpdoctor22 Peon

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    return isset($_SESSION($variable));

    should be

    return $_SESSION[$variable];
     
    phpdoctor22, Jan 12, 2012 IP
  14. Functional

    Functional Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I now have this error:

    Fatal error: Cannot redeclare tep_session_unregister() (previously declared in /home/ecgnatur/public_html/store_us/includes/functions/sessions.php:74) in /includes/functions/sessions.php on line 88

    I've tried to add some code further down line 81. Could you please check it:
    Line 88 is a } and in bold:

    function tep_session_register($variable) {
    return isset($_SESSION[$variable]);
    }

    function tep_session_unregister($variable) {
    unset($_SESSION[$variable]);

    return true;
    }

    function tep_session_is_registered($variable) {
    return ($_SESSION($variable));
    }

    function tep_session_unregister($variable) {
    return ($_SESSION($variable));

    return true;
    }

    function tep_session_id($sessid = '') {
    if (!empty($sessid)) {
    return session_id($sessid);
    } else {
    return session_id();
    }
    }
     
    Functional, Jan 12, 2012 IP
  15. phpdoctor22

    phpdoctor22 Peon

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    The error tells you exactly what the problem is.
     
    phpdoctor22, Jan 12, 2012 IP
  16. Functional

    Functional Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Should it be return false;
     
    Functional, Jan 12, 2012 IP
  17. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #17


    here's the problem.. return $_SESSION($variable);

    it should be return $_SESSION[$variable];
     
    JohnnySchultz, Jan 12, 2012 IP
  18. Functional

    Functional Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Finally got her working! I was starting to wonder if it was ever going to happen.
    After about 20 session.php errors my site finally re-appeared.
    Many Many Thanks to everyone who helped
     
    Functional, Jan 13, 2012 IP