Pages

Tuesday, September 15, 2020

Add Google's reCAPTCHA V2 in Codeigniter and verify reCaptcha

// Controller to Load Recaptcha 

$this->load->library('recaptcha');
$recaptcha = $this->recaptcha->create_box();
$data['recaptcha'] = $recaptcha; 
$this->load->view('home',$data); 

/**************************************************/ 

// View to Show reCaptcha in Form 

<!DOCTYPE html>
<html>
<head>
	<title>CodeIgniter reCAPTCHA</title>
	<!-- reCAPTCHA JavaScript API -->
	<script src='https://www.google.com/recaptcha/api.js'></script>
</head>

<body>
	<form action="/path/to/controller">
		<?=$recaptcha?>
		<button type="submit" name="action" value="submit">Submit</button>
	</form>
</body>

</html>

/**************************************************/ 

// Action Controller
public function send_mail() { 

   $from_name = $this->input->post('name');
   $from_email = $this->input->post('email');
   $from_message = $this->input->post('message');
   $to_email = "zakeerio25@gmail.com";

   //Load email library $this->load->library('email');
    $this->load->library('recaptcha');
    $this->email->from($from_email,$from_name);
    $this->email->to($to_email);
    $this->email->subject('contact us form submitted');
    $this->email->message($from_message);
    $is_valid = $this->recaptcha->is_valid();
    if($is_valid['success']) {
        if($this->email->send()) {
            echo "success";
         } else {
            echo "failure email";
    
    }
    } else {
         echo "failure recaptcha";
    }
}


Further Details:

https://github.com/mehdibo/Codeigniter-recaptcha

Tuesday, September 1, 2020

Laravel Redirect HTTP to HTTPS via .htaccess

 Today, i share with you, redirect http to Https in laravel
You create file .htaccess in root laravel

 

RewriteEngine On
RewriteRule ^(.*)$ public/ [L]
 
Way code above it redirect to http, if you want http to https, 
you can using following code above 

 

<IfModule mod_rewrite.c>
    RewriteEngine On        
  RewriteCond %{HTTPS} !=on    
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  RewriteRule ^(.*)$ public/ [L]
</IfModule>