1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Weird problem on host, not on localhost

Discussion in 'PHP' started by PoPSiCLe, Sep 21, 2013.

  1. #1
    Okay. I've been working on this project for a while now, and have now run into a hitch - it's running perfectly fine on my localhost running WAMP - PHP 5.4.3, Apache 2.4.2, MySQL 5.5.24

    When trying to put this onto a webhost for testing, it breaks. I've checked and doublechecked the config.php, coreclass.php and such, and can't see anything obviously wrong.

    The full project can be found here, on Github: https://github.com/langbakk/persdbnew_kvarteret if anyone want to take a stab at figuring it out - the database file is within the setup/-folder (which has to be renamed, else nothing works as it's supposed to) - and the only settings needed to be changed is in config.php (in theory) - where you'll find the db-info and folder-settings etc.

    What happens is that I get an "unexpected end of file" in my index.php, it doesn't display login.php and I don't get any PHP-errors.

    I know my webhost which I'm trying to run it on is running PHP 5.3.7, and apache 2.2.x, but that shouldn't really affect this.

    I'm thinking there's something wrong in the coreclass.php, but I can't for the life of me understand what it is.

    I'll post index.php, config.php and coreclass.php here, for you to look at.

    index.php
    Code (Text):
    1. <?php
    2. session_start();
    3. $inactive = 600; // set timeout period in seconds
    4. if (isset($_SESSION['timeout'])) {
    5.     $session_life = $_SERVER['REQUEST_TIME'] - $_SESSION['timeout'];
    6. if ($session_life > $inactive) {
    7.     session_unset();
    8.     session_destroy();
    9.     header('refresh: 0');
    10.     exit;
    11. } elseif ($session_life < $inactive) {
    12.     $_SESSION['timeout'] = $_SERVER['REQUEST_TIME'];
    13. }
    14. }
    15.  
    16.  
    17. //DEBUG echo $_SESSION['userrole_name'];
    18.  
    19. include 'config.php';
    20. include 'functions.php';
    21.  
    22. // DEBUG
    23. print_r($_SESSION);
    24.  
    25. ?>
    26. <!DOCTYPE html>
    27. <html>
    28.     <head>
    29.         <meta charset="UTF-8">
    30.         <title>Personaldatabase</title>
    31.         <link type="text/css" href="http://fonts.googleapis.com/css?family=Cuprum&amp;subset=latin" rel="stylesheet">
    32.         <link type="text/css" href="<?php echo $baseurl.$csspath; ?>personaldatabase.css" rel="stylesheet" media="screen, projection">
    33.  
    34. <?php loadFiles('js', $scriptpath); ?>
    35.  
    36. <script type="text/javascript">
    37.  
    38. </script>
    39.  
    40.     </head>
    41.     <body>
    42.         <header>
    43.             <h1>Personaldatabase</h1>
    44.  
    45. <?php if ($isloggedin) { ?>
    46.             <p>Du er logget inn som: <strong><?php echo $fullname; ?></strong> med følgende tilgangsnivå: <strong <?php if ($activeuser == 0) { ?>class="inactive"<?php } ?>><?php echo $userrole_name; ?></strong><span class="right"><?php echo $version; ?></span></p>
    47. <?php } ?>
    48.         </header>
    49.        
    50.         <section id="menu">
    51. <?php
    52.     if (!$isloggedin) {
    53. ?>
    54.             <p class="mainmenu">Dette er Kvarterets personaldatabase</p>
    55.             <p class="mainmenu">Her kan du logge inn med din registrerte epostadresse og passord, og få tilgang til personaldatabasen - tilgangen begrenses etter hvilken rolle du har i systemet - er du kun bruker får du kun tilgang til å se informasjon</p>
    56.  
    57. <?php
    58.     } else {
    59.         display_menu($userrole,$usergroup);
    60.     }
    61. ?>
    62.         </section>
    63.  
    64.         <section id="content">
    65. <?php
    66.     if (!$isloggedin && is_dir('setup')) {
    67.         $display = new PageView(); echo $display->runSetup();
    68.     } elseif (!$isloggedin) {
    69.             $display = new PageView(); echo $display->getLogin();
    70.     } else {
    71.             $display = new PageView(); echo $display->getPage();
    72.     }
    73. ?>
    74.         </section>
    75.        
    76.         <footer>
    77. <?php if ($isloggedin) {
    78.             $display = new PageView(); echo $display->getLogin();
    79. }
    80. // DEBUG session-timeout - this should be removed before release
    81. $showsessionlife = (isset($session_life)) ? $session_life : "";
    82.                     echo $showsessionlife;
    83.                     echo "<br>";
    84.                     echo $inactive;
    85. ?>
    86.         </footer>  
    87.     </body>
    88. </html>
    config.php
    Code (Text):
    1.  
    2. <?php
    3. if (!session_id()) { session_start(); };
    4.  
    5. $version = "ver. 0.4 (alpha)";
    6.  
    7. //Changelog:
    8. // Ver 0.4:
    9. //     added password recovery
    10.  
    11. // This file, in conjunction with coreclass.php, language.php and functions.php is the main core behind the site.
    12. // This file contains most of the config-parameters, and the coreclass.php-file contains the actual implementation of the configuration-settings found in this file.
    13. // The language.php-file contains the language-settings, arrays for language-specific settings etc.
    14. // Functions.php contains functions used for minor page-content retrieval, for instance getting files from the script and css-folders, and providing the menu etc.
    15.  
    16. // Config.php should be loaded on every page of the site
    17.  
    18. // override settings in the php.ini file
    19. //ini_set("session.cookie_lifetime","3600"); //set the time-to-live for the sessions - if this isn't set, the time-out for the sessions will be the default setting in php.ini
    20.  
    21. // if this is set, it trumps the session-timeout in php.ini
    22.  
    23. // DB-information
    24. $dbhost = '127.0.0.1'; // Set the hostname for your database - either a direct IP-address, or a domain name
    25. $dbport = ''; // If a custom port is needed to connect to the database, set the value here
    26. $dbname = 'persdbredesign'; // Set the database name
    27. $dbusername = 'root'; // Set the username for accessing the database
    28. $dbpassword = ''; // Set the password for accessing the database - if no password is set, leave it blank
    29.  
    30.  
    31. // User-info (this will be session-based from loginform
    32. $isloggedin = (!empty($_SESSION['loggedin'])) ? $_SESSION['loggedin'] : "";
    33. $userid = (!empty($_SESSION['userid'])) ? $_SESSION['userid'] : "";
    34. $activeuser = (!empty($_SESSION['activeuser']) ? $_SESSION['activeuser'] : "");
    35. $usergroup = (!empty($_SESSION['usergroup'])) ? $_SESSION['usergroup'] : "";
    36. $userrole = (!empty($_SESSION['userrole'])) ? $_SESSION['userrole'] : "";
    37. $userrole_name = (!empty($_SESSION['userrole_name'])) ? $_SESSION['userrole_name'] : "";
    38. $userlanguage = (!empty($_SESSION['userlanguage'])) ? $_SESSION['userlanguage'] : "";
    39. $fullname = (!empty($_SESSION['fullname'])) ? $_SESSION['fullname'] : "";
    40.  
    41.  
    42. // Security-settings
    43. $hash = '3f,,de=?//--*fff'; //hash used for salting the provided passwords users add to the database - do not change this after installation, as this will render current passwords stored in the database useless
    44.  
    45.  
    46. // Path-configuration
    47. $domain = $_SERVER['SERVER_NAME'];
    48. $rootfolder = "/persdb/"; // leave this as / if installed in root webfolder
    49. $csspath = "css/";
    50. $scriptpath = "script/";
    51. $imagepath = "images/";
    52. $templatepath = "template/";
    53. $baseurl = "http://".$domain.$rootfolder."";
    54. $baseurl_page = $baseurl."index.php?page=";
    55. $current_page = (!empty($_GET['page'])) ? $_GET['page'] : "";
    56. $sub_page = (!empty($_GET['subpage'])) ? $_GET['subpage'] : "";
    57. $sub_page_url = (!empty($_GET['subpage'])) ? "&amp;subpage=".$sub_page : "";
    58.  
    59.  
    60. // Default values inserted into the pages - contact-emails etc.
    61. $main_support_email = 'langbakk@gmail.com'; // note that this has to be used inside an <a href="">-tag if you want it to be clickable
    62. $forgottenpassword = (!empty($_SESSION['forgottenpassword'])) ? $_SESSION['forgottenpassword'] : "";
    63.  
    64.  
    65. // Date-settings and controls for the timesheet-functionality
    66.  
    67. $year = (!empty($_GET['year'])) ? $_GET['year'] : "";
    68. $month = (!empty($_GET['month'])) ? $_GET['month'] : "";
    69. $place = (!empty($_GET['place'])) ? $_GET['place'] : "";
    70.  
    71. $nextmonth = sprintf("%02d", $month+1);
    72. $lastmonth = sprintf("%02d", $month-1);
    73.  
    74. $nextmonth = $baseurl_page.$current_page.$sub_page_url."&amp;year=".$year."&amp;month=".$nextmonth."&amp;place=".$place;
    75. $lastmonth = $baseurl_page.$current_page.$sub_page_url."&amp;year=".$year."&amp;month=".$lastmonth."&amp;place=".$place;
    76.  
    77. $placeurl = $baseurl_page.$current_page.$sub_page_url."&amp;year=".$year."&amp;month=".$month."&amp;place=";
    78.  
    79. $currentday = date('d');
    80. $currentweek = date('W');
    81.  
    82. if (empty($year) && empty($month)) {
    83. $daysinmonth = "";
    84. }
    85. elseif (!empty($year) && !empty($month)) {
    86. $daysinmonth = cal_days_in_month(CAL_GREGORIAN, $month, $year);
    87. };
    88.  
    89. $date = date('Y-m-d');
    90. $time = date('H:i:s');
    91. $todaydate = $date." ".$time;
    92.  
    93. $complete_var_set = get_defined_vars();
    94.  
    95.  
    96. // DEBUG print_r($complete_var_set);
    97.  
    98.  
    99. require_once('coreclass.php');
    100.  
    101.  
    102. ?>
    coreclass.php
    Code (Text):
    1.  
    2. <?php
    3. // you should not ever need to edit this file. However, if you add settings to the config.php-file, you might need to add those to this file - bottom Config-parameters, and the appropriate classes where you want to use the configured items
    4.  
    5. class Core
    6. {
    7.   public $dbh; // handle of the db connexion
    8.   private static $instance;
    9.  
    10.   private function __construct()
    11.   {
    12.   // building data source name from config
    13.   $dsn = 'mysql:host=' . Config::read('db.host') .
    14.   ';dbname='  . Config::read('db.basename') .
    15.   ';port='  . Config::read('db.port') .
    16.   ';connect_timeout=15';
    17.   // getting DB user from config  
    18.   $user = Config::read('db.user');
    19.   // getting DB password from config  
    20.   $password = Config::read('db.password');
    21.  
    22.   $setUTF8 = array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"); //comment out this or change the character encoding if your database is not set to UTF-8 character encoding
    23.  
    24.   $this->dbh = new PDO($dsn, $user, $password, $setUTF8);
    25.   }
    26.  
    27.   public static function getInstance()
    28.   {
    29.   if (!isset(self::$instance))
    30.   {
    31.   $object = __CLASS__;
    32.   self::$instance = new $object;
    33.   }
    34.   return self::$instance;
    35.   }
    36.  
    37.   // others global functions
    38. }
    39.  
    40. class Config
    41. {
    42.   static $confArray;
    43.  
    44.   public static function read($name)
    45.   {
    46.   return self::$confArray[$name];
    47.   }
    48.  
    49.   public static function write($name, $value)
    50.   {
    51.   self::$confArray[$name] = $value;
    52.   }
    53.  
    54. }
    55.  
    56. class PageView
    57. {
    58.   //private $page;
    59.  
    60.   function __construct() {
    61.   $this->page = !empty($_GET['page']);
    62.   $this->subpage = isset($_GET['subpage']);
    63.   }
    64.  
    65.   function runSetup() {
    66.   $core = Core::getInstance();
    67.   $hash = Config::read('hash');
    68.   if (is_dir('setup')) {
    69.   $path = "setup/";
    70.   include $path."index.php";
    71.   }
    72.   }
    73.  
    74.   function getLogin() {
    75.   $core = Core::getInstance();
    76.   $hash = Config::read('hash');
    77.   // $sessiontimeout = Config::read('user.timeout');
    78.   $isloggedin = Config::read('user.loggedin');
    79.   $forgottenpassword = Config::read('forgottenpassword');
    80.   if ($forgottenpassword == 1) {
    81.   include 'forgottenpassword.php';
    82.   } elseif (empty($isloggedin)) {
    83.   include 'login.php';
    84.   } else {
    85.   include 'login.php';  
    86.   }
    87.   }
    88.  
    89.   function getPage() {
    90.  
    91.   $hash = Config::read('hash');
    92.   $isloggedin = Config::read('user.loggedin');
    93.   // $sessiontimeout = Config::read('user.timeout');
    94.   $userid = Config::read('user.id');
    95.   $activeuser = Config::read('activeuser');
    96.   $usergroup = Config::read('user.group');
    97.   $userrole = Config::read('user.role');
    98.   $userrole_name = Config::read('user.role.name');
    99.   $userlanguage = Config::read('user.language');
    100.   $fullname = Config::read('fullname');
    101.   $baseurl = Config::read('baseurl');
    102.   $baseurl_page = Config::read('baseurl_page');
    103.   $scriptpath = Config::read('scriptpath');
    104.   $templatepath = Config::read('templatepath');
    105.   $imagepath = Config::read('imagepath');
    106.   $current_page = Config::read('current_page');
    107.   $sub_page = Config::read('sub_page');
    108.   $main_support_email = Config::read('main_support_email');
    109.   $forgottenpassword = Config::read('forgottenpassword');
    110.  
    111.   $year = Config::read('year');
    112.   $month = Config::read('month');
    113.   $nextmonth = Config::read('nextmonth');
    114.   $lastmonth = Config::read('lastmonth');
    115.   $currentday = Config::read('currentday');
    116.   $currentweek = Config::read('currentweek');
    117.   $daysinmonth = Config::read('daysinmonth');
    118.   $date = Config::read('date');
    119.   $time = Config::read('time');
    120.   $todaydate = Config::read('todaydate');
    121.  
    122.   $place = Config::read('place');
    123.   $placeurl = Config::read('placeurl');
    124.  
    125.  
    126.   $core = Core::getInstance();
    127.  
    128.   require_once('language.php');
    129.  
    130. $page = "";
    131. $subpage = "";
    132. $sqlcore = "";
    133.   if (!empty($this->page)) {
    134.   if (is_dir($_GET['page'])) {
    135.   $path = "".$_GET['page']."/";
    136.  
    137.   } else {
    138.   $path = "";
    139.   }
    140.   if (!empty($this->subpage)) {
    141.   $subpage = $_GET['subpage'];
    142.   }  
    143.   $page = $_GET['page'];
    144.   if (file_exists($path.$subpage.".php")) {
    145.   include $path.$subpage.".php";
    146.   } elseif (file_exists($path.$page.".php")) {
    147.   include $path.$page.".php";
    148.   } elseif (!empty($this->page) && !is_dir($_GET['page']) && !file_exists($path.$page.".php")) {
    149.   // echo "elseif";
    150.   $sqlcore = "SELECT * FROM persdb_content WHERE content_page = '$page' AND (group_access = '$usergroup' OR group_access = 0)";
    151.   }
    152.   } else {
    153.   // echo "else";
    154.   $sqlcore = "SELECT * FROM persdb_content WHERE content_page = '$page' AND (group_access = '$usergroup' OR group_access = 0)";
    155.   }
    156.   //DEBUG echo $page; echo $sqlcore;
    157.  
    158.   // $core = Core::getInstance();
    159.   $stmt = $core->dbh->prepare($sqlcore);  
    160.   $stmt->bindParam(':page', $page, PDO::PARAM_STR);
    161.  
    162.   if ($stmt->execute()) {
    163.   $rowscount = $stmt->rowCount();
    164.   if ($rowscount == 0) {
    165.   echo "<article>";
    166.   echo "<div>";
    167.   echo "<p>Du har ikke tilgang til denne siden</p>";
    168.   echo "</div>";
    169.   echo "</article>";
    170.   } elseif ($rowscount != 0) {
    171.   while ($row = $stmt->fetch()) {
    172.   echo "<article>";
    173.   if ($row['edit_access'] > $userrole) {
    174.   echo '<div class="edit"><div class="adminbuttons"><a href="#" id="'.$row['id'].'" class="editbutton confirm"></a><a href="#" class="deletebutton confirm"></a></div>';
    175.   } else {
    176.   echo '<div>';
    177.   }
    178.   echo "<h2>".$row['content_heading']."</h2>";
    179.   echo parseDBText($row['content'], $userrole);
    180.    
    181.   echo '</div>';
    182.   echo "</article>";
    183.   }
    184.   }
    185.   }
    186.    
    187.    
    188. }
    189. }
    190.  
    191. // db
    192. Config::write('db.host', $dbhost);
    193. Config::write('db.port', '');
    194. Config::write('db.basename', $dbname);
    195. Config::write('db.user', $dbusername);
    196. Config::write('db.password', '');
    197.  
    198. Config::write('hash', $hash);
    199. Config::write('baseurl',$baseurl);
    200. Config::write('baseurl_page',$baseurl_page);
    201. Config::write('templatepath', $templatepath);
    202. Config::write('scriptpath', $scriptpath);
    203. Config::write('imagepath', $imagepath);
    204. Config::write('current_page', $current_page);
    205. Config::write('sub_page', $sub_page);
    206.  
    207. Config::write('user.loggedin', $isloggedin);
    208. Config::write('user.id', $userid);
    209. Config::write('activeuser', $activeuser);
    210. Config::write('user.group', $usergroup);
    211. Config::write('user.role', $userrole);
    212. Config::write('user.role.name', $userrole_name);
    213. Config::write('user.language', $userlanguage);
    214. Config::write('fullname', $fullname);
    215. // Config::write('user.timeout', $sessiontimeout);
    216.  
    217. Config::write('main_support_email',$main_support_email);
    218. Config::write('forgottenpassword',$forgottenpassword);
    219.  
    220. // Date and timesheet-config
    221. Config::write('year', $year);
    222. Config::write('month', $month);
    223. Config::write('nextmonth', $nextmonth);
    224. Config::write('lastmonth', $lastmonth);
    225. Config::write('currentday', $currentday);
    226. Config::write('currentweek', $currentweek);
    227. Config::write('daysinmonth', $daysinmonth);
    228. Config::write('date', $date);
    229. Config::write('time', $time);
    230. Config::write('todaydate', $todaydate);
    231.  
    232.  
    233. Config::write('place', $place);
    234. Config::write('placeurl', $placeurl);
    235.  
    236. ?>
    Hopefully someone can spot what I'm doing wrong :/
    PoPSiCLe, Sep 21, 2013 IP
  2. competent123

    competent123 Notable Member

    Messages:
    1,591
    Likes Received:
    52
    Best Answers:
    6
    Trophy Points:
    205
    #2
    line 36- there is no script content in index

    2- post functions.php here as well

    usually it seems to be a missing; or a missing } somewhere ( even in includeed files
    also, make sure your server supports shortcode ( for some included file)


    in core file, there seems to be empty space before and after php tag, can you confirm.
    competent123, Sep 21, 2013 IP
  3. PoPSiCLe

    PoPSiCLe Well-Known Member

    Messages:
    1,219
    Likes Received:
    109
    Best Answers:
    51
    Trophy Points:
    160
    #3
    I do not use shortcodes, and yes, it's all coded by hand, by me. And localhost has shortcodes turned off. I know there isn't anything in the script brackets - they're just there for quick access to adding js on the fly.

    Here's functions.php
    Code (Text):
    1. <?php
    2.  
    3. function display_menu($role,$usergroup)
    4. {
    5. $sql = "SELECT * FROM persdb_menu WHERE subitem = 0 AND access >= :userrole ORDER BY category";
    6.         //DEBUG echo $sql;
    7.  
    8.                 try {
    9.                 $core = Core::getInstance();
    10.                 $stmt = $core->dbh->prepare($sql);
    11.                 $stmt->bindParam(':userrole', $role, PDO::PARAM_INT);
    12.                
    13.                 if ($stmt->execute()) {
    14.                         $count = $stmt->rowCount();
    15.                         }
    16.                 } catch (PDOException $pe) {
    17.                     trigger_error('Could not connect to MySQL database. ' . $pe->getMessage() , E_USER_ERROR);
    18.                 }
    19.  
    20.     //$i = 0;
    21.     while ($row = $stmt->fetch()) {
    22.            
    23.             $id = $row['id'];
    24.             $page = $row['menutitle'];
    25.             $accessname = $row['accessname'];
    26.             $category = $row['category'];
    27.             ?>
    28.             <ul class="mainmenu">
    29.         <li id="menuitem_<?php echo $id; ?>"><a id="<?php echo $accessname; ?>_page" href="<?php if ($accessname == 'index') { ?>index.php<?php } else { ?>index.php?page=<?php echo $accessname; } ?>" title="<?php echo ucfirst($page); ?>"><?php echo ucfirst($page); ?></a></li>
    30. <?php
    31.         if ($role == 1 || $role == 2) {
    32.             $subsql = "SELECT * FROM persdb_menu WHERE category = '$category' AND subitem = category AND access >= :userrole";
    33.         } else {
    34.             $subsql = "SELECT * FROM persdb_menu WHERE category = '$category' AND subitem = category AND access >= :userrole AND (group_access = :usergroup OR group_access = 0)";
    35.         }
    36.             //DEGUG        echo $subsql;
    37.                 try {
    38.                 $core = Core::getInstance();
    39.                 $subsql = $core->dbh->prepare($subsql);
    40.                 $subsql->bindParam(':userrole', $role, PDO::PARAM_INT);
    41.                 if ($role != 1 AND $role != 2) {
    42.                 $subsql->bindParam(':usergroup', $usergroup, PDO::PARAM_INT);
    43.                 }
    44.                
    45.                 if ($subsql->execute()) {
    46.                         $count = $subsql->rowCount();
    47.                         }
    48.                 } catch (PDOException $pe) {
    49.                     trigger_error('Could not connect to MySQL database. ' . $pe->getMessage() , E_USER_ERROR);
    50.                 }
    51.  
    52.         if ($count == 0) { ?>
    53.     </ul>
    54. <?php }
    55.         else {
    56. ?>
    57.         <li class="sub_menu_main">
    58.             <ul>
    59. <?php
    60.             while ($subrow = $subsql->fetch()) {
    61.                     $id = $subrow['id'];
    62.                     $page = $subrow['menutitle'];
    63.                     $subaccessname = $subrow['accessname'];
    64.                     $category = $subrow['category'];
    65.                     $href = $subrow['href'];
    66.                 ?>
    67.                    
    68.                     <li id="menuitem_<?php echo $id; ?>"><a id="<?php echo $subaccessname; ?>" href="<?php if ($href == "") { ?>index.php?page=<?php echo $subaccessname; ?><?php } else { echo $href; } ?>" title="<?php echo ucfirst($page); ?>"><?php echo ucfirst($page); ?></a></li>
    69.     <?php        }
    70.             ?>
    71.             </ul>
    72.         </li>
    73.             </ul>
    74. <?php    }
    75.  
    76.     }
    77. ?>
    78.  
    79.     <?php
    80.     }
    81.  
    82.  
    83.  
    84.  
    85. function get_menu($role) {
    86.     $sql = "SELECT * FROM menu WHERE subitem = 0 AND access >= :userrole";
    87.    
    88.                 try {
    89.                 $core = Core::getInstance();
    90.                 $stmt = $core->dbh->prepare($sql);
    91.                 $stmt->bindParam(':userrole', $role, PDO::PARAM_INT);
    92.                
    93.                 if ($stmt->execute()) { ?>
    94.                     <ul id="mainmenu">
    95.                     <?php
    96.                     while ($row  = $stmt->fetch()) { ?>
    97.                         <li><?php echo ucfirst($row['menutitle']); ?></li>
    98.                     <?php } ?>
    99.                     </ul>
    100.             <?php }
    101.                 } catch (PDOException $pe) {
    102.                     trigger_error('Could not connect to MySQL database. ' . $pe->getMessage() , E_USER_ERROR);
    103.                 }
    104.  
    105.     }
    106.    
    107. function loadFiles($filetype, $path) {
    108.  
    109.     // create an array to hold directory list
    110.     $results = array();
    111.  
    112.     // create a handler for the directory
    113.     $handler = opendir($path);
    114.  
    115.     // open directory and walk through the filenames
    116.     while ($file = readdir($handler)) {
    117.         $ext = pathinfo($file, PATHINFO_EXTENSION);
    118.  
    119.       // if file isn't this directory or its parent, add it to the results
    120.       if ($file != "." && $file != ".." && $ext == $filetype) {
    121.         $results[] = $file;
    122.       }
    123.  
    124.     }
    125.  
    126.     // tidy up: close the handler
    127.     closedir($handler);
    128.  
    129.     // done!
    130.         if ($filetype == 'js') {
    131.     foreach ($results as $key => $value) {
    132.         echo '<script src="'.$path.$value.'" type="text/javascript"></script>', PHP_EOL;
    133.         }
    134.     }
    135.  
    136.   }
    137.  
    138. function insertLocalURL($pagevalue = "index.php") {
    139.     if ($pagevalue == "index.php") {
    140.         $returnvalue = "index.php";
    141.     } else {
    142.         $returnvalue = "index.php?page=".$pagevalue."";
    143.     }
    144. echo $returnvalue;
    145. }
    146.  
    147.  
    148.  
    149.         function selectorPopulation($table, $idname, $columnname = 'name') {
    150.             $sql = "SELECT * FROM $table";
    151.  
    152.             $core = Core::getInstance();
    153.             $stmt = $core->dbh->query($sql);
    154.  
    155.             while ($row = $stmt->fetch()) {
    156.                 if (isset(${$idname})) {
    157.                     if ($row['id'] == $_POST[$idname]) {
    158.                         $selected = 'selected="selected"';
    159.                     } else {
    160.                         $selected = '';
    161.                     }
    162.                 } elseif ($columnname == 'countryname' && !isset($nationality) && $row['id'] == '163') {
    163.                         $selected = 'selected="selected"';
    164.                 } else {
    165.                         $selected = '';
    166.                 }
    167.             ?>
    168.             <option value="<?php echo $row['id']; ?>" <?php echo $selected; ?>><?php echo $row[$columnname]; ?></option>
    169.             <?php
    170.             }
    171.  
    172.         };
    173.  
    174. function passwordHash($hash, $password) {
    175.         $password = hash('sha512', $hash.$password);
    176.         return $password;
    177. };
    178. function parseURLContent($value) {
    179.     $value = str_replace(" ","%20", $value); //replaces spaces
    180.     return $value;
    181. }
    182. function parseDBText($value, $userrole) {
    183.     include 'config.php'; //this file is included here to provide site-variables without having to load them as globals
    184.     function normalize($value) {
    185.         // Normalize line endings
    186.         // Convert all line-endings to UNIX format
    187.         $value = str_replace('\r\n', '\n', $value);
    188.         $value = str_replace('\r', '\n', $value);
    189.         // Don't allow out-of-control blank lines
    190.         $value = preg_replace('/\n{2,}/', '\n\n', $value);
    191.         return $value;
    192.     }
    193.  
    194.   // code replacements
    195.     $value = preg_replace('#\n(\s*\n)+#', '</p><p>', $value);
    196.     $value = preg_replace('#\n#', '</p><p>', $value);
    197.     $value = '<p>'.$value.'</p>';  
    198.     $value = preg_replace('#\[b\](.+)\[\/b\]#iUs', '<b>$1</b>', $value);
    199.     $value = preg_replace('#\[urlintern\=(.+)\](.+)\[\/urlintern\]#iUs', '<a href="index.php?page=$1">$2</a>', $value);
    200.     $value = preg_replace_callback('#\[role\=(.+)\](.+)\[\/role\]#iUs', function ($matches) use ($userrole) { if ($matches[1] >= $userrole) { return $matches[2]; }; }, $value);
    201.     $value = preg_replace('#\[adminemail\]#iUs', '<a href="mailto:'.$main_support_email.'">'.$main_support_email.'</a>', $value);
    202.     $value = preg_replace('#\[url\=(.+)\](.+)\[\/url\]#iUs', '<a href="$1">$2</a>', $value);
    203.     $value = preg_replace('#\[img\](.+)\[\/img\]#iUs', '<img src="$1" alt="Image" />', $value);
    204.         return($value);
    205.  
    206. }
    207.  
    208. /*
    209. * PHP function to resize an image maintaining aspect ratio
    210. * http://salman-w.blogspot.com/2008/10/resize-images-using-phpgd-library.html
    211. *
    212. * Creates a resized (e.g. thumbnail, small, medium, large)
    213. * version of an image file and saves it as another file
    214. */
    215.  
    216. // this is a copy / paste function, and is temporary - might replace this with own function later
    217.  
    218. define('THUMBNAIL_IMAGE_MAX_WIDTH', 160);
    219. define('THUMBNAIL_IMAGE_MAX_HEIGHT', 160);
    220.  
    221. function generate_image_thumbnail($source_image_path, $thumbnail_image_path)
    222. {
    223.     list($source_image_width, $source_image_height, $source_image_type) = getimagesize($source_image_path);
    224.     switch ($source_image_type) {
    225.         case IMAGETYPE_GIF:
    226.             $source_gd_image = imagecreatefromgif($source_image_path);
    227.             break;
    228.         case IMAGETYPE_JPEG:
    229.             $source_gd_image = imagecreatefromjpeg($source_image_path);
    230.             break;
    231.         case IMAGETYPE_PNG:
    232.             $source_gd_image = imagecreatefrompng($source_image_path);
    233.             break;
    234.     }
    235.     if ($source_gd_image === false) {
    236.         return false;
    237.     }
    238.     $source_aspect_ratio = $source_image_width / $source_image_height;
    239.     $thumbnail_aspect_ratio = THUMBNAIL_IMAGE_MAX_WIDTH / THUMBNAIL_IMAGE_MAX_HEIGHT;
    240.     if ($source_image_width <= THUMBNAIL_IMAGE_MAX_WIDTH && $source_image_height <= THUMBNAIL_IMAGE_MAX_HEIGHT) {
    241.         $thumbnail_image_width = $source_image_width;
    242.         $thumbnail_image_height = $source_image_height;
    243.     } elseif ($thumbnail_aspect_ratio > $source_aspect_ratio) {
    244.         $thumbnail_image_width = (int) (THUMBNAIL_IMAGE_MAX_HEIGHT * $source_aspect_ratio);
    245.         $thumbnail_image_height = THUMBNAIL_IMAGE_MAX_HEIGHT;
    246.     } else {
    247.         $thumbnail_image_width = THUMBNAIL_IMAGE_MAX_WIDTH;
    248.         $thumbnail_image_height = (int) (THUMBNAIL_IMAGE_MAX_WIDTH / $source_aspect_ratio);
    249.     }
    250.     $thumbnail_gd_image = imagecreatetruecolor($thumbnail_image_width, $thumbnail_image_height);
    251.     imagecopyresampled($thumbnail_gd_image, $source_gd_image, 0, 0, 0, 0, $thumbnail_image_width, $thumbnail_image_height, $source_image_width, $source_image_height);
    252.     imagejpeg($thumbnail_gd_image, $thumbnail_image_path, 90);
    253.     imagedestroy($source_gd_image);
    254.     imagedestroy($thumbnail_gd_image);
    255.     return true;
    256. }
    257.  
    258. ?>
    PoPSiCLe, Sep 21, 2013 IP
  4. Basti

    Basti Active Member

    Messages:
    627
    Likes Received:
    6
    Best Answers:
    3
    Trophy Points:
    90
    #4
    config.php
    PHP:
    1.  
    2. if (!session_id()) { session_start(); };
    3.  
    PHP:
    1.  
    2. elseif (!empty($year) && !empty($month)) {
    3. $daysinmonth = cal_days_in_month(CAL_GREGORIAN, $month, $year);
    4. };
    5.  
    There should not be any ; after a curly bracket. Not sure if it is allowed in some php versions since i actually never used it.
    functions.php also has a few functions ending with };
    Basti, Sep 21, 2013 IP
  5. PoPSiCLe

    PoPSiCLe Well-Known Member

    Messages:
    1,219
    Likes Received:
    109
    Best Answers:
    51
    Trophy Points:
    160
    #5
    And... I found my problem. In the coreclass.php, the Config::write('db.password','') <- it's empty. I shouldn't be empty, but it's a layover from an earlier build. Replaced the empty '' with $dbpassword, and everything works as it's supposed to.
    PoPSiCLe, Sep 21, 2013 IP
  6. PoPSiCLe

    PoPSiCLe Well-Known Member

    Messages:
    1,219
    Likes Received:
    109
    Best Answers:
    51
    Trophy Points:
    160
    #6
    ; after a curly bracket is perfectly legal, and prevents for instance else {} constructs etc. working - ie. it just ends the curly.
    PoPSiCLe, Sep 21, 2013 IP
  7. samyak

    samyak Active Member

    Messages:
    270
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    88
    #7
    What FTp client are you using to upload your files to the server? May be the files haven't been uploaded properly. Try zipping all your files and uploading to the server and then unzipping them there.
    samyak, Sep 21, 2013 IP
  8. Basti

    Basti Active Member

    Messages:
    627
    Likes Received:
    6
    Best Answers:
    3
    Trophy Points:
    90
    #8
    Ah i see, didnt knew that
    Basti, Sep 21, 2013 IP
  9. 3dwarrior

    3dwarrior Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #9
    most often it happens due to your database tables misconfiguration, because in your database every url is set to your localhost address for example localhost/XXXX for the links, what you need to do is, search for the localhost/XXXX addresses in your exported database using any code editor software and replace it with your real web address, for example find localhost/XXXX and replace it with www.mydomain.com i hope this way it will work.

    let me know if didnt work!!

    good luck :)
    3dwarrior, Sep 21, 2013 IP
  10. PoPSiCLe

    PoPSiCLe Well-Known Member

    Messages:
    1,219
    Likes Received:
    109
    Best Answers:
    51
    Trophy Points:
    160
    #10
    Already found the error, as pointed out earlier. Thanks for the suggestion, but storing stuff like dynamic links, and using local host in the db, would make me cut myself with something blunt and painful :)
    PoPSiCLe, Sep 21, 2013 IP
  11. deathshadow

    deathshadow Prominent Member

    Messages:
    5,980
    Likes Received:
    826
    Best Answers:
    144
    Trophy Points:
    395
    #11
    Generally speaking you've got some sloppy PHP there -- the error most likely caused by a incomplete string or array somewhere. The constant opening and closing of PHP for NOTHING, outdated method of include (that will stop working sometime around PHP 6), Bizzaroland brute forcing of session clearing, using of header/exit instead of include, multiple echo statements for no fathomable reason...
    Even the broken/goofy indentation methodology is problematic and just begging for SOMETHING not to be closed right... and that's without even mentioning the HTML 5 BS and goofy illegible slow loading google webfont)

    That entire session thing at the top is just gibberish, for the life of me I can't figure out what you're trying to accomplish with that mess. Some more tips: if every condition is doing the same thing -- including 'else', do it BEFORE the condition. Likewise if every element inside a parent is getting the same class, don't put a class on it and instead inherit off the parent, and if a element already exists, don't waste time making another one.

    Your index.php for example I'd gut down to :

    Code (Text):
    1. ?php
    2.  
    3. $inactive = 600; // set timeout period in seconds
    4.  
    5. session_start();
    6. session_regenerate_id(
    7.     isset($_SESSION['expires']) &&
    8.     (time() > $_SESSION['expires'])
    9. );
    10. $SESSION['expires'] = time() + inactive;
    11.  
    12. include('config.php');
    13. include('functions.php');
    14.  
    15. echo '<!DOCTYPE html>
    16. <html   lang="no"><head>
    17.  
    18. <meta
    19.     name="viewport"
    20.     content="width=device-width; initial-scale=1.0"
    21. >
    22.  
    23. <link
    24.     type="text/css"
    25.     rel="stylesheet"
    26.     href="', $baseurl, $csspath, 'personaldatabase.css"
    27.     media="screen,projection,tv"
    28. >
    29.  
    30. <link
    31.     type="text/css"
    32.     rel="stylesheet"
    33.     href="http://fonts.googleapis.com/css?family=Cuprum&amp;subset=latin"
    34.     media="screen,projection,tv"
    35. >';
    36.  
    37. loadFiles('js', $scriptpath);
    38.  
    39. echo '
    40. </head><body>
    41.  
    42.     <header>
    43.  
    44.         <h1>Personaldatabase</h1>';
    45.  
    46. if ($isloggedin) echo '
    47.         <p>
    48.             Du er logget inn som: <strong>',$fullname,'</strong>
    49.             med følgende tilgangsnivå: <b', (
    50.                 $activeuser == 0 ? ' class="inactive"' : ''
    51.             ), '>', $userrole_name, '</b>
    52.             <span>', $version, '</span>
    53.         </p>';
    54.  
    55. echo ' 
    56.     </header>
    57.        
    58.     <nav id="menu">';
    59.    
    60. if ($isloggedin) {
    61.     display_menu($userrole,$usergroup);
    62. } else echo '
    63.         <p>
    64.             Dette er Kvarterets personaldatabase
    65.         </p><p>
    66.             Her kan du logge inn med din registrerte epostadresse og passord, og få tilgang til personaldatabasen - tilgangen begrenses etter hvilken rolle du har i systemet - er du kun bruker får du kun tilgang til å se informasjon
    67.         </p>';
    68.        
    69. $display = new PageView();
    70.  
    71. echo '
    72.     </nav>
    73.  
    74.     <section id="content">
    75.         ',(isLoggedIn ? $display->getPage() : (
    76.             is_dir('setup') ? $display->runSetup() : $display->getLogin()
    77.         )),'
    78.     </section>
    79.        
    80.     <footer>
    81.         ',($isloggedin ? $display->getLogin() : ''),'
    82.     </footer>
    83.    
    84. </body></html>';
    85.  
    86. ?>
    Throwing half a K of code in the trash. (though I'd also axe the HTML 5 garbage, and move the core 'template' type stuff into an include).

    From what I'm seeing you are also building a massive class on every pageload that you may or may not be using every piece of -- that's usually not a great idea performance-wise for php as dead code still has to run through the parser on a bytecode cache fail. It's why the 'one massive class for EVERYTHING' approach to development gives objects a bad name. ... and part of why I consider MVC on PHP to be completely broken idiotic bloat
    deathshadow, Sep 21, 2013 IP
    ryan_uk likes this.
  12. PoPSiCLe

    PoPSiCLe Well-Known Member

    Messages:
    1,219
    Likes Received:
    109
    Best Answers:
    51
    Trophy Points:
    160
    #12
    Except for the fact that you're unbelievably rude, your code is also a mess, and even though you do have some points, I'd prefer the following: not using deprecated elements like <b> in my code, not mixing html with php directly, since I prefer to have them separate if possible. Echo-statements breaks most colorcoding and makes reading the code harder.

    The session-"mess" you're talking about at the top logs the user out after a period of 10 minutes - should be pretty obvious? It might be vittled down to fewer lines, but it does the job it's supposed to do.

    The fact that you don't even take the time reading the content of the thread you're answering, where it's pointed out by me twice what the problem was, and it was not with the code itself - it was a missing $variable, or rather, an empty $variable causing the database-connection to fault, tells me you're more interested in providing a non-working (yes, I tested the code you provided, and found 4 errors in your cleaned code, which made it not work) solution, rather than helping.

    I'm not sure what you mean by "HTML5 garbage", but I'm assuming you mean things like <header>, <section> etc.

    A couple of things I did change - for instance the repeating of the $display = new PageView(); code, which of course was bloat, got rid of the exit, which wasn't needed, and other small fixes. Before I added comments to my index.php, it was 2,08 KB, compared to your file which was 1,96KB. Lots of overhead, indeed...
    PoPSiCLe, Sep 22, 2013 IP
  13. deathshadow

    deathshadow Prominent Member

    Messages:
    5,980
    Likes Received:
    826
    Best Answers:
    144
    Trophy Points:
    395
    #13
    If I'm blunt, it's because I'm trying to be honest. GOD FORBID.

    Felt the same about yours with the willy-nilly nonsensical indenting, convoluted page logic, and opening/closing PHP when there's conditionals inside it.

    ... and you might want to learn a bit more about HTML and semantics before believing LIES like that one. B and I were NEVER deprecated in ANY version of the specification. Just because something is a book title, company name, or would be bold or italic in processional writing, does NOT mean you are citing it, giving it emphasis, or giving it 'more emphasis'. That's an outright lie akin to the pageloads are evil crap, tables should never be used crap, or all the other ignorant misinformation that's floating around the pond.

    Whereas I find the illegible acid trip of color highlighting to cause more problems than it solves, time and time again making real errors invisible... much less the entire concept of the PHP tags resulting in annoying hard to read code - as evidenced by the train wreck with complete impossible to follow indentation your IF statements created inside them. I had my way, <?php, <?= and ?> would be stricken from the PHP specification entirely.

    Reformatting it so it ALMOST made sense was a start and I was able to eventually guess -- but it was far, FAR more complicated than need be for something so simple. The goofy header refresh for nothing in particular was some serious whiskey-tango-foxrot.

    I did read it, I just happened to be more interested in what led to the problem than the problem itself.

    Typos, what I get for typing it into the forums stupid editor -- which took 1.56k of code and blew it up to 2k for some reason. (stupid malfing tab conversion).

    HTML 5 on the whole is stupid garbage, those tags in particular being pointless bloat or redundant/pointless allegedly semantic nonsense. The only really useful parts of 'html 5' aren't even HTML in reality, with the entire mess of idiocy being carefully crafted to satiate the wants and desires of the idiots who until a couple years ago were still sleazing out HTML 3.2 with 4 tranny atop it. Now they get to sleaze out the same broken, pointless garbage methodology with 5 lip service around it, for zero real world improvement. I cannot fathom how anyone who actually embraced semantics and understood the point of STRICT, separation of presentation from content, or the dozen other improvements of the past decade and a half would choose to use HTML 5 for ANYTHING.
    deathshadow, Sep 22, 2013 IP
    ryan_uk likes this.