Jump to content

terryds

Members
  • Posts

    174
  • Joined

  • Last visited

Posts posted by terryds

  1. So, what should i do ? Make it global scoped or change the include_once with include ?

     

     

    I think that the file including connect.php is my logged.php

     

     

    <?php function isLoggedIn() { if (isset($_POST['action']) and $_POST['action'] == 'login') {if (empty($_POST['un']) || empty($_POST['pw'])) {$GLOBALS['loginError'] = "Please fill in both fields";return FALSE;}      $pw = crypt($_POST['pw'], '$2a$07$427fyb79dy4r948n80dimsillYs$l7$');      if (dbContainsUser($_POST['un'], $pw)) {     session_start();     $_SESSION['loggedIn'] = true;     $_SESSION['un'] = $_POST['un'];     $_SESSION['pw'] = $pw;     return TRUE;     }     else {     session_start();     unset($_SESSION['loggedIn']);     unset($_SESSION['un']);     unset($_SESSION['pw']);     $GLOBALS['loginError'] = "Invalid username or password";     return FALSE;     }} if (isset($_POST['action']) and $_POST['action'] == 'logout') {session_start();unset($_SESSION['loggedIn']);unset($_SESSION['un']);unset($_SESSION['pw']);header('Location: .');die();} session_start(); if (isset($_SESSION['loggedIn'])) {return dbContainsUser($_SESSION['un'], $_SESSION['pw']);}} function dbContainsUser($username, $password) {include "connect.php"; try {$sql = "SELECT COUNT(`id`) FROM `users` WHERE `username` = :un AND `password` = :pw";$s = $pdo->prepare($sql);$s->execute(array(':un' => $username,':pw' => $password ));} catch (PDOException $e) {$error = "SQL ERROR = Error searching for user";echo $error;die();} $row = $s->fetch(PDO::FETCH_ASSOC); if ($row['COUNT(`id`)'] > 0) {return TRUE;} else {return FALSE;}}
  2. See my code first

    <?php

    include(dirname(dirname(__FILE__)) . "/pathdefiner.php");
    include_once (BASEPATH . INC . "logged.php");
    if (!isLoggedIn()) {
    include ("templates/login.html.php");
    exit();
    }
    if (isset($_GET['addp'])) {
    $title = "Add post";
    $desc = "Type down what your post want to be";
    $action = "?addpost";
    $id = '';
    $titlepost = '';
    $button = 'Add post';
    $editmode = FALSE;
    include "templates/form.html.php";
    die();
    }
    if (isset($_GET['addpost'])) {
    if (empty($_POST['post']) || empty($_POST['title'])) {
    echo 'Please fill and set the post entry' . '<br>' . '<p><a href=".">Go Back</a></p>';
    die();
    }
    include_once (BASEPATH . INC . "connect.php");
    try {
    $sql = "INSERT INTO `posts` SET
    `title` = :title,
    `posttext` = :post,
    `posttime` = :time";
    $s = $pdo->prepare($sql);
    $s->execute(
    array(
    ':title' => $_POST['title'],
    ':post' => $_POST['post'],
    ':time' => time()
    )
    );
    }
    catch(PDOException $e) {
    die("Error adding post. Error: " . $e->getMessage());
    }
    header('Location: .');
    die();
    }
    include "templates/admin.html.php";
    include "templates/logout.inc.html.php";
    After executed, it generates an error that the $pdo variable is not set...
    But, if i change the include_once to include, it will work well...
    And, if i change the $pdo variable in my connect.php to a global scope, it will work well too...
    Can you tell me why this happens?
    Why if i change include_once to include, it will work ?
    Why if i set the $pdo variable to global, it will work ?
    Which's better ? Change include_once to include or set the global scope for $pdo ?
    This is my connect.php
    <?php
    require_once (dirname(__FILE__) . '/config.php');
    define("DSN", 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME);
    try
    {
    $pdo = new PDO(DSN, DB_UN, DB_PW);
    $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
    $pdo->exec('SET NAMES "utf8"');
    }
    catch (PDOException $e)
    {
    echo DB_PW . "<br>";
    die('Error: ' . $e->getMessage());
    }

     

  3. Hi, i want know how to make a quick installation CMS ....

    I mean installing the CMS without editing the code...

     

    So, when i set the host, database username,password,and name into a variable in a php file...

     

    Can you tell me how to do that ?

     

    I wonder so much how MyBB CMS can do this...

  4. Take a look at my code :

     

    access.inc.php

    <?php function isLoggedIn() { if (isset($_POST['action']) and $_POST['action'] == 'login') {if (empty($_POST['un']) || empty($_POST['pw'])) {$GLOBALS['loginError'] = "Please fill in both fields";return FALSE;}      $pw = crypt($_POST['pw'], '$2a$07$427fyb79223423423acgLosdillYs$l7$');      if (dbConstainsUser($_POST['un'], $pw)) {     session_start();     $_SESSION['loggedIn'] = true;     $_SESSION['un'] = $_POST['un'];     $_SESSION['pw'] = $pw;     return TRUE;     }     else {     session_start();     unset($_SESSION['loggedIn']);     unset($_SESSION['un']);     unset($_SESSION['pw']);     $GLOBALS['loginError'] = "Invalid username or password";     return FALSE;     }} session_start();if (isset($_SESSION['loggedIn'])) {return dbContainsUser($_SESSION['un'], $_SESSION['pw']);}} function dbContainsUser($username, $password) {include dirname(dirname(dirname(__FILE__))) . '/inc/connect.php'; try {$sql = "SELECT COUNT(`id`) FROM `users` WHERE `username` = :un AND `password` = :pw";$s = $pdo->prepare($sql);$s->execute(array(':un' => $username,':pw' => $password ));} catch (PDOException $e) {$error = "SQL ERROR = Error searching for user";echo $error;die();} $row = $s->fetch(PDO::FETCH_ASSOC); if ($row[0] > 0) {return TRUE;} else {return FALSE;}}

    And, my controller code :

     

    <?php
    include(dirname(dirname(__FILE__)) . "/pathdefiner.php");
    include_once ("inc/access.inc.php");
    if (!isLoggedIn()) {
    include ("template/login.html");
    exit();
    }
    echo "Under Construction";
    But, if i execute the controller code, it generates an error
    Notice: Undefined index: un in C:xampphtdocsterrytestadmininclogged.php on line 32
    Notice: Undefined index: pw in C:xampphtdocsterrytestadmininclogged.php on line 32
    My 32nd line is : return dbContainsUser($_SESSION['un'], $_SESSION['pw']);
    Please help me fix this error so it'll work as expected ...
  5. Sorry for my bad English skill ...

     

    I mean, in http://terryds.net63.net/ , then i inspect the elements , then i change the #page_header to 200px ...

     

    So, the #page_header height becomes 200px , but the #title doesn't automatically moved to the middle of the page header ...

     

     

    Can you tell me how to make the #title get to the middle of page header automatically even if the page header's height changes ?

  6. Look at my website : http://terryds.net63.net/

     

    The "Terry Djony's Official Website" gets stacked with the nav...

     

    But, if i apply padding : 30 px to the #title, it's no longer stacked...

     

    But, the next problem happens if i change the "Facebook" with a facebook icon....

     

    The welcome text ("Terry Djony's Official Website") gets stacked again....

     

     

    Can you tell me how to make it nice without using padding ?

     

    What i think now is to make the #title position is 20px below the nav... But, as i know, using the position method can make the text no longer centered...

     

    Any ideas so my #title gets 20px below the nav and keep its text-align ?

  7. See : http://line25.com/tutorials/how-to-create-a-pure-css-dropdown-menu first...

     

    I don't understand this section :

     

    nav ul:after { content: ""; clear: both; display: block; }

    I think that code is useless right ? What's the use of clear:both on that property ? It's useless right ?

     

    And, when i practiced that in my page... It's not working.. Can you tell me what's wrong ?

     

    my style.css

     

    body,h1 {
    margin: 0px;
    }
    body {
    background-color: #FFFFFF;
    font-family: Helvetica Neue, Helvetica, Verdana, Arial, sans-serif;
    font-size: small;
    }
    #page_header {
    background-color: #7EA4FC;
    margin : 10px 10px 0px 10px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    padding: 10px;
    }
    #title {
    text-align: center;
    }
    #page_nav {
    margin: 100px auto;
    text-align: center;
    }
    #page_nav ul ul {
    display: none;
    }
    #page_nav ul li:hover > ul {
    display: block;
    }
    #page_nav ul {
    background: #efefef;
    background: linear-gradient(top, #efefef 0%, #bbbbbb 100%);
    background: -moz-linear-gradient(top, #efefef 0%, #bbbbbb 100%);
    background: -webkit-linear-gradient(top, #efefef 0%,#bbbbbb 100%);
    box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
    padding: 0 20px;
    border-radius: 10px;
    list-style: none;
    position: relative;
    display: inline-table;
    }
    #page_nav ul:after {
    content: ""; clear: both; display: block;
    }
    #page_nav ul li {
    float: left;
    }
    #page_nav ul li:hover {
    background: #4b545f;
    background: linear-gradient(top, #4f5964 0%, #5f6975 40%);
    background: -moz-linear-gradient(top, #4f5964 0%, #5f6975 40%);
    background: -webkit-linear-gradient(top, #4f5964 0%,#5f6975 40%);
    }
    #page_nav ul li:hover a {
    color: #fff;
    }
    #page_nav ul li a {
    display: block; padding: 25px 40px;
    color: #757575; text-decoration: none;
    }
    #page_nav ul ul {
    background: #5f6975; border-radius: 0px; padding: 0;
    position: absolute; top: 100%;
    }
    #page_nav ul ul li {
    float: none;
    border-top: 1px solid #6b727c;
    border-bottom: 1px solid #575f6a; position: relative;
    }
    #page_nav ul ul li a {
    padding: 15px 40px;
    color: #fff;
    }
    #page_nav ul ul li a:hover {
    background: #4b545f;
    }
    #page_nav ul ul ul {
    position: absolute; left: 100%; top:0;

    }

     

    my html

     

    <!DOCTYPE html>

    <html lang="en">

    <head>

    <meta charset="utf-8">

    <title>Me - A Web Developer</title>

    <meta name="description" content="A web developer who has started a long journey">

    <link rel="stylesheet" type="text/css" href="content/themes/style.css">

    </head>

    <body>

    <header id="page_header">

    <h1 id="title">My Official Website</h1>

    <nav id="page_nav">

    <ul>

    <li><a href="#">Home</a></li>

    </ul>

    <ul>

    <li><a href="#">Sample Page</a></li>

    <ul>

    <li><a href="#">My Page 1</a></li>

    <li><a href="#">My Page 2</a></li>

    </ul>

    </li>

    </ul>

    </nav>

    </header>

    <section id="post">

    <article class="post">

    <header>

    <h2>This Website Is Under Construction</h2>

    <p>Posted by Terry on

    <time datetime="2010-10-01T14:39">October 1st, 2010 at 2:39PM</time>

    </p>

    </header>

    <aside>

    <p>

    "Please be patient and come back later."

    </p>

    </aside>

    <p>Please come back one week later.</p>

    <footer>

    <p>No comment</p>

    </footer>

    </article>

    </section>

    </body>

    </html>

     

     

    Can you tell me what's wrong ?

  8. // Create a value for the notice variable
    var notice = "I live in a variable!";
    $("p.foo").bind("click", { n:notice }, function(event){
    console.log(event.data.n);
    });
    Look at the function(event) ! Where does the parameter event come from ? I don't understand... Is it a special parameter ?
    Please explain me about the parameter.... And, i don't understand what { n:notice } means .... Can you tell me what's that ?
    I don't understand why the result is "I live in a variable" ?
    I'm also confused with the parameter of this function below... Are they special parameters too ?
    $("p,.foo").map(function(index, ele){
    $(this).append(" "+ele.tagName+" #"+index);
    });

     

  9. $("p:first").data("test","This is some data.");var p = $("p:first").detach();console.log("Data stored: "+p.data("test"));

     

     

    What does the "+p.data("test"))" mean ?

  10. Can you tell me how to make the google search result like this ?

     

    2wcml1f.png

     

    Is it can be done by using meta attribute ? How to do that?

     

    Sorry for posting in HTML/XHTML (because there is no SEO forum)

  11. This is the fix for yours...

     

    <?php
    session_start();
    ?>
    <!doctype html>
    <html>
    <head>
    <title>php scripting</title>
    </head>
    <body>
    <center>
    <?php if(!isset($_SESSION['mistake'])): ?>
    <form method="post" action="check.php">
    Name:<br /><input type="text" name="name" value="<?php
    if (isset($_SESSION['name'])) {
    echo $_SESSION['name'];
    } ?>" /><br />
    <input type="submit" name="submit" value="submit" />
    <?php endif; ?>
    </form></center>
    <p>If you see a blank page, it means you entered a wrong name </p>
    </body>
    </html>
    <?php
    if(isset($_POST['submit']))
    {
    $name = $_SESSION['name'] = $_POST['name'];
    }
    ?>
    And, this is for the check.php
    <?php
    /** If the mistake is when the user type 'mistake' in the form */
    if ($_POST['name'] == 'mistake') {
    session_start();
    $_SESSION['mistake'] = 1;
    }
    header('Location: session.php');
    I dont think that that's the best code but it works
    • Like 1
×
×
  • Create New...