Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /proc/self/root/var/www/laciasmara.com/public_html/shop/application/controllers/ |
Upload File : |
<?php defined('BASEPATH') or exit('No direct script access allowed'); class Subscription extends Public_Controller { public function __construct() { parent::__construct(); $this->load->library('GoogleClient'); $this->load->library('VisitorTracking'); $this->load->database(); $this->load->library('form_validation'); $this->load->helper('security'); $loginUrl = $this->googleclient->getLoginUrl(); $this->data_footer['googleUrl'] = $loginUrl; if ($this->session->userdata('site_lang') == 'english') { $this->lang->load('mainpage', 'english'); } else { $this->lang->load('mainpage', 'indonesian'); } } public function subscribe() { if (!$this->input->is_ajax_request()) { log_message('error', 'Non-Ajax request attempted on subscription endpoint'); show_404(); } $this->output->set_content_type('application/json'); try { $this->form_validation->set_rules( 'email', 'Email', 'trim|required|valid_email|is_unique[subscribers.email]', array( 'required' => 'Please provide an email address.', 'valid_email' => 'Please provide a valid email address.', 'is_unique' => 'This email is already subscribed.' ) ); if ($this->form_validation->run() === FALSE) { throw new Exception(strip_tags(form_error('email'))); } $email = $this->security->xss_clean($this->input->post('email')); $data = array( 'email' => $email, 'subscription_date' => date('Y-m-d H:i:s'), 'ip_address' => $this->input->ip_address(), 'user_agent' => $this->input->user_agent(), 'referer_url' => $this->input->server('HTTP_REFERER'), 'customer_id' => (int) $this->session->userdata('customer')['customer_id'] ?? NULL, 'source' => 'website', 'preferences' => json_encode([ 'newsletter' => true, 'promotions' => true ]), 'is_verified' => true, 'consent' => true ); // Insert ke database dengan error handling $this->db->trans_start(); $insert = $this->db->insert('subscribers', $data); $this->db->trans_complete(); if ($this->db->trans_status() === FALSE) { throw new Exception('Failed to save subscription. Please try again.'); } // Response sukses $response = array( 'success' => true, 'message' => 'Thank you for subscribing to our newsletter!' ); } catch (Exception $e) { $response = array( 'success' => false, 'message' => $e->getMessage() ); } echo json_encode($response); } }