Solve PHP imap_open Invalid Certificate Failure

Lets say, I have a following configuration:

Incoming Server: mail.domain.com
IMAP Port: 143
Username: user@domain.com
Password: userpass

But having error while trying to connect inbox, like following code:

$inbox = imap_open('{mail.domain.com:143}INBOX', 'user@domain.com', 'userpass');

ERROR:
Can't open mailbox {mail.domain.com:143}INBOX: invalid remote specification

The solution is to use a flag “/novalidate-cert”. Its purpose is “do not validate certificates from TLS/SSL server, needed if server uses self-signed certificates”.

So this will be right call:

$inbox = imap_open('{mail.domain.com:143/novalidate-cert}INBOX', 'user@domain.com', 'userpass');

Get url parameters from url-string

Lets say, we have an url as variable. We want to parse its each parameters.
Here is a solution:

$url = 'https://www.google.co.uk/search?hl=en&tbo=d&site=&source=hp&q=skin+smoothing+cream&hl=en&ei=YqVnUu2BCYfZrQfRwYFw&start=10&sa=N';

$urlParam = parse_url($url);
print_r($urlParam);
/*
Array
(
    ['scheme'] => https
    ['host']   => www.google.co.uk
    ['path']   => /search
    ['query']  => hl=en&tbo=d&site=&source=hp&q=skin+smoothing+cream&hl=en&ei=YqVnUu2BCYfZrQfRwYFw&start=10&sa=N
)
*/

parse_str($urlParam['query'], $queryParam);
print_r($queryParam);
/*
Array
(
    ['hl']      => en
    ['tbo']     => d
    ['site']    => 
    ['source']  => hp
    ['q']       => skin smoothing cream
    ['ei']      => YqVnUu2BCYfZrQfRwYFw
    ['start']   => 10
    ['sa']      => N
)
*/

Access private Variable and private Method from outside of Class in PHP

Today I have learnt how to access private variable and private method from outside of a php class. It is by using a built-in class “ReflectionClass”.

Here is the code-snippet:

Class Demo
{
    private $myPrivateVariable = 'I am Private Variable';
	
	public function myPublicMethod()
    {
        return 'I am Public Method';
    }

    private function myPrivateMethod()
    {
        return 'I am Private Method';
    }
}

$demo = new Demo();

//$reflection_class = new ReflectionClass('Demo');
$reflection_class = new ReflectionClass($demo);

$private_method = $reflection_class->getMethod('myPrivateMethod');
$private_method->setAccessible(true);
echo $private_method->invoke($demo);
// I am Private Method

$private_variable = $reflection_class->getProperty('myPrivateVariable');
$private_variable->setAccessible(true);
echo $private_variable->getValue($demo);
// I am Private Variable

Request and Response XML for EPS Image upload using eBay LMS

Images can be uploaded to eBay using “UploadSiteHostedPictures” jobType.

Sample Request XML:

<?xml version="1.0" encoding="UTF-8"?>
<BulkDataExchangeRequests xmlns="urn:ebay:apis:eBLBaseComponents">
	<Header>
		<Version>831</Version>
		<SiteID>100</SiteID>
	</Header>
	<UploadSiteHostedPicturesRequest xmlns="urn:ebay:apis:eBLBaseComponents">
		<ErrorLanguage>en_US</ErrorLanguage>
		<Version>831</Version>
		<WarningLevel>High</WarningLevel>
		<ExternalPictureURL>http://lorempixel.com/500/400/sports/Rafiqul%20Islam/</ExternalPictureURL>
		<MessageID>SKU10000</MessageID>
	</UploadSiteHostedPicturesRequest>
</BulkDataExchangeRequests>

Here I have uploaded single image. Repeat the block “UploadSiteHostedPicturesRequest” for multiple image upload. You will have each bolck’s status individually using “MessageID” TAG.

Here is corresponding Response XML:

<?xml version="1.0" encoding="utf-8"?>
<BulkDataExchangeResponses xmlns="urn:ebay:apis:eBLBaseComponents">
<UploadSiteHostedPicturesResponse xmlns="urn:ebay:apis:eBLBaseComponents">
   <Timestamp>2013-08-22T05:02:56.805Z</Timestamp>
   <Ack>Warning</Ack>
   <CorrelationID>SKU10000</CorrelationID>
   <Errors>
    <ShortMessage>Dimensions of the picture you uploaded are smaller than recommended.</ShortMessage>
    <LongMessage>To reduce possible issues with picture display quality, eBay recommends that pictures you upload are 1000 pixels or larger on the longest side.</LongMessage>
    <ErrorCode>21916790</ErrorCode>
    <SeverityCode>Warning</SeverityCode>
    <ErrorParameters ParamID="0">
     <Value>1000</Value>
    </ErrorParameters>
    <ErrorClassification>RequestError</ErrorClassification>
   </Errors>
   <Errors>
    <ShortMessage>Quality value of the JPEG format picture you uploaded is lower than recommended.</ShortMessage>
    <LongMessage>To reduce possible issues with picture display quality, eBay recommends that pictures you upload have a JPEG quality value of 90 or greater.</LongMessage>
    <ErrorCode>21916791</ErrorCode>
    <SeverityCode>Warning</SeverityCode>
    <ErrorParameters ParamID="0">
     <Value>90</Value>
    </ErrorParameters>
    <ErrorClassification>RequestError</ErrorClassification>
   </Errors>
   <Version>837</Version>
   <Build>E837_CORE_MSA_16303079_R1</Build>
   <PictureSystemVersion>2</PictureSystemVersion>
   <SiteHostedPictureDetails>
    <PictureSet>Standard</PictureSet>
    <PictureFormat>JPG</PictureFormat>
    <FullURL>http://i.ebayimg.sandbox.ebay.com/00/s/NDAwWDUwMA==/$(KGrHqZHJEcFE1ey6gWEBSFZu!M!z!~~60_1.JPG?set_id=8800005007</FullURL>
    <BaseURL>http://i.ebayimg.sandbox.ebay.com/00/s/NDAwWDUwMA==/$(KGrHqZHJEcFE1ey6gWEBSFZu!M!z!~~60_</BaseURL>
    <PictureSetMember>
     <MemberURL>http://i.ebayimg.sandbox.ebay.com/00/s/NDAwWDUwMA==/$(KGrHqZHJEcFE1ey6gWEBSFZu!M!z!~~60_0.JPG</MemberURL>
     <PictureHeight>76</PictureHeight>
     <PictureWidth>96</PictureWidth>
    </PictureSetMember>
    <PictureSetMember>
     <MemberURL>http://i.ebayimg.sandbox.ebay.com/00/s/NDAwWDUwMA==/$(KGrHqZHJEcFE1ey6gWEBSFZu!M!z!~~60_1.JPG</MemberURL>
     <PictureHeight>320</PictureHeight>
     <PictureWidth>400</PictureWidth>
    </PictureSetMember>
    <PictureSetMember>
     <MemberURL>http://i.ebayimg.sandbox.ebay.com/00/s/NDAwWDUwMA==/$(KGrHqZHJEcFE1ey6gWEBSFZu!M!z!~~60_2.JPG</MemberURL>
     <PictureHeight>160</PictureHeight>
     <PictureWidth>200</PictureWidth>
    </PictureSetMember>
    <PictureSetMember>
     <MemberURL>http://i.ebayimg.sandbox.ebay.com/00/s/NDAwWDUwMA==/$(KGrHqZHJEcFE1ey6gWEBSFZu!M!z!~~60_12.JPG</MemberURL>
     <PictureHeight>400</PictureHeight>
     <PictureWidth>500</PictureWidth>
    </PictureSetMember>
    <PictureSetMember>
     <MemberURL>http://i.ebayimg.sandbox.ebay.com/00/s/NDAwWDUwMA==/$(KGrHqZHJEcFE1ey6gWEBSFZu!M!z!~~60_14.JPG</MemberURL>
     <PictureHeight>51</PictureHeight>
     <PictureWidth>64</PictureWidth>
    </PictureSetMember>
    <PictureSetMember>
     <MemberURL>http://i.ebayimg.sandbox.ebay.com/00/s/NDAwWDUwMA==/$(KGrHqZHJEcFE1ey6gWEBSFZu!M!z!~~60_35.JPG</MemberURL>
     <PictureHeight>240</PictureHeight>
     <PictureWidth>300</PictureWidth>
    </PictureSetMember>
    <PictureSetMember>
     <MemberURL>http://i.ebayimg.sandbox.ebay.com/00/s/NDAwWDUwMA==/$(KGrHqZHJEcFE1ey6gWEBSFZu!M!z!~~60_39.JPG</MemberURL>
     <PictureHeight>25</PictureHeight>
     <PictureWidth>32</PictureWidth>
    </PictureSetMember>
    <ExternalPictureURL>http://lorempixel.com/500/400/sports/Rafiqul%20Islam/</ExternalPictureURL>
    <UseByDate>2013-10-21T05:02:53.289Z</UseByDate>
   </SiteHostedPictureDetails>
  </UploadSiteHostedPicturesResponse>
</BulkDataExchangeResponses>

Ref: 
http://pages.ebay.com/help/sell/pictures.html

eBay LMS – Job Responses

The followings are responses from ebay LMS job requests:

<?xml version="1.0" encoding="UTF-8"?>
<createUploadJobResponse xmlns="http://www.ebay.com/marketplace/services">
  <ack>Success</ack>
  <version>1.3.0</version>
  <timestamp>2013-07-30T03:59:37.712Z</timestamp>
  <jobId>50002974683</jobId>
  <fileReferenceId>50003232563</fileReferenceId>
  <maxFileSize>15728640</maxFileSize>
</createUploadJobResponse>
<?xml version="1.0" encoding="UTF-8"?>
<uploadFileResponse xmlns="http://www.ebay.com/marketplace/services">
  <ack>Success</ack>
  <version>1.1.0</version>
  <timestamp>2013-07-30T03:59:51.846Z</timestamp>
</uploadFileResponse>
<?xml version="1.0" encoding="UTF-8"?>
<startUploadJobResponse xmlns="http://www.ebay.com/marketplace/services">
  <ack>Success</ack>
  <version>1.3.0</version>
  <timestamp>2013-07-30T04:00:04.981Z</timestamp>
</startUploadJobResponse>
<?xml version="1.0" encoding="UTF-8"?>
<getJobStatusResponse xmlns="http://www.ebay.com/marketplace/services">
  <ack>Success</ack>
  <version>1.3.0</version>
  <timestamp>2013-07-30T04:00:17.873Z</timestamp>
  <jobProfile>
    <jobId>50002974683</jobId>
    <jobType>AddFixedPriceItem</jobType>
    <jobStatus>Scheduled</jobStatus>
    <creationTime>2013-07-30T03:59:37.000Z</creationTime>
    <inputFileReferenceId>50003232563</inputFileReferenceId>
    <startTime>2013-07-30T04:00:04.000Z</startTime>
  </jobProfile>
</getJobStatusResponse>
<?xml version="1.0" encoding="UTF-8"?>
<getJobStatusResponse xmlns="http://www.ebay.com/marketplace/services">
  <ack>Success</ack>
  <version>1.3.0</version>
  <timestamp>2013-07-30T04:00:52.483Z</timestamp>
  <jobProfile>
    <jobId>50002974683</jobId>
    <jobType>AddFixedPriceItem</jobType>
    <jobStatus>InProcess</jobStatus>
    <creationTime>2013-07-30T03:59:37.000Z</creationTime>
    <errorCount>0</errorCount>
    <percentComplete>0.0</percentComplete>
    <inputFileReferenceId>50003232563</inputFileReferenceId>
    <startTime>2013-07-30T04:00:04.000Z</startTime>
  </jobProfile>
</getJobStatusResponse>
<?xml version="1.0" encoding="UTF-8"?>
<getJobStatusResponse xmlns="http://www.ebay.com/marketplace/services">
  <ack>Success</ack>
  <version>1.3.0</version>
  <timestamp>2013-07-30T04:07:03.202Z</timestamp>
  <jobProfile>
    <jobId>50002974683</jobId>
    <jobType>AddFixedPriceItem</jobType>
    <jobStatus>InProcess</jobStatus>
    <creationTime>2013-07-30T03:59:37.000Z</creationTime>
    <errorCount>0</errorCount>
    <percentComplete>95.0</percentComplete>
    <inputFileReferenceId>50003232563</inputFileReferenceId>
    <startTime>2013-07-30T04:00:04.000Z</startTime>
  </jobProfile>
</getJobStatusResponse>
<?xml version="1.0" encoding="UTF-8"?>
<getJobStatusResponse xmlns="http://www.ebay.com/marketplace/services">
  <ack>Success</ack>
  <version>1.3.0</version>
  <timestamp>2013-07-30T04:14:06.823Z</timestamp>
  <jobProfile>
    <jobId>50002974683</jobId>
    <jobType>AddFixedPriceItem</jobType>
    <jobStatus>Completed</jobStatus>
    <creationTime>2013-07-30T03:59:37.000Z</creationTime>
    <completionTime>2013-07-30T04:13:18.000Z</completionTime>
    <errorCount>0</errorCount>
    <percentComplete>100.0</percentComplete>
    <fileReferenceId>50003232573</fileReferenceId>
    <inputFileReferenceId>50003232563</inputFileReferenceId>
    <startTime>2013-07-30T04:00:04.000Z</startTime>
  </jobProfile>
</getJobStatusResponse>
<?xml version="1.0" encoding="UTF-8"?>
<downloadFileResponse xmlns="http://www.ebay.com/marketplace/services">
  <ack>Success</ack>
  <version>1.1.0</version>
  <timestamp>2013-07-30T04:14:50.612Z</timestamp>
  <fileAttachment>
    <Size>0</Size>
    <Data>
      <xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:urn:uuid:E48F27E659A1BA6E151375157703407"/>
    </Data>
  </fileAttachment>
</downloadFileResponse>
<?xml version="1.0" encoding="UTF-8"?>
<abortJobResponse xmlns="http://www.ebay.com/marketplace/services">
  <ack>Failure</ack>
  <errorMessage>
    <error>
      <errorId>21</errorId>
      <domain>Marketplace</domain>
      <severity>Error</severity>
      <category>Application</category>
      <message>The job is already in terminated states such as completed, failed and aborted</message>
      <subdomain>BulkDataExchange</subdomain>
    </error>
  </errorMessage>
  <version>1.3.0</version>
  <timestamp>2013-07-30T04:15:17.778Z</timestamp>
</abortJobResponse>
<?xml version="1.0" encoding="UTF-8"?>
<abortJobResponse xmlns="http://www.ebay.com/marketplace/services">
  <ack>Success</ack>
  <version>1.3.0</version>
  <timestamp>2013-08-19T06:46:05.842Z</timestamp>
</abortJobResponse>

USE keyword in php anonymous function

I have found a nice use of USE keyword in php anonymous function from Erik’s blog

According to his article:

The use keyword allows you to introduce local variables into the local scope of an anonymous function. This is useful in the case where you pass the anonymous function to some other function which you have no control over.
Example:

<?php
function remove_lowest_average($arr) 
{
	$average = array_sum($arr) / count($arr);

	return array_filter($arr, function($v) use ($average) {
		return ($v > $average);
	});
}

/*
following is an array with 9 elements which sum up to 45. 
Average value is 5. 
So value <= 5 will be omitted.
*/
$input = array(1,2,3,4,5,6,7,8,9);
print_r(remove_lowest_average($input));
// Output: array(6,7,8,9);
?>

How to import .txt or .csv file data into MySQL?

3 steps to follow:

Step1: Write a file publisher.txt in D: directory with following sample data:

P001;Jex Max Publication;New York;USA;New York;15;1969-12-25
P002;BPP Publication;Mumbai;India;New Delhi;10;1985-10-01
P003;New Harrold Publication;Adelaide;Australia;Sydney;6;1975-09-05
P004;Ultra Press Inc.;London;UK;London;6;1948-07-10
P005;Mountain Publication;Houstan;USA;Sun Diego;6;1975-01-01

Step 2: Create a table

CREATE TABLE publisher(
pub_id VARCHAR(50) DEFAULT NULL,
pub_name VARCHAR(50) DEFAULT NULL,
pub_city VARCHAR(50) DEFAULT NULL,
country VARCHAR(50) DEFAULT NULL,
country_office VARCHAR(50) DEFAULT NULL,
no_of_branch VARCHAR(50) DEFAULT NULL,
estd DATE DEFAULT NULL
);

Step 3: execute following MySQL command:

LOAD DATA
INFILE "D:\\publisher.txt"
INTO TABLE publisher
FIELDS TERMINATED BY ';'
LINES TERMINATED BY '\r\n'
(pub_id, pub_name, pub_city, country, country_office, no_of_branch, estd);

If you want to ignore some columns from csv (or txt), just use @dummy for those columns:

LOAD DATA
INFILE "D:\\publisher.txt"
INTO TABLE publisher
FIELDS TERMINATED BY ';'
LINES TERMINATED BY '\r\n'
(pub_id, pub_name, @dummy, country, country_office, @dummy, estd);

Relevant post:
How-to Selectively Import Data from a Data File in MySQL 5
MySQL: Row N was truncated; a solution

AFAIK

AFAIK = As far as I know
BBL = Be back later
BRB = Be right back
BTW = By The Way
CYA = See you
DIY = Do it yourself
ETA = Estimated time of arrival
ETD = Estimated time of departure
FWIW = For what it’s worth
FYI = For your information
GJ = Good job
H/O = Hold on
IMAO = In My Arrogant Opinion
IMO = In my opinion
J/K = Just joking
K = OK
L8 = Late
MMB = Message me back
NP = No problem
Pls = Please
ROFL = Rolling on the floor laughing
Sup = What’s up?
TBH = To Be Honest

SQL Injection

What it is

SQL Command Injection is a technique where an attacker creates or alters existing SQL commands to expose hidden data, or to override valuable ones, or even to execute dangerous system level commands on the database host. This is accomplished by the application taking user input and combining it with static parameters to build an SQL query.

SQL queries are able to circumvent access controls, thereby bypassing standard authentication and authorization checks, and sometimes SQL queries even may allow access to host operating system level commands.

Avoidance Techniques

  • Never connect to the database as a superuser or as the database owner. Use always customized users with very limited privileges.
  • Use prepared statements with bound variables. They are provided by PDO, by MySQLi and by other libraries.
  • Check if the given input has the expected data type. PHP has a wide range of input validating functions, from the simplest ones found in Variable Functions and in Character Type Functions (e.g. is_numeric(), ctype_digit() respectively) and onwards to the Perl compatible Regular Expressions support.
  • If the application waits for numerical input, consider verifying data with ctype_digit(), or silently change its type using settype(), or use its numeric representation by sprintf().
  • If the database layer doesn’t support binding variables then quote each non numeric user supplied value that is passed to the database with the database-specific string escape function (e.g. mysql_real_escape_string(), sqlite_escape_string(), etc.). Generic functions like addslashes() are useful only in a very specific environment (e.g. MySQL in a single-byte character set with disabled NO_BACKSLASH_ESCAPES) so it is better to avoid them.
  • Do not print out any database specific information, especially about the schema, by fair means or foul. See also Error Reporting and Error Handling and Logging Functions.
  • You may use stored procedures and previously defined cursors to abstract data access so that users do not directly access tables or views, but this solution has another impacts.
  • You benefit from logging queries either within your script or by the database itself. Obviously, the logging is unable to prevent any harmful attempt, but it can be helpful to trace back which application has been circumvented.

Reff:
http://php.net/manual/en/security.database.sql-injection.php

Tasneem – meaning of name

Tasneem means a heavenly fountain.

Tasneem is the name of one of the most honorable drinks of the inhabitants of the Paradise. It is poured on them form the heights.

Tasneem is the name of a fountain in Jannahh (Paradise) whose drink is superior to the purest of wines. Its nectar will only be drunk by those nearest to Allah Ta’ala. Literally means “rich and elevated”.

Tasneem is the name of a spring in Paradise as stated in the Glorious Quran Chapter 83 Surah Mutaffefeen verse 27 & 28:
27      With it will be (given) a mixture of Tasneem;
28      A spring from (the waters), whereof drink those Nearest to Allah.

Reff:
http://www.islamweb.net/emainpage/index.php?page=showfatwa&Option=FatwaId&Id=88629
http://wiki.answers.com/Q/What_does_the_name_Tasneem_mean_in_the_Arabic_Quran
http://www.gowister.com/islam-answer-1933.html