Codeigniter has a nice CAPTCHA function (would be nice if we did not need them) which I used on the contact page. To use this you include the captcha helper, include a table in the database, and then just check the return value against what is expected. The system handles the cleaning. When inserting a new record you have to save the IP address, time, and the word to be displayed (I used the default). In the form validation function I use a call back to handle this.
$this->load->helper('captcha');
$vals = array( 'img_path' => './images/', 'img_url' => base_url() . 'images/' ); $cap = create_captcha($vals); $data['cap'] = $cap; $sqlData = array( 'captcha_time' => $cap['time'], 'ip_address' => $this->input->ip_address(), 'word' => $cap['word'] ); $query = $this->db->insert_string('captcha', $sqlData); $this->db->query($query);
// the call back $this->form_validation->set_rules('captcha', 'CAPTCHA', 'required|callback_checkCaptcha');
function checkCaptcha() { // First, delete old captchas $expiration = time()-7200; // Two hour limit $this->db->query("DELETE FROM captcha WHERE captcha_time < ".$expiration); // Then see if a captcha exists: $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?"; $binds = array($_POST['captcha'], $this->input->ip_address(), $expiration); $query = $this->db->query($sql, $binds); $row = $query->row(); if($row->count == 0) { $this->form_validation->set_message('checkCaptcha', 'CAPTCHA must match input value'); return FALSE; } return TRUE; }
Ok if you need to force a your computer to find a secific computer and the DNS does not want to resolve the name you can add the value to the hosts record in the system32/etc directory. I normally run notepad in admin mode to save getting the no permission error.
C:\Windows\System32\drivers\etc\hosts
Add this line until the rest of DNS records are updated, hate 1and1 today!
38.113.1.225 www.theheartlinknetwork.com
I added the prev/next to the post view so the user can go to the next post, if there is no prev or next post the link will not be there but the word is. Still need to be able to go past the first group of post on the home page but then I have to have more then one home page full of post
Posted this somewhere else, still think it is interesting so posting it again.
http://www.notmartha.org/archives/2010/03/30/chocolate-easter-surprise-eggs/
Ok so todays battle is with 1and1. One of the website was admin started throwing a 500 error. After a lot of searching we found that somehow the 1and1 DNS settings had change to the wrong server, go figure...
I am using the CK Editor here with CodeIgnitor using the ckeditor_helper from here. The helper is placed in the CodeIgnitor helper folder in the application directory which allows the helper to be called. The next step is to load the helper before calling it with the $this->load->helper('ckeditor'). The next step is to display the editor in the brower by setting the name of the text area to be used in the parmaters passed the the help function.
I also needed to update images which is not supported out of the box but can be accomplish by adding another parameter and creating a uploader. The below code shows the finally setting in the browser.
<textarea cols="60" name="FCKeditor1" rows="8"><?php echo set_value('contents'); ?></textarea>
$parm = array(
//ID of the textarea that will be replaced
'id' => 'FCKeditor1',
'path' => 'scripts/ckeditor',
'config' => array(
'filebrowserImageUploadUrl' => site_url('uploader?type=file.jpg')
),
);
echo display_ckeditor($parm);
?>
class Uploader extends CI_Controller
{
function Uploader()
{
parent::__construct();
}
function index()
{
$upload_file = $this->image($_FILES["upload"]["name"]);
if(isset($upload_file['data']['upload_data']['file_name']) && trim($upload_file['data']['upload_data']['file_name']) != '')
{
$funcNum = $_GET['CKEditorFuncNum'];
$CKEditor = $_GET['CKEditor'];
$langCode = $_GET['langCode'];
$url = site_url('images') . '/' . $upload_file['data']['upload_data']['file_name'];
$message = '';
echo "";
} else {
echo $upload_file['message']['error'];
}
}
function image($filenames = '')
{
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '300';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
$result['status'] = 0;
$result['message'] = 'fail';
$result['data'] = array();
if ( ! $this->upload->do_upload('upload'))
{
$error = array('error' => $this->upload->display_errors());
$result['message'] = $error;
}
else
{
$data = array('upload_data' => $this->upload->data());
$result['status'] = 1;
$result['message'] = 'Upload OK';
$result['data'] = $data;
}
return $result;
}
}
This site will be about programming and other odds and ends. It is written in CodeIgniter using PHP and will be a test site for things I need to do on other sites.
Note that I am building a BLOG or CMS depending on your view point using CodeIgniter so some basic functionality does not exist and may never or will be added as I have time.