links-zonder-mysql
-----------------
links.inc.php
-----------------
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/*
*
*@file: links.inc.php
*@version: 2.1 [26-02-2006]
*@auteur: Boaz den Besten
*@www: www.n3rd.nl
*@omschrijving:
* een links systeem zonder MySQL
* variabele: user een username om mee in te loggen
* variabele: pass een password om mee in te loggen
* variabele: file het bestand waar de links in opgeslagen worden.
* functie: read_csv een functie om een csv bestand in een array te zetten
* functie: addlink een link toevoegen
* functie: new_file maakt het bestand leeg
* functie: login_do inlog gegeven checken en inloggen
* functie: login_check inlog gegeven checken
*
*/
class csv{
var $user = 'username';
var $pass = 'password';
var $file = 'links.csv';
function read_csv(){
$data = array();
$file = file($this->file);
foreach($file as $key => $value){
$data[$key] = explode(';', trim($value));
}
return $data;
}
function addlink($addr, $name, $view=1){
if(!empty($addr) && !empty($name) && !strpos($addr, ';') && !strpos($name, ';') && ($view==1||$view==0)){
if(substr($addr, 0, 7) != 'http://'){
$addr = 'http://' . $addr;
}
$addr = htmlentities(trim($addr), ENT_QUOTES);
$name = htmlentities(trim($name), ENT_QUOTES);
$file = fopen($this->file, 'a');
fwrite($file, $view . ";" . substr($name, 0, 50) . ";" . substr($addr,0, 157) . "\r\n");
fclose($file);
return true;
}else{
return false;
}
}
function new_file(){
$file = fopen($this->file, 'w');
fwrite($file, '');
fclose($file);
}
function login_do($user, $pass, $rechten=1){
if($user == $this->user && $pass == $this->pass){
$_SESSION['user'] = $user;
$_SESSION['pass'] = md5($pass);
$_SESSION['rechten'] = $rechten;
$_SESSION['client_ip'] = $_SERVER['REMOTE_ADDR'];
return true;
}else{
return false;
}
}
function login_check($rechten=1){
if(!isset($_SESSION['user']) || !isset($_SESSION['pass']) || !isset($_SESSION['rechten'])){
return false;
}else{
if($_SESSION['user'] == $this->user && $_SESSION['pass'] == md5($this->pass) && $_SESSION['rechten'] >= $rechten && $_SESSION['client_ip'] == $_SERVER['REMOTE_ADDR']){
return true;
}else{
return false;
}
}
}
}
?>
/*
*
*@file: links.inc.php
*@version: 2.1 [26-02-2006]
*@auteur: Boaz den Besten
*@www: www.n3rd.nl
*@omschrijving:
* een links systeem zonder MySQL
* variabele: user een username om mee in te loggen
* variabele: pass een password om mee in te loggen
* variabele: file het bestand waar de links in opgeslagen worden.
* functie: read_csv een functie om een csv bestand in een array te zetten
* functie: addlink een link toevoegen
* functie: new_file maakt het bestand leeg
* functie: login_do inlog gegeven checken en inloggen
* functie: login_check inlog gegeven checken
*
*/
class csv{
var $user = 'username';
var $pass = 'password';
var $file = 'links.csv';
function read_csv(){
$data = array();
$file = file($this->file);
foreach($file as $key => $value){
$data[$key] = explode(';', trim($value));
}
return $data;
}
function addlink($addr, $name, $view=1){
if(!empty($addr) && !empty($name) && !strpos($addr, ';') && !strpos($name, ';') && ($view==1||$view==0)){
if(substr($addr, 0, 7) != 'http://'){
$addr = 'http://' . $addr;
}
$addr = htmlentities(trim($addr), ENT_QUOTES);
$name = htmlentities(trim($name), ENT_QUOTES);
$file = fopen($this->file, 'a');
fwrite($file, $view . ";" . substr($name, 0, 50) . ";" . substr($addr,0, 157) . "\r\n");
fclose($file);
return true;
}else{
return false;
}
}
function new_file(){
$file = fopen($this->file, 'w');
fwrite($file, '');
fclose($file);
}
function login_do($user, $pass, $rechten=1){
if($user == $this->user && $pass == $this->pass){
$_SESSION['user'] = $user;
$_SESSION['pass'] = md5($pass);
$_SESSION['rechten'] = $rechten;
$_SESSION['client_ip'] = $_SERVER['REMOTE_ADDR'];
return true;
}else{
return false;
}
}
function login_check($rechten=1){
if(!isset($_SESSION['user']) || !isset($_SESSION['pass']) || !isset($_SESSION['rechten'])){
return false;
}else{
if($_SESSION['user'] == $this->user && $_SESSION['pass'] == md5($this->pass) && $_SESSION['rechten'] >= $rechten && $_SESSION['client_ip'] == $_SERVER['REMOTE_ADDR']){
return true;
}else{
return false;
}
}
}
}
?>
-----------------
addlink.php
-----------------
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
include_once('links.inc.php');
$csv = new csv;
echo "<h1>Add a link</h1>\r\n";
if(isset($_POST['submit'])){
if($csv->addlink($_POST['addr'], $_POST['name'])){
echo "Thanks!\r\n";
}else{
echo "Your link could not be added.\r\n";
}
}else{
echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\">\r\n";
echo "<p>Link name:<br /><input name=\"name\" type=\"text\" maxlength=\"50\" /></p>\r\n";
echo "<p>Link adress:<br /><input name=\"addr\" type=\"text\" maxlength=\"150\" /></p>\r\n";
echo "<input type=\"submit\" name=\"submit\" value=\"Submit\" />\r\n";
echo "</form>\r\n";
}
echo "<br />\r\n";
echo "<a href=\"links.php\">Back</a>\r\n";
?>
include_once('links.inc.php');
$csv = new csv;
echo "<h1>Add a link</h1>\r\n";
if(isset($_POST['submit'])){
if($csv->addlink($_POST['addr'], $_POST['name'])){
echo "Thanks!\r\n";
}else{
echo "Your link could not be added.\r\n";
}
}else{
echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\">\r\n";
echo "<p>Link name:<br /><input name=\"name\" type=\"text\" maxlength=\"50\" /></p>\r\n";
echo "<p>Link adress:<br /><input name=\"addr\" type=\"text\" maxlength=\"150\" /></p>\r\n";
echo "<input type=\"submit\" name=\"submit\" value=\"Submit\" />\r\n";
echo "</form>\r\n";
}
echo "<br />\r\n";
echo "<a href=\"links.php\">Back</a>\r\n";
?>
-----------------
links.php
-----------------
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
-----------------
login.php
-----------------
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
session_start();
if((!isset($_POST['username']) || !isset($_POST['password'])) && (!isset($_SESSION['user']) || !isset($_SESSION['pass']))){
echo "<h1>Login</h1>\r\n";
echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\">\r\n";
echo "<p>Username<br /><input type=\"text\" name=\"username\" /></p>\r\n";
echo "<p>Password<br /><input type=\"password\" name=\"password\" /></p>\r\n";
echo "<input type=\"submit\" name=\"submit\" value=\"Submit\" />\r\n";
echo "</form>\r\n";
}else{
include_once('links.inc.php');
$csv = new csv;
if(isset($_SESSION['user']) && isset($_SESSION['pass']) && $csv->login_check()){
header("location: admin.php");
}else{
if($csv->login_do($_POST['username'], $_POST['password'])){
header("location: admin.php");
}else{
echo "Login failed!\r\n";
}
}
}
echo "<br />\r\n<a href=\"links.php\">Back</a>";
?>
session_start();
if((!isset($_POST['username']) || !isset($_POST['password'])) && (!isset($_SESSION['user']) || !isset($_SESSION['pass']))){
echo "<h1>Login</h1>\r\n";
echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\">\r\n";
echo "<p>Username<br /><input type=\"text\" name=\"username\" /></p>\r\n";
echo "<p>Password<br /><input type=\"password\" name=\"password\" /></p>\r\n";
echo "<input type=\"submit\" name=\"submit\" value=\"Submit\" />\r\n";
echo "</form>\r\n";
}else{
include_once('links.inc.php');
$csv = new csv;
if(isset($_SESSION['user']) && isset($_SESSION['pass']) && $csv->login_check()){
header("location: admin.php");
}else{
if($csv->login_do($_POST['username'], $_POST['password'])){
header("location: admin.php");
}else{
echo "Login failed!\r\n";
}
}
}
echo "<br />\r\n<a href=\"links.php\">Back</a>";
?>
-----------------
admin.php
-----------------
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
session_start();
include_once('links.inc.php');
$csv = new csv;
if(!$csv->login_check()){
header("Location: login.php");
}
if(isset($_POST['submit'])){
$csv->new_file();
foreach($_POST['name'] as $key => $name){
if(isset($_POST['view'][$key])){
$view = 1;
}else{
$view = 0;
}
$csv->addlink($_POST['addr'][$key], $name, $view);
}
}
if(isset($_POST['clear'])){
$csv->new_file();
}
echo "<h1>Admin</h1>\r\n";
echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\">\r\n";
$i = 0;
foreach($csv->read_csv() as $link){
echo "<input name=\"view[" . $i . "]\" type=\"checkbox\"";
if($link[0] == 1){
echo " checked=\"checked\"";
}
echo " />";
echo " <input name=\"name[" . $i . "]\" type=\"text\" value=\"" . $link[1] . "\" maxlength=\"50\" />";
echo " <input name=\"addr[" . $i . "]\" type=\"text\" value=\"" . $link[2] . "\" maxlength=\"150\" />";
echo "<br />\r\n";
$i++;
}
echo "<br />\r\n<input type=\"submit\" name=\"submit\" value=\"Submit\" /> <input type=\"submit\" name=\"clear\" value=\"Clear All\" />\r\n";
echo "</form>\r\n";
echo "<a href=\"loguit.php\">Logoff</a>\r\n";
?>
session_start();
include_once('links.inc.php');
$csv = new csv;
if(!$csv->login_check()){
header("Location: login.php");
}
if(isset($_POST['submit'])){
$csv->new_file();
foreach($_POST['name'] as $key => $name){
if(isset($_POST['view'][$key])){
$view = 1;
}else{
$view = 0;
}
$csv->addlink($_POST['addr'][$key], $name, $view);
}
}
if(isset($_POST['clear'])){
$csv->new_file();
}
echo "<h1>Admin</h1>\r\n";
echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\">\r\n";
$i = 0;
foreach($csv->read_csv() as $link){
echo "<input name=\"view[" . $i . "]\" type=\"checkbox\"";
if($link[0] == 1){
echo " checked=\"checked\"";
}
echo " />";
echo " <input name=\"name[" . $i . "]\" type=\"text\" value=\"" . $link[1] . "\" maxlength=\"50\" />";
echo " <input name=\"addr[" . $i . "]\" type=\"text\" value=\"" . $link[2] . "\" maxlength=\"150\" />";
echo "<br />\r\n";
$i++;
}
echo "<br />\r\n<input type=\"submit\" name=\"submit\" value=\"Submit\" /> <input type=\"submit\" name=\"clear\" value=\"Clear All\" />\r\n";
echo "</form>\r\n";
echo "<a href=\"loguit.php\">Logoff</a>\r\n";
?>
-----------------
loguit.php
-----------------