Pages

Showing posts with label codeigniter. Show all posts
Showing posts with label codeigniter. Show all posts

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

Friday, February 3, 2017

Remove Index.php from URL in codeigniter

How to Remove Index.php from URL in codeigniter

Just Copy and paste this data in your .htaccess on root folder of your project file then run your project.

RewriteEngine On

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]

#When your application folder isn't in the system folder

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]