Monday, January 27, 2014

PHP | User System - login & register


index.php


<?php
require 'core.inc.php';
require 'connect.inc.php';

if (loggedin()) {
    $firstname = getuserfield('firstname');
    $surname = getuserfield('surname');

    echo 'You\'re logged in, '.$firstname.' '.$surname.' ';
    echo '<a href="logout.php">Logout</a>';
} else {
    include 'loginform.inc.php';
}


?>

connect.inc.php


<?php

$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_pass = '';

$mysql_db = 'a_database';

if (!mysql_connect($mysql_host, $mysql_user, $mysql_pass) || !mysql_select_db($mysql_db)) {
    die(mysql_error());
}

?>

core.inc.php


<?php
ob_start();
session_start();

$current_file = $_SERVER['SCRIPT_NAME'];
if (isset($_SERVER['HTTP_REFERER'])&&!empty($_SERVER['HTTP_REFERER'])) {
    $http_referer = $_SERVER['HTTP_REFERER'];
}

function loggedin(){
    if (isset($_SESSION['user_id']) && !empty($_SESSION['user_id'])) {
        return true;
    } else {
        return false;
    }   
}

function getuserfield($field){
    $query = "SELECT $field FROM users WHERE id = '".$_SESSION['user_id']."'";
    if ($query_run = mysql_query($query)) {
        if ($query_result = mysql_result($query_run, 0, $field)) {
            return $query_result;
        }
    }
}

?>

loginform.inc.php


<?php

if (isset($_POST['username']) && isset($_POST['password'])) {
    $username = $_POST['username'];
    $password = $_POST['password'];

    $password_hash = md5($password);

    if (!empty($username) && !empty($password)) {
       
        $query = "SELECT id FROM users WHERE username = '".mysql_real_escape_string($username)."' AND password = '".mysql_real_escape_string($password_hash)."'";
        if ($query_run = mysql_query($query)) {
            $query_num_rows = mysql_num_rows($query_run);
            if ($query_num_rows==0) {
                echo "Invalid username/password combination.";
            } else if ($query_num_rows==1) {
                $user_id = mysql_result($query_run, 0, 'id');
                $_SESSION['user_id'] = $user_id;
                header('Location: index.php');
            }
           
        }

    } else {
        echo "You must supply username and password.";
    }
   
}

?>
<form action="<?php echo $current_file; ?>" method="POST">
    Username: <input type="text" name="username" value="<?php if (isset($username)) { echo $username; } ?>">
    Password: <input type="password" name="password">
    <input type="submit" value="Login">
</form>

logout.php


<?php
require 'core.inc.php';
session_destroy();
header('Location: '.$http_referer);
?>

register.php


<?php
require 'core.inc.php';
require 'connect.inc.php';

if (!loggedin()) {
    if (isset($_POST['username'])&&isset($_POST['password'])&&isset($_POST['password_again'])&&isset($_POST['firstname'])&&isset($_POST['surname'])) {
        $username = $_POST['username'];

        $password = $_POST['password'];
        $password_again = $_POST['password_again'];
        $password_hash = md5($password);

        $firstname = $_POST['firstname'];
        $surname = $_POST['surname'];
        if (!empty($username)&&!empty($password)&&!empty($password_again)&&!empty($firstname)&&!empty($surname)) {
            if ($password!=$password_again) {
                echo 'Passwords do not match.';
            } else {
                $query = "SELECT username FROM users WHERE username = '".mysql_real_escape_string($username)."'";
                $query_run = mysql_query($query);

                if (mysql_num_rows($query_run)==1) {
                    echo $username.' is already exists.';
                } else {
                    $query = "INSERT INTO users VALUES ('', '".mysql_real_escape_string($username)."', '".mysql_real_escape_string($password_hash)."', '".mysql_real_escape_string($firstname)."', '".mysql_real_escape_string($surname)."')";
                    if ($query_run = mysql_query($query)) {
                        header('Location: register_success.php');
                    } else {
                        echo 'Sorry, we couldn\'t register you at this time. Try again later.';
                    }
                   
                }
               
            }
           
        } else {
            echo 'All fields are required.';
        }
       
    }
?>
<form action="register.php" method="POST">
    <table>
        <tr>
            <td>Username:</td>
            <td><input type="text" name="username" maxlength="30" value="<?php if (isset($username)) { echo $username; } ?>"></td>
        </tr>
        <tr>
            <td>Password:</td>
            <td><input type="password" name="password"></td>
        </tr>
        <tr>
            <td>Pass again:</td>
            <td><input type="password" name="password_again"></td>
        </tr>
        <tr>
            <td>Firstname:</td>
            <td><input type="text" name="firstname" maxlength="40" value="<?php if (isset($firstname)) { echo $firstname; } ?>"></td>
        </tr>
        <tr>
            <td>Surname:</td>
            <td><input type="text" name="surname" maxlength="40" value="<?php if (isset($surname)) { echo $surname; } ?>"></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td><input type="submit" value="Register"></td>
        </tr>
    </table>
</form>
<?php
} else if (loggedin()) {
    echo 'You\'re already registered and logged in.';
}


?>


Sunday, January 26, 2014

Notepad++ for Windows


Notepad++ is a free (as in "free speech" and also as in "free beer") source code editor and Notepad replacement that supports several languages. Running in the MS Windows environment, its use is governed by GPL License.
Based on the powerful editing component Scintilla, Notepad++ is written in C++ and uses pure Win32 API and STL which ensures a higher execution speed and smaller program size. By optimizing as many routines as possible without losing user friendliness, Notepad++ is trying to reduce the world carbon dioxide emissions. When using less CPU power, the PC can throttle down and reduce power consumption, resulting in a greener environment.
Screenshot

I hope you enjoy Notepad++ as much as I enjoy coding it.

برنامج notepad++ هو برنامج رائع في تطوير وتصميم المواقع لمستخدمي الويندوز وبه العديد من المميزات التي تساعد المطور في كتابة برامجه على أفضل وجه وهو برنامج مجاني مفتوح المصدر .

TextMate for Mac


TextMate brings Apple's approach to operating systems into the world of text editors. By bridging UNIX underpinnings and GUI, TextMate cherry-picks the best of both worlds to the benefit of expert scripters and novice users alike.
Project Window
Whether you are a programmer or a designer, the production of code and markup is hard work. Without an editor dedicated to the task, it is also often cumbersome, overwhelming, and repetitive. Especially when you are dealing with a lot of files at once — like most projects do. TextMate puts you back in control, reduces the mental overhead, and turns manual work into something the computer does.
Fonts And Colors
Created by a closet UNIX geek who was lured to the Mac platform by its ease of use and elegance, TextMate has been referred to as the culmination of Emacs and OS X and has resulted in countless requests for both a Windows and Linux port, but TextMate remains exclusive for the Mac, and that is how we like it!
TextMate is not an IDE but by using its powerful snippets, macros, and unique scoping system, it can often provide features that even a language specific IDE lacks. It has enough project management features to keep most users happy, but is otherwise kept lightweight with a clean and minimalistic GUI.

Command Editor 

TextMate من البرامج المميزة جداً والمعروفة من قبل مستخدمين الماك فهو برنامج رائع في البرمجة وتطوير المواقع وكتابة الأكواد بطريقة سهلة ومميزة ومنظمة يتميز بوجود compiler بداخله لمعظم لغات البرمجة مع صغر حجمه وتقبله للأنظمة القديمة ويمكن من عمل مشاريع منظمة مع العلم أنه مخصص للـ mac os x فقط


Saturday, January 25, 2014


Developer X Tricks


html : index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>popup window demo</title>
    <!-- Copyrights Ahmed Al Ansaary -->
    <link rel="stylesheet" type="text/css" href="popup.css">
    <script type="text/javascript" src="popup.js"></script>
</head>
<body>
    <div id="popup">
        <div id="popup_header">
            <div class="popup_header_title">popup title</div>
            <div class="popup_header_btn" onClick="popup('close');">x</div>
            <div class="popup_header_btn" onClick="popup('resize');">+</div>
            <div class="popup_header_btn" onClick="popup('minimize');">-</div>
        </div>
        <div id="popup_content">this is the content of this popup...</div>
    </div>
    <button onClick="popup('show');">show popup window</button>
</body>
</html>

css : popup.css


/*Copyrights Ahmed Al Ansaary*/
*{
    margin: 0px;
    padding: 0px;
}
#popup{
    width: 0px;
    height: 0px;
    position: fixed;
    left: 50%;
    top: 50%;
    margin-left: -200px;
    margin-top: -200px;
    border: 0;
    border-radius: 5px;
    box-shadow: 0px 0px 20px #666;
    overflow: hidden;
    transition: all .5s;
}
#popup_header{
    position: absolute;
    width: 100%;
    height: 25px;
    background-color: #666;
    top: 0px;
    z-index: 6;
    overflow: hidden;
    cursor: default;
}
.popup_header_btn{
    width: 20px;
    height: 20px;
    margin: 2.5px;
    float: right;
    background-color: #444;
    color: #fff;
    text-align: center;
    border: 0;
    border-radius: 5px;
    cursor: default;
    z-index: 7;
    transition: all .3s;
}
.popup_header_btn:hover{
    background-color: #555;
}
.popup_header_title{
    margin: 2.5px;
    margin-left: 5px;
    float: left;
    color: #fff;
    text-shadow: 1px 1px 5px #333;
}
#popup_content{
    position: absolute;
    width: 100%;
    height: 100%;
    padding-top: 25px;
    margin: 5px;
    z-index: 5;
}

javascript : popup.js


/* Copyrights Ahmed Al Ansaary */
function popup (x) {
    var popup = document.getElementById('popup');
    switch(x){
        case "show":
            popup.style.width = "400px";
            popup.style.height = "400px";   
            break;
        case "minimize":
            popup.style.width = "200px";
            popup.style.height = "25px";   
            break;
        case "resize":
            if (popup.style.width == "100%") {
                popup.style.width = "400px";
                popup.style.height = "400px";
                popup.style.top = "50%";
                popup.style.left = "50%";
                popup.style.marginLeft = "-200px";
                popup.style.marginTop = "-200px";   
                break;
            } else{
                popup.style.width = "100%";
                popup.style.height = "100%";
                popup.style.top = "0px";
                popup.style.left = "0px";
                popup.style.marginLeft = "0px";
                popup.style.marginTop = "0px";
                break;
            }
        case "close":
            popup.style.width = "0px";
            popup.style.height = "0px";   
            break;
    }
   
}

Friday, January 24, 2014




دي شوية إضافات للفوتوشوب ناس كتير طلبتها مني , وأنا آسف جدا على التأخير , وهانزل شرح تركيب الإضافات , أنا اللي مأخرني اليومين دول اني بأفكر أخلي الشرح أونلاين مش أوفلاين ان شاء الله هاكتبه بلغة HTML5 وهيكون تفاعلي برضو , وإن شاء الله هايعجبكو جداً
http://www.mediafire.com/?6bk0rf368i6a8xe
http://www.mediafire.com/?97sk3cva6cjmp5f
http://www.mediafire.com/?c0z8cry7p9cedgv
http://www.mediafire.com/?tyc59cgswxkm3mi
http://www.mediafire.com/?cjs3l761tnn61rm
http://www.mediafire.com/?it7w872ass28lis




الدرس الثاني : التعامل مع الملفات .
http://www.mediafire.com/?ppeac9dzh2nmopa
إبتداء من الدرس اللي جاي ان شاء الله هاندخل في الجد وهنبدأ برغبة الجماهير إضافة الـ Plugins
(فلترات - تدريجات - فرش - اسكوتات - خطوط -وحاجات من اللي قلبك يحبها)

كورس الفوتوشوب (تفاعلي)
الدرس الأول : التعرف على البرنامج .
http://www.mediafire.com/?r3t3vb8fe3odw26
جاري رفع نسخة الفوتوشوب المستخدمة في الشرح
أنا استخدمت نسخة قديمة شوية وعربي علشان أضمن انها تشتغل على أي امكانيات
الفروقات بينها وبين الجديد مش كتيير أوي ,, ان شاء الله هأوضحها في الشرح
أنا نفذت فكرة جديدة في الشرح انه يكون تفاعلي بمعنى ان مش أنا هاشتغل وانت هاتتفرج
لا إنت هاتشتغل بايديك وهاتتنقل من خطوة لخطوة بنفسك (يا رب الفكرة تعجبكم)
أنا نزلت الدرس الأول كتجربة لو في أي استفسارات أو اضافات أو اقتراحات أنا في الخدمة

Powered by Blogger.
Subscribe to RSS Feed Follow me on Twitter!