I am looking through the book:
https://www.packtpub.com/web-development/cms-design-using-php-and-jquery
On chapter two they give simple CMS example, but i am getting errors when loging.
Could you please explain, which part of code checks username and password i submit with the form.
I do not understand program flow.
I visit: "http://localhost/cms2/ww.admin/"
It has a form with username and password and submit button.
apache2\htdocs\cms2\ww.admin\index.php
requires "apache2\htdocs\cms2\ww.admin\header.php"
which requires "apache2\htdocs\cms2\ww.admin\admin_libs.php"
which requires "/cms2/ww.incs/basics.php" .
It is not clear at which point the submitted username and password are checked.
Most probably
Expand|Select|Wrap|Line Numbers
function __autoload($name) {
require $name . '.php';
}
somehow loads some class. But i do not understand how it is colled and how parameter $name is given to it.
I visit: "http://localhost/cms2/ww.admin/"
This loads
apache2\htdocs\cms2\ww.admin\index.php
Expand|Select|Wrap|Line Numbers
<?php
//apache2\htdocs\cms2\ww.admin\index.php
require 'header.php';
echo 'you are logged in!';
this requires "apache2\htdocs\cms2\ww.admin\header.php"
Expand|Select|Wrap|Line Numbers
<?php
//apache2\htdocs\cms2\ww.admin\header.php
header('Content-type: text/html; Charset=utf-8');
require 'admin_libs.php';
?>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js"></script>
<link rel="stylesheet" href="/ww.admin/theme/admin.css" type="text/css" />
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/themes/south-street/jquery-ui.css" type="text/css" />
</head>
<body>
<div id="header">
<div id="menu-top">
<ul>
<li><a href="/cms2/ww.admin/users.php">Users</a></li>
<li><a href="/cms2/ww.incs/logout.php?redirect=/ww.admin/">Log Out</a></li>
</ul>
</div>
</div>
<div id="wrapper">
this requires "apache2\htdocs\cms2\ww.admin\admin_libs.php"
Expand|Select|Wrap|Line Numbers
<?php
// apache2\htdocs\cms2\ww.admin\admin_libs.php
require $_SERVER['DOCUMENT_ROOT'].'/cms2/ww.incs/basics.php';
function is_admin(){
if(!isset($_SESSION['userdata']))return false;
if(
isset($_SESSION['userdata']['groups']['_administrators']) ||
isset($_SESSION['userdata']['groups']['_superadministrators'])
)return true;
if(!isset($_REQUEST['login_msg']))$_REQUEST['login_msg']='permissiondenied';
return false;
}
if(!is_admin()){
/* print_r('SCRIPTBASE'.SCRIPTBASE);
// SCRIPTBASEC:/Bitnami/wampstack-5.4.38-0/apache2/htdocs/cms2/ */
require SCRIPTBASE.'ww.admin/login/login.php';
exit;
}
This requires "/cms2/ww.incs/basics.php"
Expand|Select|Wrap|Line Numbers
<?php
// apache2\htdocs\cms2\ww.incs\basics.php
session_start();
function __autoload($name) {
require $name . '.php';
}
/* added http://php.net/manual/en/function.spl-autoload-register.php */
spl_autoload_register("__autoload");
function dbAll($query,$key='') {
$q = dbQuery($query);
$results=array();
while($r=$q->fetch(PDO::FETCH_ASSOC))$results[]=$r;
if(!$key)return $results;
$arr=array();
foreach($results as $r)$arr[$r[$key]]=$r;
return $arr;
}
function dbInit(){
if(isset($GLOBALS['db']))return $GLOBALS['db'];
global $DBVARS;
$db=new PDO('mysql:host='.$DBVARS['hostname'].';dbname='.$DBVARS['db_name'],$DBVARS['username'],$DBVARS['password']);
$db->query('SET NAMES utf8');
$db->num_queries=0;
$GLOBALS['db']=$db;
return $db;
}
function dbOne($query, $field='') {
$r = dbRow($query);
return $r[$field];
}
function dbLastInsertId() {
return dbOne('select last_insert_id() as id','id');
}
function dbQuery($query){
$db=dbInit();
$q=$db->query($query);
$db->num_queries++;
return $q;
}
function dbRow($query) {
$q = dbQuery($query);
return $q->fetch(PDO::FETCH_ASSOC);
}
define('SCRIPTBASE', $_SERVER['DOCUMENT_ROOT'] . '/cms2/');
print_r ($_SERVER['DOCUMENT_ROOT']);
require SCRIPTBASE . 'private/config.php';
if(!defined('CONFIG_FILE'))define('CONFIG_FILE',SCRIPTBASE.'private/config.php');
set_include_path(SCRIPTBASE.'ww.php_classes'.PATH_SEPARATOR.get_include_path());