PHP + PayPal IPN + SQLite = a mysterious 503 error? - php

I have a simple php Paypal ipn listener which inserts the raw POST data into an SQLite (v2) database. It was working. Then...it stopped working. (I don't recall making any changes to it.) It uses a basic php sample that Paypal provides using CURL to communicate with Paypal (followed by the db insert). It just gives a 503 Service Unavailable error now.
It works (minus actually doing anything :)) if I comment out the final line, that simple contains "sqlite_exec(...)".
Alternatively, a MySQL insert works fine.Mailing results works as well.
The SQLite database appears normal. Another script reads & updates as normal.
Web host sees no issues on the server side.
Can anyone make sense of this?
Or maybe there is a way to send the POST data to another script so that it gets processed separately, on its own, instead of altogether as one page?
Update: What I'm trying to insert is the "raw post data" string...
$raw_post_data = file_get_contents('php://input');
...as seen on the top line here under php sample code: https://www.x.com/developers/PayPal/documentation-tools/code-sample/216623 . My script is the same except with an insert at the bottom, which basically looks like this:
$dbloc = "/db/ipn.sqlite";
if($db = sqlite_open("$dbloc", 0666, $sqlite_error)){}else{die ($sqlite_error);}
$datetime = date("Y-m-d H:i:s");
$data = $raw_post_data;
$sql="INSERT INTO Paypal (entrydate,verified,data) values ('$datetime',$verified,'$data')";
sqlite_exec($sql,$db);

From when are you getting this error ?
Paypal has done some IPN changes recently.
please check this links:
https://www.x.com/content/bulletin-ipn-and-pdt-scripts-and-http-1-1
http://www.tipsandtricks-hq.com/forum/topic/paypal-ipn-and-pdt-changes-effective-from-1st-february-2013
please let us know what you are trying to insert into the db.

Related

PHP and Google's reCaptcha v2 - empty response every time

We have a contact.html form that uses reCaptcha v2, whose backend processing is in a php file.
I've taken enough steps to understand that when we send the verification to google's api, the response comes back empty. Below is code that gave me this proof.
$url = 'https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST["g-recaptcha-response"].'&remoteip='.$_SERVER['REMOTE_ADDR'];
$verify = file_get_contents($url);
echo $url;
if (empty($verify)) echo 'Failed to fetch data';`
However, when I manually enter the url into a browser, I get a JSON response back that indicates success.
What, then, is the difference? Why would file_get_contents return empty if a simple get request from a Chrome browser give me trouble?
I have read that file_get_contents is synchronous, so I wouldn't expect this is just a noob error on waiting for the response.
Any help would be appreciated, this is my very first time working with PHP. It's not hard, but I may be missing something vital.
Sorry everyone, I can't understand why, but the problem was in the method used to access the site verify.
Using curl syntax, I finally got it working.
Change the configuration in php.ini file and don't need curl.
allow_url_fopen=0 to allow_url_fopen=1

Json data from php API at online hosting

I need your advice. I made API in php to communicate with my android application and mySQL database. Now I wanna put this api on free online hosting with free database, the problem is that when i make query for that API I'm receiving my json data with junk from hosting like HTML tags and commercial text "[hosting name] free hosting". When my app receives this data, it shuts down. Everything works fine on local wamp server but at online hosting my app is crashing
I have 3 questions for you
Is it normal on free hosting or maybe my API is wrong designed?
If I put my php files on paid serwer will I avoid this additional stuff added by hosting company?.
Check out part of my sample user registration php code
$new_sql_select_query = "select * from userinfo where userName like '$userName' and userEmail like '$userEmail';";
$sql_all_data = mysqli_query($con, $new_sql_select_query);
$userDataJson = array();
while ($row = mysqli_fetch_array($sql_all_data)) {
$userDataJson["userId"] = $row["userId"];
$userDataJson["userName"] = $row["userName"];
$userDataJson["userEmail"] = $row["userEmail"];
$userDataJson["accountBalance"] = $row["accountBalance"];
}
$responseJson["success"] = 1;
$responseJson["message"] = "User correctly added to base!";
array_push($responseJson["user"], $userDataJson);
echo json_encode($responseJson);
I have an idea but I do not know how to do it correctly. I am generating a new json data file by code below
$myjson = json_encode($responseJson);
file_put_contents('myfile.json', $myjson);
but here is another problem, my app need to be somehow redirected to this new file because right now my app is connecting directly to a specific php file in this case CreateNewUserDB.php so how should I do it?. Should I return link to this generated json file to my app and then make another connection but this time to this "myfile.json" file?. Waiting for answers.
Regards
The reason that your app might be crashing is that when you do send response to your app on localhost, then only json data is sent. But as you said on the free hosting, you got some html. When your java code tried to make a json object out of it, it must have thrown an exception and hence the error.
There are plenty of free hosting, that are good and don't do these type of advertisements. https://www.biz.nf/ is one of them. I used it in my early years. Also paid hosting will not give you problems like these
This is an old thread, but I had a similar problem recently.
I uploaded my php json api in my shared hosting and solved the problem setting the right format by adding the header for json in the php file:
header('Content-Type: application/json');
I encourage you to work with Firebase, it will handle all the background staff for you, and it gives you access to the database also, besides that, it's very fast comparing to regular databases.

How to get webhook data into query string to be read by a custom php script?

I have a custom script in php that is intended to receive a webhook from a 3rd party CMS (specifically FLG360), search the source for records that match a given field name in the query string (using $_GET), and return/display the results.
When going to the full URL (including the query string) manually, the query string is read by the script and the correct actions are performed.
However, when sending the webhook from the CMS, it does not seem to be able to find or read the query string.
Here's the part of my script that I expected to be reading and actioning the webhook via simple $_GET requests:
$IDtoSearch = $_GET['company'];
$status = $_GET['status'];
Is pulling data from a webhook via php as simple as performing some $_GET requests? I have confirmation from the CMS support team that the webhook is definitely formatted as a query string.
I have added this to the script, in order to record any existing query string to the server's error log:
//capture the webhook and save to error log
$webhookContent = "";
$webhook = fopen('php://input' , 'rb');
while (!feof($webhook)) {
$webhookContent .= fread($webhook, 4096);
}
fclose($webhook);
error_log($webhookContent);
...which is doing its job. Here's what I find in the logs after firing a webhook from the CMS:
eventtype=workflow&eventdatetime=2016-07-29+15%3A16%3A06&eventuserid=&eventusername=&id=109355632&subid=&ipaddress=217.33.80.130&received=2016-06-17+15%3A50%3A37&leadgroupid=49625&leadgroupname=zzALEX+TEST+Applicants+collections&leadtype=FIDOR+Applicant&status=Pre+Default+Applicant+%2336731&progress=Accepted&siteid=16515&sitename=FIDOR+Applicant&userid=32197&username=Aimee+Davies&buyerid=&buyername=&buyerreference=&introducerid=46437&introducername=Alex+Test+cases&reference=&source=FIDOR&medium=&term=&cost=0.00&value=0.00&transferdatetime=0000-00-00+00%3A00%3A00&transfersuccessful=No&xmldatetime=0000-00-00+00%3A00%3A00&xmlfails=0&xmlresult=&xmlreference=&appointmentdatetime=&appointmentnotes=&lastnotedatetime=0000-00-00+00%3A00%3A00&lastnote=&taskexists=No&workflowexists=Yes&dropbox=l109355632.d675cdbf4f75f7d9c6ee99a6b7034b7c%40msrvr.net&fullname=Mr.+Alex+Connor&title=Mr.&firstname=Alex&lastname=Connor&company=TFS9876543&jobtitle=&phone1=&phone2=&fax=&email=&address=&address2=&address3=&towncity=&postcode=&dob=&dobday=&dobmonth=&dobyear=&contacttime=&contactphone=Unknown&contactfax=Unknown&contactemail=Unknown&contactmail=Unknown&data1=&data2=&data3=&data4=&data5=&data6=&data7=&data8=&data9=&data10=&data11=&data12=&data13=&data14=&data15=&data16=&data17=&data18=&data19=&data20=&data21=&data22=&data23=&data24=&data25=&data26=&data27=&data28=&data29=&data30=&data31=&data32=&data33=&data34=&data35=&data36=&data37=&data38=&data39=&data40=&data41=&data42=&data43=&data44=&data45=&data46=&data47=&data48=&data49=&data50=&type1=Work+Telephone+Number&type2=TFS+Number&type3=Current+loan+balance&type4=Contracted+Monthly+Payment+Amount&type5=Last+payment+date+received&type6=Last+amount+received&type7=Next+scheduled+payment+date&type8=Current+Arrears+figure+incl+Legals%2FCharges&type9=Current+Payment+method&type10=Guarantor+is+deceased&type11=Guarantor+has+entered+DMP%2FBKO%2FIVA+&type12=Spare&type13=Actual+receipts+to+date&type14=Applicant+flat+number&type15=Applicant+house+name&type16=Applicant+house+number&type17=Guarantor+relationship+to+main+applicant&type18=Guarantor+First+Name&type19=Guarantor+Last+Name&type20=Joint+App+First+Name&type21=Joint+App+Last+Name&type22=Applicant+has+entered+DMP%2FBKO%2FIVA&type23=Current+Vienna+Status&type24=Solicitors&type25=Legal+Status&type26=Number+of+Months+in+Arrears&type27=Promise+To+Pay+DATE+%28dd%2Fmm%2Fyyyy%29&type28=Promise+To+Pay+AMOUNT&type29=Loan+Final+payment+date+%28dd%2Fmm%2Fyyyy%29&type30=Agreement+signed+date+%28FOR+DEFAULT%29+-+dd%2Fmm%2Fyyyy&type31=Default+expiry+date+%28dd%2Fmm%2Fyyyy%29&type32=Less+Rebate+of+interest+%28amount+from+settlement+letter%29&type33=Sum+Required+to+repay+loan+%28Amount+from+settlement+letter%29&type34=Default+ISSUED+date+%28dd%2Fmm%2Fyyyy%29&type35=Arrangement+Amount&type36=Arrangement+Start+Date+%28dd%2Fmm%2Fyyyy%29&type37=Arrangement+Type&type38=Arrangement+Term&type39=Arrangement+Monthly+Shortfall&type40=spare&type41=spare&type42=spare&type43=spare&type44=spare&type45=DMP%2FIVA+offer+of+Repayment&type46=Reasons+for+Arrears&type47=OFS+LETTER+3+DATE+%28dd%2Fmm%2Fyyyy%29&type48=IBC+Referance&type49=Restriction+or+Charging+order&type50=IMPORTANT+NOTES
All the information from the CMS record seems to be coming in, just not being read or recognised as a query string by my script.
Here's what I get when manually entering a query string on the URL:
, referer: https://www.domain.com/flg/index.php/?company=cream&status=cheese
Not sure what the ", referer:" part means, or why this error is being logged with the full URL as opposed to the above.
Hope somebody can help with this, I'm tearing my hair out.
Please let me know if you need any additional information.
Many thanks.
U can use parse_str() on $webhookContent
Credit to #Aleksej in the comments for this - it was as simple as changing the GET to POST. Problem solved, the script is now doing its job.

mssql_execute causing Error code: ERR_EMPTY_RESPONSE

I am having an issue with a site that I am moving onto a new server. This site is connected to a SQL Server database, and is working correctly in it's current location. However, the new location is having problems with a single mssql_execute. Here is a sample of the code:
function get_customer_select_info() {
$link = get_db_link();
$customer_all_command_text = "dbo.Customer_All";
$customer_all_stmt = mssql_init($customer_all_command_text, $link);
$search = "%";
mssql_bind($customer_all_stmt, "#parm1", $search, SQLVARCHAR, false, false, 15);
$result = mssql_execute($customer_all_stmt);
mssql_free_statement($customer_all_stmt);
return $result;
}
Calling the above function results in
Unable to load the webpage because the server sent no data.
Error code: ERR_EMPTY_RESPONSE
from Chrome.
get_db_link retrieves a new connection to the database, or returns the current one if it already exists. It is functioning correctly. I have tried just closing the link and creating a new one if one already exists, which had no effect on the error.
This is not a problem connecting to the database because before this stored procedure is executed, three others are called and executed correctly.
Another complication is that running a trace on the given database results in this stored procedure getting called on the database and being successful!
Commenting out the mssql_execute makes the page load correctly (minus the information that this function returns).
Again, the same exact code on the current server works correctly, but the code on the new server is causing problems. I can't obtain any debugging information from apache or php because it is not actually sending anything.
If you facing ERR_EMPTY_RESPONSE then i will suggest you to follow these steps
Refresh page and restart browser
Clean your cache and browser cookies
Check internet connection
Update Google Chrome
Check router
I am also sharing video tutorial where you will find the complete solution of given steps to resolve your problem here is the link
http://vimeo.com/60824619
Best of luck

Certain strings not reaching PHP via GET

I'm working with a very simple mock-up application to query a DB and display the results on a map. The application sends a GET httprequest to a server which returns a serialized array of value. The basic structure of the httprequest is:
httpRequest.open("GET","handle-query.php?query=" + queryJs)
and, on the other side:
$queryPhp = $_GET["query"];
When the query looks like this...
["SELECT%SUM(commit)%FROM%financialdata%WHERE%region='Centre'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%region='Kara'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%region='Maritime'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%region='Plateaux'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%region='Savanes'"]
...then it is passed to the server properly, and generates a response. However, when the query looks like this...
["SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Sotouboua'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Tchamba'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Tchaoudjo'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Assoli'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Bassar'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Bimah'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Doufelgou'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Keran'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Kozah'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Golfe'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Lacs'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Vo'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Yoto'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Zio'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Amou'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Haho'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Kloto'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Ogou'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Wawa'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Oti'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Tone'"]
...then the server receives an empty string. Both of the strings are generated by the same function, and both work perfectly on my virtual server (WAMP). If anyone has any ideas it would be greatly appreciated.
(P.S. After reading I realize that I should be using a framework with better sanitization, etc., but this is just a demo that will need to live online for maybe 2 hours, and it would be better to fix this small thing than start over. It works perfectly on my localhost.)
To actually answer your question, you're sending a get parameter as query (handle-query.php?query=) and then pulling it off as queryJS (queryJs).
$_GET['query'] // instead of $_GET['queryJs']
should do it.
(And as everyone has pointed out, don't send SQL in the clear or otherwise over the wire, unless you plan on not actually executing the SQL, and you just like to advertise your db structure, maybe it is that pretty.)

Categories