string encryption is not working in my codeigniter view. i have written below code in my view it shows some error. can any one help me out to fix this issue.
<?php
$this->load->library('encryption');
$msg = "My Message";
$encrypt_msg = $this->encryption->encode($msg);
echo $encrypt_msg;
?>
for this i got below error
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Loader::$encryption
Filename: back-end/edit_wd_view.php
Line Number: 82
Backtrace:
File: /Applications/XAMPP/xamppfiles/htdocs/projects/5ine-portfolio/application/views/back-end/edit_wd_view.php
Line: 82
Function: _error_handler
File: /Applications/XAMPP/xamppfiles/htdocs/projects/5ine-portfolio/application/views/back-end/backend_view.php
Line: 1
Function: view
File: /Applications/XAMPP/xamppfiles/htdocs/projects/5ine-portfolio/application/controllers/Back_end.php
Line: 552
Function: view
File: /Applications/XAMPP/xamppfiles/htdocs/projects/5ine-portfolio/index.php
Line: 315
Function: require_once
$this->load->library('encryption');
$key = bin2hex($this->encryption->create_key(16));
$this->encryption->initialize(
array(
'cipher' => 'aes-256',
'mode' => 'ctr',
'key' => $key
)
);
$this->encryption->initialize(array('driver' => 'openssl'));
$msg = "My Message";
$encrypt_msg = $this->encryption->encrypt($msg);
echo $encrypt_msg;
More About https://codeigniter.com/userguide3/libraries/encryption.html
Related
I'm trying to create my first test in laravel.
$random = str_random(12);
$payload = [
'name' => $random,
'email' => $random .'#www.com',
'password' => '123456',
];
$this->json('post', '/api/v1/register', $payload)
->assertStatus(200);
The method being called from this url /api/v1/register contains:
$rules = User::rules();
$validation = \Validator::make( $this->input, $rules );
if ( $validation->fails() ) {
return true;
}else return true;
When I run the test it gives response status 500.
when I write ( echo 1; ) above this line :
if ( $validation->fails() ) {
it outputs (1 ) plus the 500 status response
If I write echo 1; below the same line, nothing outputted, so that line the line producing the error.
I check laravel log file and this is the error:
[2018-03-03 12:55:07] testing.ERROR: SQLSTATE[HY000] [2002] No such
file or directory {"exception":"[object] (PDOException(code: 2002):
SQLSTATE[HY000] [2002] No such file or directory at
/opt/lampp/htdocs/ws/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:67)
Note: calling the same URL from the browser or from a rest client works fine with no errors.
Have you made any changes to your phpunit.xml? It sounds to me like your testing environment is looking for a database that is not there.
Using the below PHP code to invoke lambda function but i am getting the below error. Looked at the PHP AWS api docuumentation not able to find whats causing issue.
Receiving the below error from aws php sdk
PHP Warning: Illegal string offset 'StatusCode' in /var/www/html/Guzzle/Service/Command/LocationVisitor/Response/StatusCodeVisitor.php on line 21
PHP Warning: Illegal string offset 'FunctionError' in /var/www/html/Guzzle/Service/Command/LocationVisitor/Response/HeaderVisitor.php on line 24
PHP Warning: Illegal string offset 'LogResult' in /var/www/html/Guzzle/Service/Command/LocationVisitor/Response/HeaderVisitor.php on line 24
PHP Catchable fatal error: Argument 1 passed to Guzzle\Service\Resource\Model::__construct() must be of the type array, string given, called in /var/www/html/Guzzle/Service/Command/OperationResponseParser.php on line 86 and defined in /var/www/html/Guzzle/Service/Resource/Model.php on line 20
use Aws\Lambda\LambdaClient;
$client = LambdaClient::factory(array(
'credentials' => array(
'key' => $f_key,
'secret' => $f_secret,
),
'region' => 'ap-southeast-2'
));
try {
echo "new invoke" . "\n";
$result = $client->invoke(array(
// FunctionName is required
'FunctionName' => 'hello_wo’,
));
}catch(Exception $e) {
echo 'Error retrieving lambd error message code-' . $e->getCode . '-error message-' . $e->getMessage() ;
}
Try this:
$client = LambdaClient::factory([
'key' => $f_key,
'secret' => $f_secret,
'region' => 'ap-southeast-2'
]);
Code:
function getUserId($userName) {
$myModel = new MY_Model();
$requiredFields = "id";
$whereClause = [ // line number 35
"is_active" => 'ACTIVE',
"user_name" => $userName
];
$userId = $myModel->select("users", $requiredFields, $whereClause);
return $userId;
}
Error:
Parse error: syntax error, unexpected '[' in /home/com/public_html/_apis/application/helpers/custom_helper.php on line 35
A PHP Error was encountered
Severity: Parsing Error
Message: syntax error, unexpected '['
Filename: helpers/custom_helper.php
Line Number: 35
Backtrace:
Replace Where Clause with this (Hope this help) :
$whereClause = array( // line number 35
"is_active" => 'ACTIVE',
"user_name" => $userName
);
Try this
$whereClause = array();
$whereClause['is_active'] = 'ACTIVE';
$whereClause['user_name'] = $userName;
I get the following error when click on sign up button.
Fatal error: Call to undefined function set_value() in C:\wamp\www\bdcom\www\application\views\auth\register_form.php on line 19
I am new to codeigniter framework.
following is the code in register_form.php
if ($success){
echo '<div id=success>'.$success_message.'<div>';
}else {
//show the form
$use_username = true;
if ($use_username) {
$username = array(
'name' => 'username',
'id' => 'username',
'value' => set_value('username'),
'maxlength' => $this->config->item('username_max_length', 'tank_auth'),
'size' => 30,
);
}
And this is how I load register.php in auth.php
$this->load->view('auth/register_form', $data);
Have loaded the form helper in autoloader as well. Stuck from 3 days tring to figure out what the problem is. Appreciate the help
Thanks
Check if your autoload.php has the following, if not add them, its due to form helper not being loaded.
$autoload['helper'] = array('url','form','html');
In your constructor of your controller write this:
$this->load->helper('form');
following along with :CodeIgniter from Scratch: The Calendar Library
The code from the earlier version:
class Mycal extends CI_Controller
{
function display($month, $year) {
$conf = array(
'start_day' => 'Monday',
'show_next_prev' => true,
'next_prev_url' => base_url() . 'mycal/display'
);
$this->load->library('calendar', $conf);
print $this->calendar->generate($month, $year);
}
}
generates these errors:
A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for Mycal::display()
Filename: controllers/mycal.php
Line Number: 4 A PHP Error was encountered
Severity: Warning
Message: Missing argument 2 for Mycal::display()
Filename: controllers/mycal.php
Line Number: 4 A PHP Error was encountered
Severity: Notice
Message: Undefined variable: year
Filename: controllers/mycal.php
Line Number: 16 A PHP Error was encountered
Severity: Notice
Message: Undefined variable: month
Filename: controllers/mycal.php
Line Number: 16
I updated to the following:
class Mycal extends CI_Controller {
function display($year = null, $month = null) {
$year = $this->uri->segment(3);
$month = $this->uri->segment(4);
$conf = array(
'start_day' => 'Monday',
'show_next_prev' => true,
'next_prev_url' => base_url() . 'mycal/display/'
);
$this->load->library('calendar', $conf);
print $this->calendar->generate($year, $month);
}
}
It works as desired, but is it following best practices for CI?
When the display function is called, $year and $month will be set to the URI segments (or null) for you. The $this->uri->segment call is not needed here.
Also echo is slightly faster than print (according to this).
function display($year = null, $month = null) {
$conf = array(
'start_day' => 'Monday',
'show_next_prev' => true,
'next_prev_url' => base_url() . 'mycal/display/'
);
$this->load->library('calendar', $conf);
echo $this->calendar->generate($year, $month);
}
Building off of Rocket's answer, you need to set the year and month if they're not passed in the url.
By doing $year = null, $month = null as the parameters, it means that if no parameters are passed, $year will equal null and $month will equal null, but if parameters are passed in the url, $year will equal the first parameter and $month will equal the next parameter.
function display($year = null, $month = null) {
$year = ($year == null) ? date('Y') : $year;
$month = ($month == null) ? date('n') : $month;
$conf = array(
'start_day' => 'Monday',
'show_next_prev' => true,
'next_prev_url' => base_url() . 'mycal/display/'
);
$this->load->library('calendar', $conf);
echo $this->calendar->generate($year, $month);
}