How to do resume parsing in codeigniter - codeigniter

I'm riswana new to Codeigniter. And I'm trying to find out how to do parsing in Codeigniter? I've got a task: to do parsing with some piece of unknown for me symbols and put it to DB. I guess I can create DB and tables with help of mysql, but I have no idea how to do parsing and what all these symbols below mean?

You can read file using file_get_contents like below :
<?php
$filedata = file_get_contents('filepath');
echo $filedata;
?>
Using CURL
<?php
$url = "yourfilepath";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
echo $data;
?>

Related

reCaptcha V2 is now timing out during valication

I have been using reCaptcha V2 for awhile now and all of a sudden the validation is timing out on the file_get_contents line.
I can copy the URL from the error and paste it into a new window and the JSON object comes back immediately.
$url = 'https://www.google.com/recaptcha/api/siteverify?secret='. urlencode($secret) .'&response='. urlencode($captcha);
$response = file_get_contents($url);
$responseKeys = json_decode($response,true);
I fixed this timeout problem with the File_get_contents by changing to using $curl instead.
Like this:
$url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($secret) . '&response=' . urlencode($captcha);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
// file get contents not used any more
//$response = file_get_contents($url,0,stream_context_create(["http"=>["timeout"=>120]]) );
$responseKeys = json_decode($response,true);
// should return JSON with success as true

curl with laravel return session expired

I use curl with laravel and I need to launch a function inside a controller.
but when I put
dd('test');
after the namespace it's print.but when I try with the function a have a session expired
this is the code for the curl
// Préparation des données
$data = [];
$data["code__client"] = "VERTDIS13";
$data["status"] = "90";
$data["numero__incident"] = "INC544842";
// On tranforme le tableau PHP en objet JSON
$data = json_encode($data);
// Envoi au serveur
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://localhost:3000/notification/server");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "data=" . $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, true);
$server_output = curl_exec($ch);
$error = curl_error($ch);
if($error!=""){ dd($error);}
curl_close($ch);
// Ici pour tester j'affiche ce que le serveur renvoi
return $server_output;
inside the controller I tried to print data but it doesn't work
do you see the issue ?
thanks for help .
The session expired response sounds to me as if you are performing multiple consecutive curl requests to your application. If that's the case and your application depends on session cookies you can create a simple text file that is read and writeable to the script that does the curl requests, and add this to your code:
$cookie_file = "/the/path/to/your/cookiefile.txt";
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
Change the path in $cookie_file to the full filesystem path of the text file you create and curl will persist session cookies that are being returned with responses and use them in consecutive requests.
For this to work I think you should remove the line
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
because this would advise curl to ignore the cookies in the file.
Besides that I think the line
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, true);
is also obsolete, because you don't provide basic auth credentials in your curl request.
I presume you extract data from within the application?
To me, it looks like CSRF token is missing or is in fact invalid.
for ($i = 0; $i < $metas->length; $i++){
$meta = $metas->item($i);
if($meta->getAttribute('name') == 'csrf-token')
$csrfToken = $meta->getAttribute('content');
}
$headers = array();
$headers[] = "Cookie: X-CSRF-Token=$csrfToken";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
More about CSRF & cURL
Give this a go

Codeigniter hit an url and get back

I am using codeigniter 3.0 in my webapp. I want to hit an URL then get back to a view. Lets say on clicking a button, I want to hit an API then return back to the same view with success message. Can anyone help?
My API is http://wmlab.in/api/getData.php?username=web
I tried file('http://wmlab.in/api/getData.php?username=web') but it is not working.
use curl to do that and also install curl if your server did not have curl.
url="http://wmlab.in/api/getData.php?username=web";
function getUrlContent($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$data = curl_exec($ch);
echo $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return ($httpcode>=200 && $httpcode<300) ? $data : false;
}
$content=getUrlContent($url);
echo $content;
You can use file_get_contents('http://wmlab.in/api/getData.php?username=web') or can use curl;
For Curl use below code:-
$channel = curl_init();
curl_setopt( $channel, CURLOPT_URL, "http://wmlab.in/api/getData.php?username=web" );
curl_setopt( $channel, CURLOPT_RETURNTRANSFER, 1 );
$response= curl_exec ( $channel );
curl_close ( $channel );
// after curl response redirect to othe page
redirect('anypage');
For file get content use below code:-
$response=file_get_contents('http://wmlab.in/api/getData.php?username=web')
// after response redirect to othe page
redirect('anypage');
Hope it will help you.
it should be work
$result=file_get_contents('http://wmlab.in/api/getData.php?username=web');

Square Connect API - image upload - Empty Reply From Server code 52 error

Trying to get square connect API image upload working using PHP.
I used the square connect API guide: docs.connect.squareup.com/api/connect/v1/#post-image
Tried two different ways based on what I found on StackOverflow and Google searching.
Method 1) regular curl request:
https://gist.github.com/delalis/17c3c111e3b42df127ed
Method 2) using CURLFile (php >=5.5 only)
https://gist.github.com/delalis/5c7ecc2aaa024927b360
Both methods gave me this empty reply from server error:
Error: "Empty reply from server" - Code: 52
I am able to connect to square to do other functions no problem, image uploading however is proving to be quite difficult!
Any help would be greatly appreciated.
Here's a working PHP example that I usually share with people:
https://gist.github.com/tdeck/7118c7128a4a2b653d11
<?php
function uploadItemImage($url, $access_token, $image_file) {
$headers = ["Authorization: Bearer $access_token"];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ['image_data' => "#$image_file;type=image/jpeg"]);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$return_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
print "POST to $url with status $return_status\n";
curl_close($ch);
return $data ? json_decode($data) : false;
}
print_r(
uploadItemImage(
'https://connect.squareup.com/v1/me/items/ITEM_ID/image',
'ACCESS_TOKEN',
'IMAGE_FILE.jpg'
)
);
?>

how to Magento sending SMS upon creating shipment

Magento sending SMS when order confirmed and creating shipment, we have PHP code below:
<?php
$ch = curl_init();
$user="**#bindaaslo.com:**";
$receipientno="98910***";
$senderID="TEST SMS";
$msgtxt="this is test message , test"; curl_setopt($ch,CURLOPT_URL, "http://api.mVaayoo.com/mvaayooapi/MessageCompose"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "user=$user&senderID=$senderID&receipientno=$receipientno&msgtxt=$msgtxt"); $buffer = curl_exec($ch); if(empty ($buffer)) { echo " buffer is empty "; } else { echo $buffer; } curl_close($ch);
?>
open file [magento]\app\code\core\Mage\Adminhtml\controllers\Sales\Order\ShipmentController.php
find saveAction() and add your code in that
public function saveAction()
{
......................
$ch = curl_init();
$user="**#bindaaslo.com:**";
$receipientno="98910***";
$senderID="TEST SMS";
$msgtxt="this is test message , test"; curl_setopt($ch,CURLOPT_URL, "http://api.mVaayoo.com/mvaayooapi/MessageCompose"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "user=$user&senderID=$senderID&receipientno=$receipientno&msgtxt=$msgtxt"); $buffer = curl_exec($ch); if(empty ($buffer)) { echo " buffer is empty "; } else { echo $buffer; } curl_close($ch);
......................
}
Note: Don't directly change in core files instead of it override controller.
Or
you can achieve same through observer
some links help you to create observer for sales_order_shipment_save_before events
Magento - 2 or more observer on same event
https://magento.stackexchange.com/questions/847/hook-into-order-shipped-event-and-get-order-id-for-order-shipped

Resources