pin-login
pin.php - Hier word het plaatje gemaakt.
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
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
<?php
session_start();
$width = (isset($_GET['width']) ? $_GET['width'] : 12);
$kleurgetal = 200;
$im = imagecreatetruecolor($width*6-1, $width*8-1);
$bg = imagecolorallocate($im, 255, 255, 255); // Achtergrondkleur
imagefill($im, 0, 0, $bg);
imagecolortransparent($im);
$getallen = range(0, 9);
shuffle($getallen);
$kleuren = array();
// Creëer al dan niet random kleuren.
$kleur = imagecolorallocate($im, 127, 157, 185);
for ($i = 0; $i <= 9; $i++)
{
$kleuren[$i] = imagecolorallocate($im, $kleurgetal+rand(-20, 20), $kleurgetal+rand(-20, 20), $kleurgetal+rand(-20, 20));
}
$x2 = 1;
$x3 = 1;
$keys = array();
for ($i = 0; $i <= 9; $i++)
{
// x en y van hokjes bepalen
if ($i == 9)
{
$x2 = 3;
$x3 = 2;
}
$y = floor($i/3);
$x = $i-$y*3;
// Vierkantjes waar cijfers in gaan.
imagefilledrectangle($im, ($x*2)*$width, ($y*2)*$width, ($x*2+2)*$width*$x2-2, ($y*2+2)*$width-2, $kleuren[$i]);
imagerectangle($im, ($x*2)*$width, ($y*2)*$width, ($x*2+2)*$width*$x2-2, ($y*2+2)*$width-2, $kleur);
// Schuine lijntjes - opleuking
for ($i2 = 0; $i2 < ($width*$x3)-1; $i2++)
{
imageline($im, (($i2*2)+1)+($x*2)*$width, ($y*2)*$width, ($x*2)*$width+1, (($i2*2)+1)+($y*2)*$width-1, $kleur);
}
// Sessie waarin staat op welke plaats welk nummer staat.
imagechar($im, 5, ($x*2+1)*$x2*$width-5, ($y*2+1)*$width-8, $getallen[$i], $kleur);
$_SESSION['keys'][$i] = $getallen[$i];
}
// Show image
header('Content-Type: image/gif');
imagegif($im);
imagedestroy($im);
?>
session_start();
$width = (isset($_GET['width']) ? $_GET['width'] : 12);
$kleurgetal = 200;
$im = imagecreatetruecolor($width*6-1, $width*8-1);
$bg = imagecolorallocate($im, 255, 255, 255); // Achtergrondkleur
imagefill($im, 0, 0, $bg);
imagecolortransparent($im);
$getallen = range(0, 9);
shuffle($getallen);
$kleuren = array();
// Creëer al dan niet random kleuren.
$kleur = imagecolorallocate($im, 127, 157, 185);
for ($i = 0; $i <= 9; $i++)
{
$kleuren[$i] = imagecolorallocate($im, $kleurgetal+rand(-20, 20), $kleurgetal+rand(-20, 20), $kleurgetal+rand(-20, 20));
}
$x2 = 1;
$x3 = 1;
$keys = array();
for ($i = 0; $i <= 9; $i++)
{
// x en y van hokjes bepalen
if ($i == 9)
{
$x2 = 3;
$x3 = 2;
}
$y = floor($i/3);
$x = $i-$y*3;
// Vierkantjes waar cijfers in gaan.
imagefilledrectangle($im, ($x*2)*$width, ($y*2)*$width, ($x*2+2)*$width*$x2-2, ($y*2+2)*$width-2, $kleuren[$i]);
imagerectangle($im, ($x*2)*$width, ($y*2)*$width, ($x*2+2)*$width*$x2-2, ($y*2+2)*$width-2, $kleur);
// Schuine lijntjes - opleuking
for ($i2 = 0; $i2 < ($width*$x3)-1; $i2++)
{
imageline($im, (($i2*2)+1)+($x*2)*$width, ($y*2)*$width, ($x*2)*$width+1, (($i2*2)+1)+($y*2)*$width-1, $kleur);
}
// Sessie waarin staat op welke plaats welk nummer staat.
imagechar($im, 5, ($x*2+1)*$x2*$width-5, ($y*2+1)*$width-8, $getallen[$i], $kleur);
$_SESSION['keys'][$i] = $getallen[$i];
}
// Show image
header('Content-Type: image/gif');
imagegif($im);
imagedestroy($im);
?>
functions.php - functie die handig is bij elke pagina waar je de PIN gebruikt. Hier kun je nog extra functies bij maken die handig zijn voor een PIN.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
// Controle welk cijfer ingedrukt is.
function pin_click ()
{
global $width;
$x = floor($_POST['pin_x']/($width*2));
$y = floor($_POST['pin_y']/($width*2));
$place = $x+$y*3;
if ($place > 9)
{
$place = 9;
}
if (isset($_SESSION['keys'][$place]))
{
$_SESSION['pin'][] = $_SESSION['keys'][$place];
}
}
?>
// Controle welk cijfer ingedrukt is.
function pin_click ()
{
global $width;
$x = floor($_POST['pin_x']/($width*2));
$y = floor($_POST['pin_y']/($width*2));
$place = $x+$y*3;
if ($place > 9)
{
$place = 9;
}
if (isset($_SESSION['keys'][$place]))
{
$_SESSION['pin'][] = $_SESSION['keys'][$place];
}
}
?>
page.php - Een vereenvoudigde pagina met PIN.
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
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
<?php
session_start();
// Als Sessie-IP niet gelijk is aan Gebruiker-IP
if (isset($_SESSION['ip']) && $_SESSION['ip'] != $_SERVER['REMOTE_ADDR'])
{
unset($_SESSION);
session_destroy();
session_start();
}
$width = 12;
include('functions.php');
// Zet sessie, als deze nog niet geset is.
if (!isset($_SESSION['ip']))
{
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
$_SESSION['pin'] = array();
}
// één of alle tekens van de PIN wissen, bij indrukken van Del of Clear.
if ($_POST['action'] == 'Clear' or $_POST['action'] == 'Del')
{
if ($_POST['action'] == 'Clear')
{
$_SESSION['pin'] = array();
}
if ($_POST['action'] == 'Del')
{
unset($_SESSION['pin'][(count($_SESSION['pin'])-1)]);
}
unset($_POST['action'], $_POST['pin_x'], $_POST['pin_y']);
}
// Controleren welk getal ingetoetst is.
if (isset($_POST['pin_x']) && isset($_POST['pin_y']))
{
pin_click();
}
$totpin = count($_SESSION['pin']);
$tekens = '';
for ($i = 0; $i < $totpin; $i++)
{
$tekens .= '*';
}
echo 'Pin: '.$tekens;
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
echo '<input type="image" name="pin" src="pin.php?width='.$width.'" alt="PIN"/>';
echo '<br/ ><input type="submit" name="action" value="Del"><input type="submit" name="action" value="Clear">';
echo '</form>';
?>
session_start();
// Als Sessie-IP niet gelijk is aan Gebruiker-IP
if (isset($_SESSION['ip']) && $_SESSION['ip'] != $_SERVER['REMOTE_ADDR'])
{
unset($_SESSION);
session_destroy();
session_start();
}
$width = 12;
include('functions.php');
// Zet sessie, als deze nog niet geset is.
if (!isset($_SESSION['ip']))
{
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
$_SESSION['pin'] = array();
}
// één of alle tekens van de PIN wissen, bij indrukken van Del of Clear.
if ($_POST['action'] == 'Clear' or $_POST['action'] == 'Del')
{
if ($_POST['action'] == 'Clear')
{
$_SESSION['pin'] = array();
}
if ($_POST['action'] == 'Del')
{
unset($_SESSION['pin'][(count($_SESSION['pin'])-1)]);
}
unset($_POST['action'], $_POST['pin_x'], $_POST['pin_y']);
}
// Controleren welk getal ingetoetst is.
if (isset($_POST['pin_x']) && isset($_POST['pin_y']))
{
pin_click();
}
$totpin = count($_SESSION['pin']);
$tekens = '';
for ($i = 0; $i < $totpin; $i++)
{
$tekens .= '*';
}
echo 'Pin: '.$tekens;
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
echo '<input type="image" name="pin" src="pin.php?width='.$width.'" alt="PIN"/>';
echo '<br/ ><input type="submit" name="action" value="Del"><input type="submit" name="action" value="Clear">';
echo '</form>';
?>