Page 1 of 1

Parse error: parse error, unexpected $end in...

Posted: Tue Jun 29, 2004 3:44 pm
by natgopal
Hi, shown below, is the source-code in a file(extension 'php'). When I use the function require() on this file, I get the error : "Parse error: parse error, unexpected $end in line 52". Line 52 has only the following two characters: ?>

Can you please tell me what the problem is and what the solution would be? Already, I've spent quite a while trying to fix this problem.

Code: Select all

<?php
  session_start();
  header("Cache-control: private");

  $ses_table = "RAJ_Users";
  $db_con    = "Y";
  $db_host   = 'localhost';
  $db_user   = $_SESSION['username'];
  $db_pass   = $_SESSION['password'];
  $db_dbase  = 'sessions';
  $_path     = "C:\Program Files\Apache Group\Apache2\htdocs\SessionSupport";

  /* Create a connection to a database. */
  function db_connect()  { $mysql_connect_var = mysql_pconnect($db_host, $db_user, $db_pass);
                           $mysql_db  =  mysql_select_db($db_dbase, $mysql_connect_var);
                           if  (!$mysql_connect_var)  { mysql_error();  return FALSE; }
                           if  (!$mysql_db)  {mysql_error();  return FALSE; }
                           return TRUE;
                         }

  /* Open session, if you have your own db connection code, put it in here! */
  function _open($_path, PHPSESSID)  { if  ($db_con == 'Y')  { $db_connect(); }
                                       return TRUE;
                                     }

  /* Close session. */
  function _close()  { $_gc(0);
                       return TRUE;
                     }

  /* Read session data from database. */
  function _read($User_ID, $pwd)  { $session_sql = 'SELECT * FROM $ses_table WHERE User_ID = $db_user AND Password = $db_pass';
                                    $session_res = mysql_query($session_sql);

                                    if  (!$session_res)  { mysql_error();  return ' '; }
                                    $session_num = 0;
                                    $session_num = mysql_num_rows($session_res);
                                    $session_row = mysql_fetch_assoc($session_res);
                                    return $session_row;
                                  }

 /* Garbage collection; deletes old sessions. */
  function _gc($life)  { $ses_life = strtotime('-5 minutes');
                         $session_sql = 'DELETE FROM $ses_table WHERE ses_time < $ses_life';
                         $session_res = mysql_query($session_sql);

                         if  (!$session_res)  { return FALSE; }
                         else  { return TRUE; }
                       }

  session_set_save_handler('_open', '_close', '_read', '', '', '_gc');
?>


feyd | use

Code: Select all

tags.[/color]

Posted: Tue Jun 29, 2004 3:48 pm
by feyd
Your problem is now quite obvious.

Code: Select all

$_path     = "C:\Program Files\Apache Group\Apache2\htdocs\SessionSupport";
should be

Code: Select all

$_path     = "C:\\Program Files\\Apache Group\\Apache2\\htdocs\\SessionSupport";

Posted: Tue Jun 29, 2004 4:14 pm
by natgopal
Hi Feyd,
Thank You. I tried the fix (the line that defines the variable 'path'),
but it did not work.


Regards

Posted: Tue Jun 29, 2004 4:29 pm
by feyd
well.. looking at your code more.. you have some serious errors in using global variables and in how your functions are designed.. take a look at session_set_save_handler again for an example of how it's supposed to be written...

Posted: Wed Jun 30, 2004 11:39 am
by natgopal
Thanks again. I checked the code-section where I call session_set_save_handler, but, it does not seem incorrect. Can you please throw more light on this(I've to get this working and proceed to other tasks)? Meanwhile, I'll try some fixes to find a solution.

Regards

Posted: Wed Jun 30, 2004 12:12 pm
by feyd
ok:
  1. db_connect has some odd logic, and calling mysql_error() outright will print squat (last I checked)
  2. Your _open function should have parse errors. The second argument is supposed to be a variable, not a constant..
  3. _read is taking 2 arguments, while it is only supposed to take 1.
  4. you don't have a _write or _destroy function
  5. _gc isn't using the $life argument
  6. all the functions are using global variable names, yet you did not tell the functions to use the global variables.
  7. _read and _gc are both using single quote strings that contain variables you wish to resolve. They won't because it's a single quote string.