PHP Custom Session Handler not working on some domains - php

We have several quality domains with the identical code base. We are converting from using the native PHP session handler to a custom session handler writing the session data to MySQL. On certain domains the session handling is broken because the session data written to the database is corrupted.
At first we thought it might have something to do with different PHP levels on the different domains. However, we have ruled this out as one domain where it is not working has the same PHP level as a domain where it is working.
This question seems similar to the one at
Custom Session Handler not working on PHP5.6 but does on PHP7. However, in our case the issue is not resolved by adding session_write_close().
Here is some debugging output from the two different instances that clearly shows what is happening. In each case, first a print_r of $_SESSION is shown, followed by the contents of the session data as it will be written to the database:
On first domain designated as "local":
Before write--session data via print_r:
Array ( [debug] => Array ( [0] => Session ID e2104hafmvtur2rsof78m918gs ) [scr_width] => 2560 [recent_page_view_history] => Array ( [0] => / [1] => / [2] => / [3] => / [4] => / [5] => / ) [my_user_label_full] => Independent Sales Rep [my_user_label_short] => Rep [opp_user_type_id] => 2 [opp_user_label_full] => Principal [opp_user_label_long] => New Line [opp_user_label_long_seo] => Independent Sales Companies & New Line [opp_user_label_short] => Principal [user_value_stmt] => Industry Expertise [opp_user_value_stmt] => Sales Opportunity [with_or_as] => as an Independent Sales Rep. This guide for companies that hire reps will help you understand how to be a better rep. [is_help_open] => 1 [referrer] => / [IE_warning_given] => 1 [link_mode] => 0 [isTouchScreen] => 0 [dynamicInputWording] => point your cursor at [dynamicInputWordingCapitalized] => Point your cursor at [devicePixelRatio] => 2 )
Before write--data passed into custom session handler write():
debug|a:1:{i:0;s:37:"Session ID e2104hafmvtur2rsof78m918gs";}scr_width|s:4:"2560";recent_page_view_history|a:6:{i:0;s:1:"/";i:1;s:1:"/";i:2;s:1:"/";i:3;s:1:"/";i:4;s:1:"/";i:5;s:1:"/";}my_user_label_full|s:21:"Independent Sales Rep";my_user_label_short|s:3:"Rep";opp_user_type_id|i:2;opp_user_label_full|s:9:"Principal";opp_user_label_long|s:8:"New Line";opp_user_label_long_seo|s:42:"Independent Sales Companies & New Line";opp_user_label_short|s:9:"Principal";user_value_stmt|s:18:"Industry Expertise";opp_user_value_stmt|s:17:"Sales Opportunity";with_or_as|s:117:"as an Independent Sales Rep. This guide for companies that hire reps will help you understand how to be a better rep.";is_help_open|b:1;referrer|s:1:"/";IE_warning_given|b:1;link_mode|i:0;isTouchScreen|s:1:"0";dynamicInputWording|s:20:"point your cursor at";dynamicInputWordingCapitalized|s:20:"Point your cursor at";devicePixelRatio|s:1:"2";
The above looks as expected and the website works normally.
On second domain designated as "dev":
Before write--session data via print_r:
Array ( [debug] => Array ( [0] => Session ID v301fcrls9ijktjtlc7n4gd3n5 ) [scr_width] => 2560 [recent_page_view_history] => Array ( [0] => /landing-page.php [1] => /landing-page.php [2] => /landing-page.php [3] => /landing-page.php [4] => /landing-page.php [5] => /landing-page.php ) [my_user_label_full] => Principal [my_user_label_short] => Principal [opp_user_type_id] => 1 [opp_user_label_full] => Independent Sales Rep [opp_user_label_long] => Sales Rep [opp_user_label_long_seo] => Independent Sales Rep [opp_user_label_short] => Rep [user_value_stmt] => Sales Opportunity [opp_user_value_stmt] => Industry Expertise [with_or_as] => with Independent Sales Reps. [is_help_open] => 1 [referrer] => /landing-page.php [IE_warning_given] => 1 [link_mode] => 0 [isTouchScreen] => 0 [dynamicInputWording] => point your cursor at [dynamicInputWordingCapitalized] => Point your cursor at [devicePixelRatio] => 2 [site_user_type] => 2 [lp_source] => register-external )
Before write--data passed into custom session handler write():
pQkKjjiuhsxKkLD5bG1pcvfRiU073NotPwuYW3TrIAEwiKACrZ1s6dbIQmOeo7430UQAYgu_GENi_KhZx4vSUdaV4iXmSOVxNZgoNC_7-xDzOMDdRo7zp3sk-_aEv3XyenNiNtcy5GkE7UH1O1qKG-WBXel7bDNJ6hVUaadz9DoBwzhHFid5O5TOBT9gccwzAab2DWN-sa4vjwSDwaQ03rxquQT07iv4T_BQPvB2_pLYB_fz7GSI470o-bePEb4N209gd3oUA4xlg0Hw4pCssCN6FO6vtamNzaTqXDpS-f9nGhxpALp1eUZ1ts9nzbAZQ_llj0XbOW3FtnmnargZjbigJBWvL5XmD_bg5yIZwCHxJ4w8CWrKjasjfuInLMmzi02ViEtjmxtCZ5kLMETjE42MOSRuqrK7wr6zZFEha3gK2wfzQvrIwbr3ZEQTOpzBinYggiECiLAkpH4qy6XTjgnc-RT4_r4L7_LD2rBtXKjm3gNJgjZeLjeUMZubXBcLVGiW1ELuLgq0zHmU6ppIAMhk1rkThOMq3qgyQ0rsJGauTPDrImWzbbbnBgbooYywscjZjf-KNoRyCEaZRFga1zEeQWheEYFO7miVXFi-BSZZYJfXFHuto-kcfV9yZHInlz9p1Lcgd0YpbVUeIwZb2MUPhhzASDUnu4uuy_iVUn6WsyuEciQVYhEDcLBYJ6zHlSTs46vOWJdjE19LR8HQQL5jKJZBJpeC_jqgTNDWsVC5B1hZKpFswDZnOrUgEKOS9rHfusYOw0Ydczhr67TBTzCVUZvJVbm77LgBuY-JuLCv2Yv6mMCltXohtxMhb5t6PMXTnQTsinJD_SdY0YQZbAo26iPlO3u690IJd2tncPFZavwcflKodm_KW0LLtUR4CX4MZ0tmqY0qB1lkW8qgri6aZKAvgurr9BZhZcNqcsnAb6Po7zLdZOtwM3KF51LBzbcxGiDG6yWUy_9nw9p_y9GadXbfhfFbmR5jTQsaJLxR2-Y_2TiMxhgkWu7G2Buv6IZqUD-dCvU9vXQTnyUhlVijsO1pP02IxqtyO4D8cGp4k8l7IxeuqxsbX2oj7IdhiYIwG5t5IfEKTOQiimjPV0jSsBhwIftD5U-ofwpEQjcd7MLrzm7iX3eZuFnVvvNsMg_TCOScvs4b0DhV46KdDLfdD4WMoVhI6QnFH4s7jiqI9TYQNLRqSZNqO1cdFGHSyLcT1qGpDpZn0-ljpV_nzrYDXe6d2fsejqBZs_aWAZQFFJ7qMwUzVX53dzLgTf3ziAzPwPayQl8NBd8VptIKiVLZfN1v0tofRPuNXXVUd2s.
As you can see, rather than the special serialized version of the data, it becomes obfuscated in some way. And session handling is broken.
On a domain designated as "qa", the output is identical to "local". Please note that "local" has php 7.1, while both "dev" and "qa" have php 5.6. The php.ini files for all three domains have identical settings for session.* variables.
Question: what is the cause of the obfuscation of session data?

We found the solution. It was that Suhosin was enabled on some domains but not on others. Suhosin automatically encrypts the session data.
We will be losing Suhosin as we move forward as it appears to not be an integral part of PHP 7+. Either is is not available, or does not compile properly.

Related

How do i provide the PriceBook2Id on Order object using Sales Force phptoolkit?

I'm using PHP Toolkit for Sales Force, and it's been working great, except when i try to Create an order.
The error i receive is:
[message] => Order: bad field names on insert/update call: Pricebook2Id
Where my object field and value are:
$orderObj->Pricebook2Id = '01s4T0000027uumQAA';
---- EDIT
For those imagining the ID is wrong, when i query for pricelists on Sales Force, i receive the following in the response:
[1] => stdClass Object
(
[Id] => 01s4T0000027uumQAA
[CreatedById] => 0054T000000tM8jQAE
[CreatedDate] => 2020-02-10T15:03:33.000Z
[Description] => Produtos Scientific
[IsActive] => 1
[IsDeleted] =>
[IsStandard] =>
[LastModifiedById] => 0054T000000tM8jQAE
[LastModifiedDate] => 2020-02-10T15:19:20.000Z
[Name] => Produtos SST
[SystemModstamp] => 2020-02-10T15:19:20.000Z
)
There's no information anywhere about this problem, has anyone faced this before?
Turn out this isn't a code or permission problem, it's a validation problem from the WSDL.
If you find yourself in this kind of error with Sales Force, generate and update your WSDL as stated in:
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_quickstart_steps_generate_wsdl.htm
This should solve your field differences problems.
At leats it did for me. Thanks for all that looked in this question. Hope it helps.

Google APIs Client Library for PHP - countryBlocked exception

I've created a web application which runs with the 'Google APIs Client Library'.
This worked perfectly for me for the last two years.
But since yesterday I am facing a huge problem.
If I want to access the analytics api the system returns:
Google_Service_Exception Object
(
[errors:protected] => Array
(
[0] => Array
(
[domain] => global
[reason] => countryBlocked
[message] => This service is not available from your region
)
)
[retryMap:Google_Service_Exception:private] => Array
(
[500] => -1
[503] => -1
[rateLimitExceeded] => -1
[userRateLimitExceeded] => -1
)
[message:protected] => Error calling GET https://www.googleapis.com/analytics/v3/management/accounts/~all/webproperties/~all/profiles: (403) This service is not available from your region
)
I've checked the logs and made 50 requests the last 30 days so spamming could not be the reason for the block.
When I run it from a different Server it runs just fine.
Can anyone explain why this is happening and how I can bypass it?

Fetch Report using GoodData API

I have created a report on my GoodData UI. Now I want to fetch this report using the API. I spent hours digging the API docs but I am unable to find a simple way to do so.
If I try gdc/execute/raw/, it returns
[error] => Array
(
[parameters] => Array
(
[0] => execute
)
[requestId] => 53fPgKcFdkjf8PZ5:4n6x9lp9vk3ydbvs
[component] => GDC
[errorClass] => GDC::Exception::NotFound
[message] => resource %s not found
)
If I try gdc/xtab2/executor3 it returns
[error] => Array
(
[parameters] => Array
(
[0] => report_req
[1] => STRUCTURE INVALID - name of structure:'ReportReq'(tag:report_req), /report_req/ExecutionObject: Object does not match any alternative. Alternatives tried : [STRUCTURE INVALID - name of structure:'ReportReq' ...]
)
[requestId] => a0yRpNUpCPRsbPS0:6nagmwaw61h5g2bn
[component] => Apache::REST
[errorClass] => GDC::Exception::User
[message] => Checking '%s', result %s
)
Your requests got 404 and 400 statuses respectively.
When you tried to use 'gdc/execute/raw/' the call that reached our side was: "request="POST /gdc/execute/raw/ HTTP/1.1"", instead of that it should look like "POST /gdc/app/projects/{your_project_id}/execute/raw/ HTTP/1.1", that's the reason your are getting a 'NotFound' error. Regarding 'gdc/xtab2/executor3' there's apparently something wrong within the body of the call.
Please post your calls here, their bodies and how exactly you are making them, or open a support ticket with those details at https://support.gooddata.com/home so that we can investigate further.
Ultimately I followed this code piece https://gist.github.com/gnilrets/b9d2ce9890d8aaa07042
Much better than reading the whole GoodData API documentation.

Amazon EC2 spot instance requests seem to be throttled

I can't get more than 2 spot instances into to be fulfilled at any given time.
Requests are for m3.large Windows instances.
Request bids are above the current price for all zones in us-east-1
Account Spot Request limitation is currently 40.
Account limit for m3.large instances is 20.
If I manually request 3 I receive a status of capacity-oversubscribed for the third, always. If I cancel one of the two that are fulfilled, the third is fulfilled.
If I request 3 through the API, 2 are fulfilled and I get a status of az-group-constraint. If I cancel one of the successful requests, the third is fulfilled.
This seems like I'm hitting some kind of limitation that I'm not aware of or some kind of throttling.
This is request array I'm sending over:
Array
(
[DryRun] => false
[SpotPrice] => 0.13
[InstanceCount] => 1
[Type] => one-time
[ValidUntil] => 1418087849 // about an hour from the original request
[LaunchGroup] => d4768b0ba115414a70d2fd8ffe3e6d67 // unique to each request
[AvailabilityZoneGroup] => us-east-1
[LaunchSpecification] => Array
(
[InstanceType] => m3.large
[ImageId] => ami-34222d5c
[KeyName] => thu
[Monitoring] => Array
(
[Enabled] => false
)
[SecurityGroupIds] => Array
(
[0] => sg-31273f54
)
)

Parent nameservers

I've been trying to find out how to detect what parent nameserver is associated with a domain name. For example, when you search for a domain name using intoDNS, it displays results for both the 'normal' and parent nameservers. They mention what the parent nameserver is, like this:
k.gtld-servers.net was kind enough to give us that information.
But how did they know they had to query this specific nameserver? A few examples of what the parent nameserver is:
stackoverflow.com k.gtld-servers.net
google.com c.gtld-servers.net
ycombinator.com a.gtld-servers.net
asp.net g.gtld-servers.net
google.nl sns-pb.isc.org
google.de z.nic.de
It seems all generic TLDs can be queried at a certain subdomain of gtld-servers.net.
Right now, I find the 'normal' nameservers in PHP like this:
$nameservers = dns_get_record($domain_name, DNS_NS);
So, I'd like to know, how can I find out what the parent nameserver is for a specific domain and how can I query this using PHP?
Update
I've found out that UNIX' nslookup tool accepts a server parameter. If it's left empty, it returns the same results as PHPs dns_get_record, but if it one of the root servers for that top-level domain as specified on http://www.iana.org/domains/root/db, it will return the same results as intoDNS lists as the results of the parent server.
The only problem left is how to query this specific server, as I'd greatly prefer not to use exec() to call nslookup directly. Does anyone know of an alternative to dns_get_record which does allow you to specify the server?
I've found out how to do it. I had to use NET_DNS2 PEAR package for this, because it allows you to specificy which DNS server to use. If I specify one of the servers listed in the file nickc mentioned:
http://www.iana.org/domains/root/db
(you have to use one of the servers for the top-level domain you're querying, it doesn't matter which one)
require 'Net/DNS2.php';
$server = gethostbyname('j.gtld-servers.net'); // 192.48.79.30
$r = new Net_DNS2_Resolver(array('nameservers' => array($server)));
$result = $r->query('stackoverflow.com', 'NS');
print_r ($result);
This will print:
...
[authority] => Array
(
[0] => Net_DNS2_RR_NS Object
(
[nsdname] => ns1.webfaction.com
[name] => webassay.com
[type] => NS
[class] => IN
[ttl] => 172800
[rdlength] => 17
[rdata] => ns1webfaction�
)
[1] => Net_DNS2_RR_NS Object
(
[nsdname] => ns2.webfaction.com
[name] => webassay.com
[type] => NS
[class] => IN
[ttl] => 172800
[rdlength] => 6
[rdata] => ns2�.
)
[2] => Net_DNS2_RR_NS Object
(
[nsdname] => ns3.webfaction.com
[name] => webassay.com
[type] => NS
[class] => IN
[ttl] => 172800
[rdlength] => 6
[rdata] => ns3�.
)
)
...
This matches the nameservers listed as returned by the parent server at intoDNS: http://www.intodns.com/stackoverflow.com
The name-servers for a particular domain are those that are designated in the zone file as a "NS" record. The hosts/servers you list are global/root servers that maintain information for the particular TLD of the domain in question.
If you want to find out what those are, you could look here: http://www.iana.org/domains/root/db

Categories