Kirjautuminen

Haku

Tehtävät

Keskustelu: Nettisivujen teko: PHP/MYSQL: GetSimple Plugin Creation (require-login name of the plugin)

samip537 [29.12.2013 03:59:57]

#

Terveppä terve!

Siis tarkoitus olisi tämä saada tehtyä Get Simple ohjelmistolle.

http://get-simple.info/wiki/plugins:creation

Voisiko joku siis olla ystävällinen ja auttaa tässä koska itse ne tiedä miten tuo pitäisi tehdä?

Kaikki tarvittavat tiedostot lähdekoodeineen alla.

Yritän siis työstää pluginia Get Simple ohjelmistolle, mutta siitä ei tunne oikein tulevan mitään.

Onko jollakin tietoa miten tämä pitäisi tehdä kuin esimerkki on tälläinen?

Esimerkki:

<?php
/*
Plugin Name: Hello World
Description: Echos "Hello World" in footer of theme
Version: 1.0
Author: Chris Cagle
Author URI: http://www.cagintranet.com/
*/

# get correct id for plugin
$thisfile=basename(__FILE__, ".php");

# register plugin
register_plugin(
	$thisfile, //Plugin id
	'Hello World', 	//Plugin name
	'1.0', 		//Plugin version
	'Chris Cagle',  //Plugin author
	'http://www.cagintranet.com/', //author website
	'Finds email addresses in content and components and "hides" them', //Plugin description
	'theme', //page type - on which admin tab to display
	'hello_world_show'  //main function (administration)
);

# activate filter
add_action('theme-footer','hello_world');

# add a link in the admin tab 'theme'
add_action('theme-sidebar','createSideMenu',array($thisfile,'Hello World description'));

# functions
function hello_world() {
	echo '<p>Hello World</p>';
}

function hello_world_show() {
	echo '<p>I like to echo "Hello World" in the footers of all themes.</p>';
}
?>

auth.php:

<?php
        //Start session
        session_start();

        //Check whether the session variable SESS_MEMBER_ID is present or not
        if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) {
                header("location: access-denied.php");
                exit();
        }
?>

config.php:

<?php
    define('DB_HOST', 'localhost');
    define('DB_USER', 'phplogin_db');
    define('DB_PASSWORD', '********************');
    define('DB_DATABASE', 'phplogin');
?>

index.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login Form</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<header>
     <center><p><b>You need to log in before u can access this page!<b></p></center>
<p>&nbsp;</p>
<form id="loginForm" name="loginForm" method="post" action="login-exec.php">
  <table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
    <tr>
      <td width="112"><b>Login</b></td>
      <td width="188"><input name="login" type="text" class="textfield" id="login" /></td>
    </tr>
    <tr>
      <td><b>Password</b></td>
      <td><input name="password" type="password" class="textfield" id="password" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="Submit" value="Login" /></td>
    </tr>
  </table>
</form>
</body>
</html>

jump.php:

<?php
$url = $_POST["url"];
header("Location: $url");
?>

logging.php:

<?php

$file = 'log/log.txt';

$ip = get_ip();
$host = gethostbyaddr($ip);
$date = date('Y-m-d H:i:s');
$agent = $_SERVER['HTTP_USER_AGENT'];

$row = "{$ip}, {$host}, {$agent}, {$date}\n";

file_put_contents($file, $row, FILE_APPEND);

function get_ip() {
    if (isset($_SERVER['HTTP_CLIENT_IP'])) {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else {
        $ip = $_SERVER['REMOTE_ADDR'];
    }

    return $ip;
}

login-exec.php:

<?php
        //Start session
        session_start();

        //Include database connection details
        require_once('config.php');

        //Array to store validation errors
        $errmsg_arr = array();

        //Validation error flag
        $errflag = false;

        //Connect to mysql server
        $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
        if(!$link) {
                die('Failed to connect to server: ' . mysql_error());
        }

        //Select database
        $db = mysql_select_db(DB_DATABASE);
        if(!$db) {
                die("Unable to select database");
        }

        //Function to sanitize values received from the form. Prevents SQL injection
        function clean($str) {
                $str = @trim($str);
                if(get_magic_quotes_gpc()) {
                        $str = stripslashes($str);
                }
                return mysql_real_escape_string($str);
        }

        //Sanitize the POST values
        $login = clean($_POST['login']);
        $password = clean($_POST['password']);

        //Input Validations
        if($login == '') {
                $errmsg_arr[] = 'Login ID missing';
                $errflag = true;
        }
        if($password == '') {
                $errmsg_arr[] = 'Password missing';
                $errflag = true;
        }

        //If there are input validations, redirect back to the login form
        if($errflag) {
                $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
                session_write_close();
                header("location: login-form.php");
                exit();
        }

        //Create query
        $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'";
        $result=mysql_query($qry);

        //Check whether the query was successful or not
        if($result) {
                if(mysql_num_rows($result) == 1) {
                        //Login Successful
                        session_regenerate_id();
                        $member = mysql_fetch_assoc($result);
                        $_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
                        $_SESSION['SESS_FIRST_NAME'] = $member['firstname'];
                        $_SESSION['SESS_LAST_NAME'] = $member['lastname'];
                        session_write_close();
                        header("location: member-index.php");
                        exit();
                }else {
                        //Login failed
                        header("location: login-failed.php");
                        exit();
                }
        }else {
                die("Query failed");
        }
?>

login-failed.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login Failed</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Login Failed </h1>
<p align="center">&nbsp;</p>
<h4 align="center" class="err">Login Failed!<br />
  Please check your username and password</h4>
</body>
</html>

loginmodule.css:

body {
        font: 11px Verdana, Arial, Helvetica, sans-serif;
        color: #666666;
        margin: 0px;
        padding: 20px 10px 0px;
}
.textfield {
        font-size: 11px;
        color: #333333;
        background: #F7F7F7;
        border: 1px solid #CCCCCC;
        padding-left: 1px;
}
h1 {
        color: #99CC00;
        margin: 0px 0px 5px;
        padding: 0px 0px 3px;
        font: bold 18px Verdana, Arial, Helvetica, sans-serif;
        border-bottom: 1px dashed #E6E8ED;
}
a {
        color: #2D3954;
        font-size: 11px;
}
a:hover {
        color: #99CC00;
}
.err {
        color: #FF9900;
}
th {
        font-weight: bold;
        text-align: left;
}

logout.php:

<?php
        //Start session
        session_start();

        //Unset the variables stored in session
        unset($_SESSION['SESS_MEMBER_ID']);
        unset($_SESSION['SESS_FIRST_NAME']);
        unset($_SESSION['SESS_LAST_NAME']);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Logged Out</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Logout </h1>
<p align="center">&nbsp;</p>
<h4 align="center" class="err">You have been logged out.</h4>
<p align="center">Click here to <a href="index.php">Login</a></p>
</body>
</html>

Mysql-data.sql:

#
# Table structure for table 'members'
#

CREATE TABLE `members` (
  `member_id` int(11) unsigned NOT NULL auto_increment,
  `firstname` varchar(100) default NULL,
  `lastname` varchar(100) default NULL,
  `login` varchar(100) NOT NULL default '',
  `passwd` varchar(32) NOT NULL default '',
  PRIMARY KEY  (`member_id`)
) ENGINE=MyISAM;



#
# Dumping data for table 'members'
#

INSERT INTO `members` (`member_id`, `firstname`, `lastname`, `login`, `passwd`) VALUES("1", "Jatinder", "Thind", "phpsense", "ba018360fc26e0cc2e929b8e071f052d");

member-index.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Member Index</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Welcome!</h1>
<a href="member-profile.php">My profile</a> | <a href="logout.php">Logout</a>
<p>This is a password protected area only accessible to members. </p>
<p><b>Note: </b> access to this page will be recorded!</p>
</body>
</html>
<?php include 'logging.php'; ?>

member-profile.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>My Profile</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>My Profile </h1>
<a href="member-index.php">Home</a> | <a href="logout.php">Logout</a>
<p>Jump to another page:</p>
<form action="jump.php" method="post">
<select name=url>
<option value="http://saakuttinen.co.cc/abyss/htdocs/testing-php/PHP-Login/logout.php">Log out</option>
</select>
<input type="submit" value="Go">
</form>
</body>
</html>

register-exec.php:

<?php
        //Start session
        session_start();

        //Include database connection details
        require_once('config.php');

        //Array to store validation errors
        $errmsg_arr = array();

        //Validation error flag
        $errflag = false;

        //Connect to mysql server
        $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
        if(!$link) {
                die('Failed to connect to server: ' . mysql_error());
        }

        //Select database
        $db = mysql_select_db(DB_DATABASE);
        if(!$db) {
                die("Unable to select database");
        }

        //Function to sanitize values received from the form. Prevents SQL injection
        function clean($str) {
                $str = @trim($str);
                if(get_magic_quotes_gpc()) {
                        $str = stripslashes($str);
                }
                return mysql_real_escape_string($str);
        }

        //Sanitize the POST values
        $fname = clean($_POST['fname']);
        $lname = clean($_POST['lname']);
        $login = clean($_POST['login']);
        $password = clean($_POST['password']);
        $cpassword = clean($_POST['cpassword']);

        //Input Validations
        if($fname == '') {
                $errmsg_arr[] = 'First name missing';
                $errflag = true;
        }
        if($lname == '') {
                $errmsg_arr[] = 'Last name missing';
                $errflag = true;
        }
        if($login == '') {
                $errmsg_arr[] = 'Login ID missing';
                $errflag = true;
        }
        if($password == '') {
                $errmsg_arr[] = 'Password missing';
                $errflag = true;
        }
        if($cpassword == '') {
                $errmsg_arr[] = 'Confirm password missing';
                $errflag = true;
        }
        if( strcmp($password, $cpassword) != 0 ) {
                $errmsg_arr[] = 'Passwords do not match';
                $errflag = true;
        }

        //Check for duplicate login ID
        if($login != '') {
                $qry = "SELECT * FROM members WHERE login='$login'";
                $result = mysql_query($qry);
                if($result) {
                        if(mysql_num_rows($result) > 0) {
                                $errmsg_arr[] = 'Login ID already in use';
                                $errflag = true;
                        }
                        @mysql_free_result($result);
                }
                else {
                        die("Query failed");
                }
        }

        //If there are input validations, redirect back to the registration form
        if($errflag) {
                $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
                session_write_close();
                header("location: register-form.php");
                exit();
        }

        //Create INSERT query
        $qry = "INSERT INTO members(firstname, lastname, login, passwd) VALUES('$fname','$lname','$login','".md5($_POST['password'])."')";
        $result = @mysql_query($qry);

        //Check whether the query was successful or not
        if($result) {
                header("location: register-success.php");
                exit();
        }else {
                die("Query failed");
        }
?>

register-form.php:

<?php
        session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login Form</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
        if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) {
                echo '<ul class="err">';
                foreach($_SESSION['ERRMSG_ARR'] as $msg) {
                        echo '<li>',$msg,'</li>';
                }
                echo '</ul>';
                unset($_SESSION['ERRMSG_ARR']);
        }
?>
<form id="loginForm" name="loginForm" method="post" action="register-exec.php">
  <table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
    <tr>
      <th>First Name </th>
      <td><input name="fname" type="text" class="textfield" id="fname" /></td>
    </tr>
    <tr>
      <th>Last Name </th>
      <td><input name="lname" type="text" class="textfield" id="lname" /></td>
    </tr>
    <tr>
      <th width="124">Login</th>
      <td width="168"><input name="login" type="text" class="textfield" id="login" /></td>
    </tr>
    <tr>
      <th>Password</th>
      <td><input name="password" type="password" class="textfield" id="password" /></td>
    </tr>
    <tr>
      <th>Confirm Password </th>
      <td><input name="cpassword" type="password" class="textfield" id="cpassword" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="Submit" value="Register" /></td>
    </tr>
  </table>
</form>
</body>
</html>

register-success.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Registration Successful</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Registration Successful</h1>
<p><a href="login-form.php">Click here</a> to login to your account.</p>
</body>
</html>

access-denied.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Access Denied</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Access Denied </h1>
<p align="center">&nbsp;</p>
<h4 align="center" class="err">Access Denied!<br />
  You do not have access to this resource.</h4>
</body>
</html>

Vastaus

Aihe on jo aika vanha, joten et voi enää vastata siihen.

Tietoa sivustosta