Two CodeIgniter App Session Overiding Eachother - codeigniter

so i have 2 ci app on my server(different project folder) and the session overiding each other when accessed with same browser.
i just notice this, because i think its gonna be different by default even the session variable name is same.
i find some problem here when im set_userdata and sess_destroy it applying to both of the app.
i use pretty much same variable on each other
$data_session = array(
'EMP_ID' => $data['EMP_ID'],
'EMP_FULL_NAME' => $data['EMP_FULL_NAME'],
'EMP_F_NUM' => $data['EMP_F_NUM'],
'EMP_EMAIL' => $data['EMP_EMAIL'],
'LEAD_STATUS' => $data['LEAD_STATUS'],
'BRANCH_ID' => $row_br['BRANCH_ID'],
'BRANCH_NAME' => $row_br['BRANCH_NAME'],
'BRANCH_CODE' => $row_br['BRANCH_CODE'],
'DEPART_ID' => $row_dep['DEPART_ID'],
'DEPART_NAME' => $row_dep['DEPART_NAME'],
'STATUSLOGIN' => "LOGIN",
'CONTINUE' => 'NEW'
);
$this->session->set_userdata($data_session);
how do i make it different from each other? do i need to make a different variable when set_userdata on each app?

My guess is you are probably using the copy of an old project to create a new project. In doing so you also need to change the Config variables for sessions in the application/config/config.php file.
So you need to update one session name variable.
$config['sess_cookie_name'] = 'second_project_session';

Related

Add cursorPaginate to collection

So, I have built a very detailed collection in Laravel to give me very specific and clean data in a format that works within my frontend. Now, forgetting that this will be a LOT of data, I needed to add paginate. As this is just going to be infinite scroll, I wanted to use cursorPaginate
Unfortunately, the code below does not allow it. The standard error of Method Illuminate\Support\Collection::cursorPaginate does not exist
How would I be best to refactor this to give me the data required AND give me cursorPaginate? I am completely open to changing some of it, I just do not know where best to start.
Thanks in advance!
return Activity::get()->groupBy('batch_uuid')->map(function ($batch) {
return [
'description' => $batch->first()->description,
'uuid' => $batch->first()->batch_uuid,
'event' => $batch->first()->event,
'created_at' => $batch->first()->created_at,
'subject' => $batch->first()->subject_type::find($batch->first()->subject_id),
'activities' => $batch->map(function ($activity) {
return [
'item' => $activity->causer_type::find($activity->causer_id),
];
}),
];
})->sortByDesc('created_at')->values();
```
You should watch this video from Laravel Daily. First method mentioned in this video he uses LengthAwarePaginator but you can try CursorPaginator for your purpose.

Overwrite Laravel Http Faker

Is there a way to overwrite values of Http::fake([]) in Laravel during testing. I've noticed that if I set a value during a faker, eg. Http::fake(['url1.com' => Http::response('OK'), 'url2.com' => Http::response('Not Found', 404),]), if for some reason I need to change the value of say url1.com to something else such as ['message' => 'Success'], if I "update" the value by calling Http::fake(['url1.com' => Http::response(['message' => 'Success']) again at a later point, I'd expect the response when I call Http::get('url1.com') to return ['message' => 'Success'] but it instead always returns OK which was the original value set.
Same way if I later call Http::fake(['url2.com' => Http::response(['message' => 'Object found.'])]), I would expect the response when I call Http::get('url2.com') to be ['message' => 'Object found.'] but it'll always return Not found which was the original value set.
You can use achieve this by swapping the Http client
Http::fake(['https://potato.com' => Http::response('Yummy!', 200)]);
dump(Http::get('https://potato.com')->body()); // Yummy!
at some point in your test, you can reset the Http Facade using Facade Swap
Http::swap(app(\Illuminate\Http\Client\Factory::class));
now you can change the fake value to whatever you want
Http::fake(['https://potato.com' => Http::response("That's what the dcotor ordered.", 200)]);
dump(Http::get('https://potato.com')->body()); // That's what the doctor orderd.

The sessions are dying on redirect

The sessions are no longer working on redirect, if i set a session with session([ 'key' => 'value' ]); is working on the same page, but if i set the session in controller, after redirect is NULL, also, when i redirect, the values passed ->with(array) are NULL:
return redirect()->route('account.login', ['subdomain' => 'account'])->with(
[
'request-tfa' => true,
'requested-email' => $validatedData['email'],
'requested-password' => encrypt($validatedData['password'])
]);
When i get the value using Session::get('request-tfa') is NULL, until now, this worked perfectly.
Do anyone have any idea how to fix it?
Should i try to use a database as session storage? but i don't know how to setup the database to store the sessions.
EDIT: I changed the session driver to database and is still not working, but the sessions are stored.
And even \Auth::attempt is not working, like, if i use:
if(\Auth::attempt(['email' => $validatedData['email'], 'password' => $validatedData['password']]))
{
return \Auth::id();
}
it working, but if i have return redirect i am guest again.
EDIT X2
Well, i changed my virtual host domain and restarted my pc and now is working...
If you want to have a session after redirect you should use:
session()->put('something')

zf2 DB insert using custom query is not working

We are developing a website using ZF2. We alreday started the project. We installed ZF2 skelton application and integrated the album module. Everything seems working. Now we are trying to integrate multiple zend forms in a module. Forms eveyrything we made [ by modifying the albulm module elements) I am able to insert/update/delete etc data in to the default table that set on the module.php file [this is for form 1].
I have another form which requires to insert/delete/update to another table, I created new form class, Table class (on model) etc. When I tried to insert the data in to Db using custom query format, it throws error:
File:
/home/catholic/public_html/propertydosth/vendor/zendframework/zendframework/library/Zend/Db/Sql/Insert.php:298
Message:
The key adapter was not found in this objects column list.
It seems adaptor value is not getting something..
My Code for insert query:
$adapter = $this->tableGateway->getAdapter();
$sql = new Sql($adapter);
$insert = $sql->insert('dad_cms');
$newData = array(
'category_id' => $admin->category_id,
'cms_title' => $admin->cms_title,
'cmd_desc' => $admin->cmd_desc,
'seo_keywords' => $admin->seo_keywords,
'seo_titles' => $admin->seo_titles
);
$insert->values($newData);
$selectString = $sql->getSqlStringForSqlObject($insert);
$results = $insert->adapter->query($selectString, Adapter::QUERY_MODE_EXECUTE);
I am getting correct query value when I echoed $selectString .
Any one please suggest what is wrong in my code to get it done.
Finally Sam helped me on this issue:
So correct Answer become [this will be helpful somebody having similar issue. Even I spent lot of time to debug the same]:
$adapter = $this->tableGateway->getAdapter();
$sql = new Sql($adapter);
$insert = $sql->insert('dad_cms');
$newData = array(
'category_id' => $admin->category_id,
'cms_title' => $admin->cms_title,
'cmd_desc' => $admin->cmd_desc,
'seo_keywords' => $admin->seo_keywords,
'seo_titles' => $admin->seo_titles
);
$insert->values($newData);
$selectString = $sql->getSqlStringForSqlObject($insert);
$results = $adapter->query($selectString, Adapter::QUERY_MODE_EXECUTE);

Updating post_meta in WordPress through XML-RPC

I am currently working on a project that involves scraping data from over 300 static pages and transferring that data into a WordPress site. I have set up various custom fields with the Simple Fields (http://simple-fields.com/) plugin, and have a basic XML-RPC connection working. Below is what I am using to test injecting custom posts (written in Ruby):
connection = XMLRPC::Client.new_from_uri "http://localhost:8888/xmlrpc.php"
username = "admin"
password = "password"
test_post = {
:post_type => "custom_property",
:post_status => "draft",
:post_title => "test post!",
:post_meta => {
:_simple_fields_fieldGroupID_1_fieldID_3_numInSet_0 => "test"
}
}
puts connection.call("wp.newPost", 1, username, password, test_post)
I have tried :custom_fields in place of :post_meta but still to no avail. I can't seem to be able to update the custom fields that have been created through Simple Fields.
If anyone has any suggestions on what to do, it would be greatly appreciated.
EDIT: This problem was solved by extending the XML-RPC functions using this article: http://kovshenin.com/2010/custom-xml-rpc-methods-in-wordpress/
It is actually quite tricky to figure out the structure of the Wordpress post. If it is a custom field you want to post in, you should use the format below:
'custom_fields' => [{'key' => 'something', 'value' => 'something else'}]
If it is custom taxonomy, use this:
'terms' => {
'custom_type' => [value],
'custom_something' => ['array_item','array_item']
}
For terms you always need to put the value into an array even if it's just one item. Hope it helped.

Resources