Help with Parse Error in PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JJMcClaw
    New Member
    • Aug 2010
    • 3

    Help with Parse Error in PHP

    Hi All,

    Wonder if anyone can shed any light on this error I am getting.

    I have the following error when trying to access my site:
    "Parse error: syntax error, unexpected '(', expecting T_STRING in /dev/lookatme/_config/config.php on line 145"

    I've looked at the code again but I can't figure out what is wrong... Here is the code.

    Code:
    <?
    session_start();
    
    $config = array();
    
    if ((strpos($_SERVER['SERVER_NAME'],'localhost') !== 0) && (strpos($_SERVER['SERVER_NAME'],'192.168.52.132') !== 0)) {
    	// LIVE SETTINGS
    	$config['site_url'] = "http://www.mysite.co.uk/dev/lookatme/";
    
    	$config['database'] = "mysite_co_uk";
    	mysql_connect("mysite.co.uk.mysql","mysite_co_uk","L3Tm3Inn") or die("Unable to conn. to database");
    	@mysql_select_db($config['database']) or die("Unable to select database");
    
    	// INI SETS
    	ini_set('include_path', '_inc/');
    
    	// PATH TO SITE ROOT
    	$config['site_path'] = "";
    
    } else {
    	// LOCAL SETTINGS
    	$config['site_url'] = "http://localhost/";
    
    	$config['database'] = "localdb";
    	mysql_connect("localhost","root","12345") or die("Unable to conn. to database");
    	@mysql_select_db($config['database']) or die("Unable to select database");
    
    	// INI SETS
    	ini_set('include_path', '_inc/');
    
    	// PATH TO SITE ROOT
    	$config['site_path'] = "";
    
    }
    
    // webpage defaults
    $webpage = array();
    $webpage['id'] = "";
    $webpage['sets'] = array();
    $webpage['default'] = 0;
    $webpage['system'] = 1;
    $webpage['versionid'] = "";
    $webpage['version_name'] = "";
    $webpage['meta_title'] = "";
    $webpage['meta_keywords'] = "";
    $webpage['meta_description'] = "";
    $route = array();
    
    $admin = array();
    $admin['id'] = (isset($_SESSION['adminid'])) ? $_SESSION['adminid'] : "" ;
    $admin['tab'] = (isset($_SESSION['admintab'])) ? $_SESSION['admintab'] : "" ;
    
    $user = array();
    $user['spamprotect'] = (isset($_SESSION['spamprotect'])) ? $_SESSION['spamprotect'] : "" ;
    
    if (isset($_GET['tab'])) {
    	$admin['tab'] = $_GET['tab'];
    	$_SESSION['admintab'] = $admin['tab'];
    
    }
    
    
    // INCLUDES
    include("common.php");
    include("forms.php");
    include("sql_functions.php");
    include("emails.php");
    include("phpmailer/class.phpmailer.php");
    include("generator.php");
    include("cms_functions.php");
    
    // DEFAULTS
    
    $default = array();
    
    // GET CONFIG DETAILS
    
    $sql = "
    	SELECT
    		*
    	FROM
    		core_config
    	WHERE
    		active = '1'
    ";
    $result = mysql_query($sql);
    $num = mysql_numrows($result);
    
    if ($num > 0) {
    	$i = 0;
    	while ($i < $num) {
    		$key = mysql_result($result,$i,"field");
    		$value = mysql_result($result,$i,"value");
    		$config[$key] = $value;
    	$i++;
    	}
    
    }
    
    // GET ADMIN DETAILS
    
    if ($admin['id'] != "") {
    	$sql = "
    		SELECT
    			*
    		FROM
    			admin_users
    		INNER JOIN
    			admin_types ON
    			admin_users.typeid = admin_types.id
    		WHERE
    			admin_users.id='".$admin['id']."'
    		";
    	$result = mysql_query($sql);
    	$num = mysql_num_rows($result);
    
    	if ($num == 0) {
    		exit();
    	} else {
    		$admin['firstname'] = mysql_result($result,0,"firstname");
    		$admin['surname'] = mysql_result($result,0,"surname");
    		$admin['typeid'] = mysql_result($result,0,"typeid");
    		$admin['type'] = mysql_result($result,0,"name");
    		$admin['email'] = mysql_result($result,0,"email");
    	}
    } else {
    	$admin['firstname'] = "";
    	$admin['surname'] = "";
    	$admin['typeid'] = "";
    	$admin['type'] = "";
    	$admin['email'] = "";
    }
    
    // SPAM PROTECTION
    if ( ($user['spamprotect'] == "") || ( ( (isset($_GET['spamprotect'])) && ($_GET['spamprotect'] == "refresh") ) ) ) {
    	$user['spamprotect'] = password_return_random(4);
    	$_SESSION['spamprotect'] = $user['spamprotect'];
    }
    
    // HARD CODED ADMIN REDIRECT
    function page_requires_admin_login() {
    	extract($GLOBALS);
    	if ($admin['id'] == "") {
    		$msg = "0|Please Log In|You must sign in to view the page you were looking for.";
    		goto('../index/index.php?msg='.urlencode($msg));
    	}
    }
    
    
    // ADMIN TYPE REDIRECT
    function page_requires_admin_types($requiredtypes) {
    
    	if ($requiredtypes != "") {
    		extract($GLOBALS);
    		$typearray = explode(",", $requiredtypes);
    
    		if (!in_array($admin['typeid'], $typearray)) {
    			if ($admin['id'] == "") {
    				$msg = "0|Sign In Required|Sorry, you can not view that page.";
    				goto('../index/index.php?msg='.urlencode($msg));
    			} else {
    				$msg = "0|Access Restricted|Sorry, you do not have access to that page.";
    				goto('../index/index.php?msg='.urlencode($msg));
    			}
    		}
    	}
    }
    
    
    
    // HTTP SWITCH
    function page_requires_https($v) {
    
    	extract($GLOBALS);
    
    	if ($config['https_enabled'] == "True") {
    
    		if (isset($_SERVER['QUERY_STRING'])) {
    			$qs = "?".$_SERVER['QUERY_STRING'];
    		} else {
    			$qs = "";
    		}
    
    		switch ($v) {
    			case "1":
    				// https on
    				if($_SERVER['HTTPS'] !== "on") {
    					// redirect here
    				}
    			break;
    			case "0":
    				// https off
    				if($_SERVER['HTTPS'] == "on") {
    					// redirect here
    				}
    			break;
    			case "2":
    				// do nothing
    			break;
    		}
    	}
    }
    
    
    ?>
    Anyone got any suggestions - I'm now stumped on this one!

    Cheers,

    Jay
    Last edited by JJMcClaw; Aug 11 '10, 07:06 PM. Reason: Amend Code
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    You are not using the goto command properly.
    PHP Manual - goto

    have a look at the header() function.PHP Manual - Header

    Comment

    • JJMcClaw
      New Member
      • Aug 2010
      • 3

      #3
      Hey,

      I also have this being called from a "Common" list of functions:

      Code:
      function goto($location) {
      
      	$tag = "\\";
      
      	if (dirname($_SERVER['SCRIPT_NAME']) == $tag) {
      		$str = "/";
      	} else {
      		$str = dirname($_SERVER['SCRIPT_NAME']);
      	}
      
      	if ($_SERVER['HTTPS'] !== "on") {
      		header('location: http://'.$_SERVER['HTTP_HOST'].$str.'/'.$location);
      		exit();
      	} else {
      		header('location: https://'.$_SERVER['HTTP_HOST'].$str.'/'.$location);
      		exit();
      	}
      
      }

      Comment

      • JKing
        Recognized Expert Top Contributor
        • Jun 2007
        • 1206

        #4
        You should change the name of your function because goto is already a function in php.

        Comment

        • JJMcClaw
          New Member
          • Aug 2010
          • 3

          #5
          Thanks JKing, thats spot on, I completely forgot and it came online after 5.2, my new server runs on 5.3.3 so hence the error.

          All up and running.

          Appreciate your help :-)

          Comment

          Working...