CodeIgniter config file not finding database info? - codeigniter

I'm having database connection issues.
Here is the error I get:
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 338
Here is my database.php file settings:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'user';
$db['default']['password'] = 'password';
$db['default']['database'] = 'dvp';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
I've placed this code at the bottom of my database.php file:
echo '<pre>';
print_r($db['default']);
echo '</pre>';
echo 'Trying to connect to database: ' .$db['default']['database'];
$dbh=mysql_connect
(
$db['default']['hostname'],
$db['default']['username'],
$db['default']['password'])
or die('Cannot connect to the database because: ' . mysql_error());
mysql_select_db ($db['default']['database']);
echo '<br /> Connected OK:' ;
die( 'file: ' .__FILE__ . '--> Line: ' .__LINE__);
And the following info displays:
Array
(
[hostname] => localhost
[username] => user
[password] => password
[database] => dvp
[dbdriver] => mysql
[dbprefix] =>
[pconnect] => 1
[db_debug] => 1
[cache_on] =>
[cachedir] =>
[char_set] => utf8
[dbcollat] => utf8_general_ci
[swap_pre] =>
[autoinit] => 1
[stricton] =>
)
Trying to connect to database: dvp
Connected OK
Any ideas?

Ug, found the issue. Someone manually added a second set of db settings in another file and was calling them in from there. What a mess!

Related

Codeigniter session lost

I use codeigniter for a project, my session is configured to use the mysql database :
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
In my controller i have a code like this :
$params = array(
"type" => $data['activite_name'],
"activite" => $data['activite'],
"nom" => $data['name'],
"prenom" => $data['fname'],
"tel" => $data['tel'],
"email" => $data['email'],
"adresse" => $data['adr'],
"cp" => $data['cp'],
"ville" => $data['ville']
);
....
#Load session library and save $params as session
$this->load->library('session');
$this->session->set_userdata($params);
#Test session
$sess_name = $this->session->userdata('name');
echo $sess_name;
#Load view
$this->load->view("templates/header_interne", $data);
$this->load->view("pages/payment_view", $data);
$this->load->view("templates/footer", $data);
So when payment_view is loaded i can see my $sess_name value, but when i refresh the page i lost this session, and so on for all my sessions.
Anyone has an idea please?
Thank you.

Twitter OAUTH and Codeigniter

I'm trying to display tweets on a website built on codeigniter but can't seem to pull in the user tweets. To do this, I'm pulling the following script into my header as an include and then printing the tweet in the appropriate section with the code below. I've already set up the access tokens and consumer keys as well. Any ideas on why this is working?
Include file in header
<?php
function buildBaseString($baseURI, $method, $params) {
$r = array();
ksort($params);
foreach($params as $key=>$value){
$r[] = "$key=" . rawurlencode($value);
}
return $method."&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r));
}
function buildAuthorizationHeader($oauth) {
$r = 'Authorization: OAuth ';
$values = array();
foreach($oauth as $key=>$value)
$values[] = "$key=\"" . rawurlencode($value) . "\"";
$r .= implode(', ', $values);
return $r;
}
$url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
$oauth_access_token = "ACCESS TOKEN HERE";
$oauth_access_token_secret = "ACCESS TOKEN SECRET HERE";
$consumer_key = "CONSUMER KEY HERE";
$consumer_secret = "CONSUMER KEY SECRET HERE";
$oauth = array( 'oauth_consumer_key' => $consumer_key,
'oauth_nonce' => time(),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_token' => $oauth_access_token,
'oauth_timestamp' => time(),
'oauth_version' => '1.0'
);
$base_info = buildBaseString($url, 'GET', $oauth);
$composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
$oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
$oauth['oauth_signature'] = $oauth_signature;
// Make Requests
$header = array(buildAuthorizationHeader($oauth), 'Expect:');
$options = array( CURLOPT_HTTPHEADER => $header,
//CURLOPT_POSTFIELDS => $postfields,
CURLOPT_HEADER => false,
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false);
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);
$twitter_data = json_decode($json, false);
$latest_tweet = $twitter_data[0];
?>
Print tweet
<span class="tweet">"<?php if(!empty($latest_tweet)){echo $latest_tweet->text;} else{echo "Welcome to Time Equities!";} ?>"</span>

CodeIgniter Captcha is not working

I am at my wits end and don't know why my code is not working . Everything seems good to me .. I have implemented a captcha in my user review function and added a verification method using callback_ .
The captcha is showing in the view and i have dumped the session data and the input field data and they are both working.
The form validation is also working in case of captcha input field but seems like the callback_check_captcha parameter is not working but the function seems fine to me .
Here is my controller
function user_review($id = null , $start = 0){
$check_id = $this->mdl_phone->get_phone_feature($id);
if ($check_id == null ) {
$data['phone_model'] = $this->get_phone_models();
$data['feature'] = null;
$data['title'] = 'Nothing Found';
$data['main_content']= 'phone/error';
echo Modules::run('templates/main',$data);
} else{
$data['phone_model'] = $this->get_phone_models();
$data['success'] = null;
$data['errors'] = null;
if($this->input->server("REQUEST_METHOD") === 'POST' ){
$this->load->library('form_validation');
$this->form_validation->set_rules('text','Review','required|xss_clean');
$this->form_validation->set_rules('captcha', 'Captcha','trim|required|callback_check_captcha');
if($this->form_validation->run() == FALSE){
$data['errors'] = validation_errors();
}else{
$user = $this->ion_auth->user()->row();
$user_id = $user->id;
$data = array(
'phone_id' => $id,
'user_id' => $user_id,
'text' => strip_tags($this->input->post('text')),
);
$this->db->insert('user_review' ,$data);
$data['phone_model'] = $this->get_phone_models();
$data['success'] = 'Your Review has been successfully posted ';
$data['errors']= null;
}
}
// Initilize all Data at once by $id
$data['feature'] = $this->mdl_phone->get_phone_feature($id);
//$data['rating'] = $this->mdl_phone->get_user_rating($id);
$data['user_review'] = $this->mdl_phone->get_user_review($id , 5 , $start);
$this->load->library('pagination');
$config['base_url'] = base_url().'phone/user_review/'.$id;
$config['total_rows'] = $this->mdl_phone->get_user_review_count($id);
$config['per_page'] = 5;
$config['uri_segment'] = 4;
$config['anchor_class'] = 'class="page" ';
$this->pagination->initialize($config);
$this->load->helper('captcha');
$vals = array(
'img_path' => './captcha/',
'img_url' => base_url().'captcha/',
'img_width' => 150,
'img_height' => 30,
);
$cap = create_captcha($vals);
$this->session->set_userdata('captcha',$cap['word']);
$data['captcha'] = $cap['image'];
$data['title'] = $this->mdl_phone->get_phone_title($id)." User Review , Rating and Popularity";
$data['main_content'] = 'phone/user_review';
echo Modules::run('templates/main',$data);
}
}
function check_captcha($cap)
{
if($this->session->userdata('captcha') == $cap )
{
return true;
}
else{
$this->form_validation->set_message('check_captcha', 'Security number does not match.');
return false;
}
}
The bellow CAPTHA working properly refer this code
$this->load->helper('captcha');
$vals = array(
'img_path' => './captcha/',
'img_url' => base_url() . '/captcha/'
);
$cap = create_captcha($vals);
$data = array(
'captcha_time' => $cap['time'],
'ip_address' => $this->input->ip_address(),
'word' => $cap['word']
);
$this->session->set_userdata($data);
$data['cap_img'] = $cap['image'];
I think your image url problem or you are not giving a file permission to the captha folder .

CodeIgniter - ActiveRecords and Oracle - configuration

I had a problem with ActiveRecords - CI add brackets to the table names - so oracle returns errors.
Here is some info how to fix it :)
first configure your database
My old dns config looks like this
$dsn = array(
'phptype' => 'oci8',
'hostspec' => '192.xx.215.xx',
'service' => 'yyyyy',
'port' => '1521',
'username' => 'zzzzz',
'password' => 'aaaaa'
);
So I added in application\config\database.php this:
$db['oracle']['hostname'] = "192.xx.215.xx/yyyyy";
$db['oracle']['username'] = "zzzzz";
$db['oracle']['password'] = "ttttt";
$db['oracle']['database'] = "dbname.table";
$db['oracle']['dbdriver'] = "oci8";
$db['oracle']['dbprefix'] = "";
$db['oracle']['pconnect'] = FALSE; //must be false
$db['oracle']['db_debug'] = TRUE;
$db['oracle']['cache_on'] = FALSE;
$db['oracle']['cachedir'] = "";
$db['oracle']['char_set'] = "utf8";
$db['oracle']['dbcollat'] = "utf8_general_ci";
in system\database\drivers\oci8\oci8_driver.php replace line
return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
with
// remove duplicates if the user already included the escape
$str = preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
$str = rtrim($str,'"');
$str = ltrim($str,'"');
$str = str_replace('"."', '.', $str);
return $str;
Now i your model you can call
$this->oracle = $this->load->database('oracle', TRUE);
Now Oracle and Ci should works! :)

Email sent in localhost but not in server

When I try to send emails from localhost, everything works fine. But when I uploaded my app to the server, the email functionality doesn't work anymore! I uses a Gmail account.
Here is my config/email.php file:
$config['useragent'] = 'CodeIgniter';
$config['protocol'] = 'smtp';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = 'myemail#gmail.com';
$config['smtp_pass'] = 'my_password';
$config['smtp_port'] = 465;
$config['smtp_timeout'] = 80;
$config['wordwrap'] = TRUE;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['validate'] = FALSE;
$config['priority'] = 3;
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$config['bcc_batch_mode'] = FALSE;
$config['bcc_batch_size'] = 200;
$config['sender_name'] = 'Name';
$config['from_email'] = 'myemail#gmail.com';
$config['to_email'] = 'myemail#gmail.com';
$config['email_subject'] = 'Email Subject';
And this is how I sent an email in my controller:
$this->load->library('email');
$this->email->from($this->config->item('from_email'), $this->config->item('sender_name'));
$this->email->to($this->config->item('to_email'));
$this->email->subject($this->config->item('email_subject'));
$this->email->message($string);
if (!$this->email->send())
{
$data['success'] = FALSE;
}
else
{
$data['success'] = TRUE;
}
$this->_example_output('layouts/sendemail_confirm.php', $data);
And this is the error I receive:
A PHP Error was encountered
Severity: Warning
Message: fsockopen() [function.fsockopen]: unable to connect to
ssl://smtp.googlemail.com:465 (Connection refused)
Filename: libraries/Email.php
Line Number: 1689
A PHP Error was encountered
Severity: Warning
Message: fwrite() expects parameter 1 to be resource, boolean given
Filename: libraries/Email.php
Line Number: 1846
A PHP Error was encountered
Severity: Warning
Message: fgets() expects parameter 1 to be resource, boolean given
Filename: libraries/Email.php
Line Number: 1869
Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.googlemail.com:465 (Connection refused)
It's possible that your server's IP address is blacklisted by Google due to previous spamming attempts... Is it a shared hosting account? A cloud hosting account? Etc? All those are susseptable to stuff like this.
There might also be a reverse DNS lookup mismatch with the domain name and from address, or the domain's DNS might have SPF policy settings that are preventing Google from accepting mail, or an envelop issue with the host-name, or it's using 127.0.0.1 as the originating address.
Also check your php.ini settings to make sure you are using / or not-using sendmail_from= and mail.add_x_header= the same way on both systems.
Try using smtp host as "smtp.gmail.com"
$config['smtp_host'] = 'smtp.gmail.com';
Use this config options
$config['protocol'] = 'smtp';
$config['mail_path'] = 'ssl://smtp.googlemail.com';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
And add this line, after loading email library
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$config = Array(
'protocol' => 'mail',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'iskpro.it#gmail.com', // change it to yours
'smtp_pass' => 'afycon#123', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from($from); // change it to yours
$this->email->to($to);// change it to yours
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();

Resources