SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple PHP Problem

    Hello,

    Having a problem with the below piece of code, outputs the following:

    Parse error: syntax error, unexpected '{'

    Any help would be much appreciated.

    Kind Regards,

    Richard

    PHP Code:
      <?php 
     
     
    if (
     
     (
    $downtime && ($_SERVER['REMOTE_ADDR'] !== $adminip[1]) 
     
     || 
     
     (
    $_SERVER['REMOTE_ADDR'] !== $adminip[2])
     )
     
     { include 
    "includes/downtime.php"
     }
     elseif 
     (
     (
    $downtime && ($_SERVER['REMOTE_ADDR'] == $adminip[1]) || ($_SERVER['REMOTE_ADDR'] == $adminip[2])
     
     ){
     include (
    $page); 
     }
     elseif (!
    $downtime)
     {
     include(
    $page); } ?>

  2. #2
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need 1 extra closing bracket after $_SERVER['REMOTE_ADDR'] !== $adminip[2]) (the first instance) and 2 extra closing brackets after the second instance of that code.

    If you use a text editor like Crimson Editor or Notepad++ you'll easily see when missing these things because those editors highlight various brackets when a matching opening one exists.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2007
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    to add onto what cranial-bore said.. you also need to use proper code spacing. that code above is very inefficient to read and debug. this is a simple error to see if you space out your code properly.

    example:

    PHP Code:
    <?php
    if ((condition1) || (condition2)) {
        
    action1;
    } elseif ((
    condition3) && (condition4)) {
        
    action2;
    } else {
        
    defaultaction;
    }
    ?>
    the pear coding standard can be found here

  4. #4
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks to those who have taken the time to contribute it is much appreciated.

    The working code is included below:

    PHP Code:
    <?php 
      
    if (!$downtime)
     {include(
    "$page"); } 
     elseif (
    $downtime && ($_SERVER['REMOTE_ADDR'] == $adminip[1]) || ($_SERVER['REMOTE_ADDR'] == $adminip[2]))
      {include (
    "$page");}
     elseif ((
    $downtime && ($_SERVER['REMOTE_ADDR'] !== $adminip[1]) || ($_SERVER['REMOTE_ADDR'] !== $adminip[2])))
     {include (
    "includes/downtime.php");}
     
    ?>

  5. #5
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good, just do me a favour and change include("$page"); to include($page);
    Wrapping variables in double quotes is unnecessary.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •