-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail.php
47 lines (42 loc) · 1.23 KB
/
email.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
<?php
//Connect to mySQL db
$host = 'localhost';
$db = 'glipple';
$username = 'newsletter';
$password = 'HC4LnNRNVTXHXRRa';
//Get current users IP address from severl possible locations
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
//Only connect to db if email.php is POSTED
if ($_SERVER["REQUEST_METHOD"] === "POST")
{
//Is $_GET set and a valid email?
if (isset($_GET["e"]) && filter_var(json_decode($_GET["e"])->email, FILTER_VALIDATE_EMAIL))
{
try {
//Connect to db and pass info
$DBH = new PDO("mysql:host=$host;dbname=$db", $username, $password);
$DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$STH = $DBH->prepare("INSERT INTO emails (email, IP) VALUES (:email, :IP)");
$STH->bindParam(':email', json_decode($_GET["e"])->email);
$STH->bindParam(':IP', $ip);
$STH->execute();
//true if db was written to
$result = true;
} catch(PDOException $e) {
//false if there was an error
$result = false;
//echo 'ERROR: ' . $e->getMessage();
}
} else {
$result = false;
}
//echo the result
echo $result;
}
?>