Overriding joomla session variables for form handling - session

I have a joomla website with plethora theme. This is the link to the website where I'm facing problems. http://miraghotels.com/joomjob/membership/planadd?step=2
The form on this link is processed somewhere and an array of variables referring to the form fields and their values is stored in the Joomla session. The problem is that I want to change/override the value of a parameter which is actually in the array variable of the session. To explain this, I'm attaching this code.
$planChosen = $session->get('planChosen', 0, 'register');
First of all, what syntax is this session following? I get a different ouput from just
$session->get('planChosen').
Ok now, when I ouput this variable($planChosen), I get the following output:
Array ( [planname3] => Basic
[planperiod3] => 15 Days
[plancredit3] => 5
[price3] => 0
[plan_id] => 4
[planname4] => Premium
[planperiod4] => 3 Months
[plancredit4] => 25
[price4] => 50
[gateway] => paypal
[option] => com_joomjob
[task] => guest.grabplaninfo
[2d13d7c9e4ffff248cf29092b199f5b2] => 1 )
Now what I want to know is that where is this session stored i.e. where can I find the file where these items are processed in the session.
Secondly, if I want to override a value for e.g. change the value of "gateway" from "paypal" to "moneybookers", how can I achieve that? I tried the following code but no luck:
$string="('planChosen', 0, 'register')[\"gateway\"]";
$session->set($string, "moneybookers");
Please help me out with this

I got this from Joomla.org website
The following code gets the current session then sets the value of the session variable 'myvar' to 'helloworld'.
$session =& JFactory::getSession();
$session->set( 'myvar', 'helloworld' );
The session variable can be retrieved later in a similar way.
$session =& JFactory::getSession();
echo 'Session variable myvar has value: ' . $session->get( 'myvar', 'empty' );
So if you used this code to set paypal as payment gateway
$session->set( 'gateway', 'paypal' );
Now if you want moneybookers you can override paypal by
$session->clear('gateway');
$session->set( 'gateway', 'moneybookers' );
And your session data are saved in database by default unless you changed it to files in the global configuration area. So #__sessions has all your session data.
EDIT:
In that case you can do like this
$session =& JFactory::getSession();
$session->set( 'planChosen', $planChosen );//store array in session variable
//Now you have entire array in this session variable which contains paypal as payment gateway
// Suppose you want to update it then use the code below
$session =& JFactory::getSession();
$planChosen = $session->get( 'planChosen' );
unset($planChosen[$gateway]);
$planChosen["gateway"] = "moneybookers";
$session->set('planChosen',$planChosen);

Related

Git Bash console output breaks down when using Laravel Console choice method

I've a little problem with my console. When I use choice method from Laravel Console, the output totally breaks down. I wanted to google this but I can't find any solution. It's really annoying.
Anyone know how to fix this?
I'm using Git Bash provided by Git for Windows.
That Git bash is an emultion of unix console and it makes me able to use unix like commands. I don't want to stop using this.
Here is the console output
Give your group a name:
Something
Give your group a description (blank for skip):
>
Do you want to assign scopes to your new group? (y/n):
y
Select existing scope name: [0] Random [1] Exit (It's not a
scope)
0 0?[K
?[32mSelect existing scope name?[39m: [?[33m0?[39m] Random
[?[33m1?[39m] Exit (It's not a scope)
>
And the php code as below.
$name = $this->ask('Give your group a name');
$description = $this->ask('Give your group a description (blank for skip)');
$groups = app()->make(ScopeGroupRepository::class);
/** #var ScopeGroup $group */
$group = $groups->perform(new Create($name, $description));
$willCreateScopes = $this->answerToBoolean(
$this->ask('Do you want to assign scopes to your new group? (y/n)')
);
if(!$willCreateScopes) {
return $this->displayCreatedGroupInfo($group);
}
$scopes = app()->make(ScopeRepository::class);
/** #var Collection $unassigned */
$unassigned = $scopes->perform((new ShowAllUnassignedToGroup())->setGroupId($group->id));
if($willCreateScopes) {
do {
$scopes = $unassigned->map(function (Scope $scope){
return $scope->id;
})->toArray();
array_push($scopes, 'Exit (It\'s not a scope)');
// Here it breaks down
$selected = $this->choice('Select existing scope name', $scopes);
} while($selected !== 'Exit (It\'s not a scope)');
}
Thanks for help.

How to get the returns data like Returned Date,Merchant SKU,ASIN etc .,

I am newbie to MWS and working on returned items.
I have used Reports API .
$marketplaceIdArray = array("Id" => array('$MARKETPLACE_ID'));
$t1 = date("c", time()-437*24*60*60);
$t2 = date("c", time()-1*24*60*60);
// #TODO: set request. Action can be passed as
MarketplaceWebService_Model_ReportRequest
// object or array of parameters
$parameters = array (
'Merchant' => MERCHANT_ID,
'MarketplaceIdList' => $marketplaceIdArray,
'ReportType' => '_GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA_',
'ReportOptions' => 'ShowSalesChannel=true'
);
$request = new MarketplaceWebService_Model_RequestReportRequest($parameters);
$request = new MarketplaceWebService_Model_RequestReportRequest();
$request->setMarketplaceIdList($marketplaceIdArray);
$request->setStartDate($t1);
$request->setEndDate(t2);
$request->setMerchant(MERCHANT_ID);
$request->setReportType('_GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA_');
invokeRequestReport($service, $request);
the ouput was :
Service Response
RequestReportResponse
RequestReportResult
ReportRequestInfo
ReportRequestId
68409017536
ReportType
_GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA_
StartDate
2018-01-05T06:55:49Z
EndDate
2018-01-05T06:55:49Z
SubmittedDate
2018-01-05T06:55:49Z
ReportProcessingStatus
_SUBMITTED_
ResponseMetadata
RequestId
1ecdc803-b26c-47a2-af0e-e598a00d379d
ResponseHeaderMetadata: RequestId: 1ecdc803-b26c-47a2-af0e-e598a00d379d, ResponseContext: 0KH8lyC6JDI3d4zFp8/qpB5ZmQJx/IVxWhOq4BLHsmELEaNWGUBNKvPZpghwlK2Q1TjAQiX5bls=, Timestamp: 2018-01-05T06:55:49.488Z
but how to fetch the fields like product name, quality, reson,SKU , etc ...,
You have requested the report.
Now you can use that request ID to check when the report has finished running. (You can test it all here before writing the php code: https://mws.amazonservices.com/scratchpad/index.html )
Go to Reports and choose GetReportRequestList and type in your requestID. This will then tell you if the ReportProcessingStatus is done or still processing. When it is done you can then get the GeneratedReportId and request the GetReport using that id. That will then give you a CSV result with your returns for the given time period from the initial report request.
If all of that looks good then you will need to add steps in your PHP code to do all of that.
Once you have requested the report you will need to save the request id and periodically (depending on your order volume, maybe check every few seconds or every minute to see if the request is done. Then you would have something like this:
$reportId = $this->invokeGetReportList($service, $request);
$reportRequest = new MarketplaceWebService_Model_GetReportRequest();
$reportRequest->setMerchant(MERCHANT_ID);
$reportRequest->setReport(#fopen('php://memory', 'rw+'));
$reportRequest->setReportId($reportId);
$resultArray = $this->invokeGetReportAllOrderData($service, $reportRequest);

How to decrypt cookie?

I've just caught a crash reported on sentry, I am trying to debug and see the root cause for the problem.
Luckily, in the cookies panel, I can see the laravel_session value that was used while crash happened.
The question, is, how can decrypt the cookie?
You can decrypt the cookie with the following code:
$cookie = 'eyJpdiI6ImFUQ0FvMWFSVlNvTmhlQjdLWGw1Z1E9PSIsInZhbHVlIjoicFh6Q09iTDl0K0huWU1Nc1NYVmxSY2hPRGU5Vk85dDJyYUpRbUVjRWg5R0JxYkVobkF3YkZVcVQrakFFUmxaVnZrTjFST3F3RTZ4akpDZEpvUFJiQXc9PSIsIm1hYyI6IjlhYmJhMTY3MWMxYWI3YjJmNmFjMmNkZWE0MWZmMmVhNTNiMjI5ZWY3NzUwNzQ0ZjAzMGQ1ZGU0YzVhNjJmZGYifQ==';
$cookie_contents = json_decode( base64_decode( $cookie, true ));
$value = base64_decode( $cookie_contents->value );
$iv = base64_decode( $cookie_contents->iv );
$clear = unserialize( \openssl_decrypt($value, \Config::get( 'app.cipher' ), \Config::get( 'app.key' ), OPENSSL_RAW_DATA, $iv));
echo "Cookie contents (Session ID): $clear\n";
You should end up with a session ID that looks something like this:
Laravel 5.1: 55782b00dbfcc3f848585ac2cefc66802d773cf5
Laravel 5.4: yPjeV74joY4MtMNNtTpeOYBP2CMixJBBChc9HRND
I didn't test with Laravel 5.3, but I'm confident it will work.
When using this code, make sure you paste the entire contents of the cookie into the $cookie variable, including the two equals signs at the end.
For laravel 6 I think it's pretty much the same
$base64_key = "base64:ISAcSPwQ0HDqqLygaS9LyPzs5ZujMAKOjBou+gyz9sw=";
$payload = json_decode(base64_decode($_COOKIE["your_cookie_name"]), true);
$iv = base64_decode($payload['iv']);
$key = base64_decode(substr($base64_key, 7));
$sessionId = openssl_decrypt($payload['value'], 'AES-256-CBC', $key, 0, $iv);
echo "Session Id: $sessionId";
But check few things:
Cipher encoding, mine is 'AES-256-CBC', it can be 'AES-128-CBC' if your key length is 16
Key format, mine start with "base64:" so I have to remove this part first

cache not getting cleared?

In my content type I have a field (field_fbunique) whose default value is 0; programatically, I change its value to 1 with below code and clear cache.
The value is changed to 1, but when admin users edit the node, the field value is displayed as 0, even though the value in the database is 1 (as expected).
However, to display it as 1, I need to clear cache manually. I have Memcached enabled.
$node = node_load($nid);
$node->field_fbunique['und'][0]['value'] = 1;
field_attach_presave('node', $node);
field_attach_update('node', $node);
$nodeurl = url('node/'. $nid);
cache_clear_all($nodeurl, 'cache_page');
entity_get_controller('node')->resetCache(array($nid));
drupal_flush_all_caches();
With help of this code to exclude form_cache from memcache_bins it started working for me:
$conf['memcache_bins'] = array( 'cache' => 'default', 'cache_form' => 'none', );

Zend Framework - session id regenerated, can't stay logged in [duplicate]

This question already has an answer here:
Duplicate DB sessions created upon Zend_Auth login
(1 answer)
Closed 2 years ago.
I'm trying to store sessions in a database using Zend Sessions however for some reason my sessions die out. Im not sure if there's some code being executed which does this or whether its something else.
I've noticed that the session ID seems to be regenerated after a breif time after having logged in.
This is even despite having added the following line in my htaccess file:
php_value session.auto_start 0
The end result is that I'm logged out every minute I'm logged in.
Heres my code in my bootstrap file
$config = array(
'name' => 'session',
'primary' => 'id',
'modifiedColumn' => 'modified',
'dataColumn' => 'data',
'lifetimeColumn' => 'lifetime'
);
$saveHandler = new Zend_Session_SaveHandler_DbTable($config);
Zend_Session::rememberMe($seconds = (60 * 60 * 24 * 30));
$saveHandler->setLifetime($seconds)->setOverrideLifetime(true);
Zend_Session::setSaveHandler($saveHandler);
//start your session!
Zend_Session::start();
I'm not using any other session related function except perhaps for Zend_Auth when logging in.
Infact rememberme calls the regenerateID function of the Session class - the end result is that I'm constantly logged out every few minutes now.
I think that you might be having this problem because you're calling rememberMe BEFORE starting the session.
You have to start the session first otherwise rememberMe won't do anything since it needs a session to set the rememberMe time on.
rememberMe calls the regenerateId function and the regeneration of the Id is what really needs the session to exist.
Place the rememberMe call after the session start then see how that works for you.
If that isn't it then I don't know what it could be since my code looks similar to yours.
Have you tried something like this?
protected function _initSession() {
$config = array(
'name' => 'session',
'primary' => 'id',
'modifiedColumn' => 'modified',
'dataColumn' => 'data',
'lifetimeColumn' => 'lifetime',
'lifetime' => 60*60*24*30,
);
Zend_Session::setSaveHandler(new F_Session_SaveHandler_DbTable($config));
}
This way the lifetime isn't set after initialising the database sessions, but is directly included in the initialisation options - it works for me, I see no reason why this should fail in your case :).
I think you need to look once into following values after bootstrap code
session.gc_maxlifetime
session.cookie_lifetime
If You configure session resources in *.ini config file, check resources.session.cookie_domain parameter.
I spend 3 hours when I remembered about it.

Resources