summaryrefslogtreecommitdiff
path: root/src/web/_model/_comments.php
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/web/_model/_comments.php26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/web/_model/_comments.php b/src/web/_model/_comments.php
index 3518508..765fda8 100644
--- a/src/web/_model/_comments.php
+++ b/src/web/_model/_comments.php
@@ -36,10 +36,10 @@ class _comments_model extends Model {
public function get_comments($page)
{
- $ip = CONTEXT['ip'];
+ $ip = $this->get_ip();
$query = $this->db()
->select('*')
- ->from('admin.comment c')
+ ->from('website.comment c')
->where('c.page')
->eq($page)
->query('AND (
@@ -53,12 +53,30 @@ class _comments_model extends Model {
public function post_comment($author, $content, $page, $vulgar)
{
- $ip = CONTEXT['ip'];
+ $ip = $this->get_ip();
return $this->db()
- ->insert_into('admin.comment',
+ ->insert_into('website.comment',
'author', 'content', 'page', 'ip', 'vulgar')
->values($author, $content, $page, $ip, $vulgar)
->execute();
}
+ public function get_ip(): ?string
+ {
+ $headers = array (
+ 'HTTP_CLIENT_IP',
+ 'HTTP_X_FORWARDED_FOR',
+ 'HTTP_X_FORWARDED',
+ 'HTTP_FORWARDED_FOR',
+ 'HTTP_FORWARDED',
+ 'HTTP_X_REAL_IP',
+ 'REMOTE_ADDR'
+ );
+ foreach ($headers as $header) {
+ if (isset($_SERVER[$header]))
+ return $_SERVER[$header];
+ }
+ return NULL;
+ }
+
}