email validatie
ik heb hier een script gevonden om een e-mail adres te laten valideren.nu wil ik graag even weten of iemand mij kan helpen?
waar kan ik dit script het beste plaatsen.en hoe moet ik dit plaatsen.
kan iemand helpen.ik ben nieuw met php en probeer mijn best te doen dit allemaal snel te snappen.
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
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
<?php
function checkmail($email){
/* Check OS script is executed on*/
/* Checkdnsrr Windows support from php 5.3*/
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' and version_compare(PHP_VERSION, '5.3.0') === -1) {
/* PHP version doesn't support getmxrr and checkdnsrr*/
/* Syntax control function here*/
return preg_match('/^\w[-.\w]*@(\w[-._\w]*\.[a-zA-Z]{2,}.*)$/', $email);
}
/* PHP version higher or equal to 5.3.0*/
/* Function by Hipska @ http://www.phphulp.nl/php/scripts/11/1622/ */
if(preg_match('#.+@(?<host>.+)#',$email,$match) > 0 and getmxrr($match['host'],$mxhosts)){
/* Found MX records*/
$valid = false;
/* Walkt through MX records for valid*/
while($host = next($mxhosts) and !$valid){
/* IPv4 or IPv6 will do*/
$valid = checkdnsrr($host, 'A') or checkdnsrr($host,'AAAA');
}
return $valid;
}
/* No valid email --> no correct host name or no MX records found*/
return false;
}
?>
function checkmail($email){
/* Check OS script is executed on*/
/* Checkdnsrr Windows support from php 5.3*/
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' and version_compare(PHP_VERSION, '5.3.0') === -1) {
/* PHP version doesn't support getmxrr and checkdnsrr*/
/* Syntax control function here*/
return preg_match('/^\w[-.\w]*@(\w[-._\w]*\.[a-zA-Z]{2,}.*)$/', $email);
}
/* PHP version higher or equal to 5.3.0*/
/* Function by Hipska @ http://www.phphulp.nl/php/scripts/11/1622/ */
if(preg_match('#.+@(?<host>.+)#',$email,$match) > 0 and getmxrr($match['host'],$mxhosts)){
/* Found MX records*/
$valid = false;
/* Walkt through MX records for valid*/
while($host = next($mxhosts) and !$valid){
/* IPv4 or IPv6 will do*/
$valid = checkdnsrr($host, 'A') or checkdnsrr($host,'AAAA');
}
return $valid;
}
/* No valid email --> no correct host name or no MX records found*/
return false;
}
?>
alvast bedankt voor de hulp mocht die komen
mvg hr knarren.
Dit is een function. Die plaats je liefst bovenin je code of in een te includen functiebestand. De aanroep van de function doe je op de plaats waar je het nodig hebt.
dus het beste includen boven aan deze pagina.
Code (php)
<h4><p>registreer een account</p></h4>
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
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
<?php
if (isset($_POST['register_email'], $_POST['register_name'], $_POST['register_password'])) {
$register_email = $_POST['register_email'];
$register_name = $_POST['register_name'];
$register_password = $_POST['register_password'];
$errors = array();
if (empty($register_email) || empty($register_name) || empty($register_password)) {
$errors[] = 'alle velden moeten ingevuld zijn!';
} else {
if (filter_var($register_email, FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'email adres is niet geldig';
}
if (strlen($register_email) > 255 || strlen($register_name) > 35 || strlen($register_password) > 35) {
$errors[] = 'een of meer velden hebben een te groote naam waarde';
}
if (user_exists($register_email) === true) {
$errors[] = 'Dit email addres is all in gebruik';
}
}
if (!empty($errors)) {
foreach ($errors as $error) {
echo $error, '<br />';
}
} else {
$register = user_register($register_email, $register_name, $register_password);
$_SESSION['user_id'] = $register;
header('Location: index.php');
exit();
}
}
?>
if (isset($_POST['register_email'], $_POST['register_name'], $_POST['register_password'])) {
$register_email = $_POST['register_email'];
$register_name = $_POST['register_name'];
$register_password = $_POST['register_password'];
$errors = array();
if (empty($register_email) || empty($register_name) || empty($register_password)) {
$errors[] = 'alle velden moeten ingevuld zijn!';
} else {
if (filter_var($register_email, FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'email adres is niet geldig';
}
if (strlen($register_email) > 255 || strlen($register_name) > 35 || strlen($register_password) > 35) {
$errors[] = 'een of meer velden hebben een te groote naam waarde';
}
if (user_exists($register_email) === true) {
$errors[] = 'Dit email addres is all in gebruik';
}
}
if (!empty($errors)) {
foreach ($errors as $error) {
echo $error, '<br />';
}
} else {
$register = user_register($register_email, $register_name, $register_password);
$_SESSION['user_id'] = $register;
header('Location: index.php');
exit();
}
}
?>
<img src="images/registratieachtergrond.png"><br>
<form action="" method="post">
<p>Email:<br /><input type="email" name="register_email" size="35" maxlength="255" /></p>
<p>Volledige naam:<br /><input type="text" name="register_name" maxlength="35" /></p>
<p>Passwoord:<br /><input type="password" name="register_password" maxlength="35" /></p>
<p><input type="submit" value="registreer" /></p>
</form>
Toevoeging op 08/03/2012 20:22:14:
hoe kan ik het beste de functie aanmaken? met de gegevens van hierboven.het tweede script is een registratie script.het eerste de validatie script of werkt dat niet zo.
heb net wat geprobeert maar het lukt me niet zoals het hoort te gaan ??
Toevoeging op 08/03/2012 20:36:36:
of moet ik de funtie hier plaatsen en includen op de registratie pagina die hierboven vermeld wordt?
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
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
<?php
function logged_in() {
return isset($_SESSION['user_id']);
}
function login_check($email, $password) {
$email = mysql_real_escape_string($email);
$login_query = mysql_query("SELECT COUNT(`user_id`) as `count`, `user_id` FROM `users` WHERE `email`='$email' AND `password`='".md5($password)."'");
return (mysql_result($login_query, 0) == 1) ? mysql_result($login_query, 0, 'user_id') : false;
}
function user_data() {
$args = func_get_args();
$fields = '`'.implode('`, `', $args).'`';
$query = mysql_query("SELECT $fields FROM `users` WHERE `user_id`=".$_SESSION['user_id']);
$query_result = mysql_fetch_assoc($query);
foreach ($args as $field) {
$args[$field] = $query_result[$field];
}
return $args;
}
function user_register($email, $name, $password) {
$email = mysql_real_escape_string($email);
$name = mysql_real_escape_string($name);
mysql_query("INSERT INTO `users` VALUES ('', '$email', '$name', '".md5($password)."')");
return mysql_insert_id();
}
function user_exists($email) {
$email = mysql_real_escape_string($email);
$query = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `email`='$email'");
return (mysql_result($query, 0) == 1) ? true : false;
}
?>
function logged_in() {
return isset($_SESSION['user_id']);
}
function login_check($email, $password) {
$email = mysql_real_escape_string($email);
$login_query = mysql_query("SELECT COUNT(`user_id`) as `count`, `user_id` FROM `users` WHERE `email`='$email' AND `password`='".md5($password)."'");
return (mysql_result($login_query, 0) == 1) ? mysql_result($login_query, 0, 'user_id') : false;
}
function user_data() {
$args = func_get_args();
$fields = '`'.implode('`, `', $args).'`';
$query = mysql_query("SELECT $fields FROM `users` WHERE `user_id`=".$_SESSION['user_id']);
$query_result = mysql_fetch_assoc($query);
foreach ($args as $field) {
$args[$field] = $query_result[$field];
}
return $args;
}
function user_register($email, $name, $password) {
$email = mysql_real_escape_string($email);
$name = mysql_real_escape_string($name);
mysql_query("INSERT INTO `users` VALUES ('', '$email', '$name', '".md5($password)."')");
return mysql_insert_id();
}
function user_exists($email) {
$email = mysql_real_escape_string($email);
$query = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `email`='$email'");
return (mysql_result($query, 0) == 1) ? true : false;
}
?>
Gewijzigd op 08/03/2012 19:59:27 door projectx verheijden