Tutorial :Cakephp: Include php script in .ctp file



Question:

I want to add captcha in myfile.ctp. For this i found source for captcha along with some resource files includs(js, php). I know the folder for js files & include this file using <?php echo $javascript->link(array('ajax_captcha.js'));?>. But I don't know where to place .php file & also how to include it in myfile.ctp

Or if anybody help me to implement Captcha in Cakephp.


Solution:1

For your js, use $javascript->link('ajax_captcha',false); Not the omission of the extension. false will place it in the section of the HTML. This will look for the script in webroot/js

Personally, I would just use a standard php include directive for the php side of things, bearing in mind that the location will be relative to webroot, i.e. '/myPHP/captcha.php'will be webroot/myPHP/captcha.php.

Don't forget, CakePHP is PHP.


Solution:2

I'd use a plugin or component, http://bakery.cakephp.org/articles/view/captcha-component-with-phpcaptcha

This works very well with PHPCaptcha for all your Human vs Computer shenanigans. Feel free to google around for your preferred plugin/component.


Solution:3

There is another article in the bakery - Integrate CakePHP with Kcaptcha (read the comments there too). I have successfully implemented kcaptcha in my application.


Solution:4

Elements are a good way to pull code that gets sprinkled over and over around various views:

http://book.cakephp.org/2.0/en/views.html#elements


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »