CMS, login

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gintare
    New Member
    • Mar 2007
    • 103

    CMS, login

    I am looking through the book:

    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. If i check cms2/ww.admin/index.php it does not contain the form, captcha and submit button, neither none of included files. The question is how this website works?

    {
    By the way, it does not work, because it complains that password is wrong, although it is correct.
    I go to http://localhost/cms2/ww.admin

    input username, password and captcha.

    I am redirected to: http://localhost/cms2/ww.admin/index...sg=loginfailed

    and javascript message pops-it: login incorrect. if you've forgotten your password, please use the Forgotten Password form.

    }

    The content of files is below. The form file and many other captcha and login related files exists in this CMS. But they, as i wrote are not included in cms2/ww.admin/index.php.

    I feel i miss some powerfull programming concept, when forms are included and files are loaded, although it is not described in script.

    Could you please look through the files below and point-out at which place form and captcha is included?

    apache2\htdocs\ cms2\ww.admin\i ndex.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" .


    I visit: "http://localhost/cms2/ww.admin/"
    This loads
    apache2\htdocs\ cms2\ww.admin\i ndex.php
    Code:
    <?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"
    Code:
    <?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"
    Code:
    <?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"
    Code:
    <?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());
  • gintare
    New Member
    • Mar 2007
    • 103

    #2
    I am sorry, seems i was too tired to notice text. The reply is
    that there is a line in the last file "cms2\ww.admin\ admin_libs.php" which loads form and captcha:
    Code:
    require SCRIPTBASE.'ww.admin/login/login.php';

    Comment

    Working...