Jump to content

Search the Community

Showing results for tags 'curl'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (Dreamweaver, Zend, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 19 results

  1. Hey guys i need help with a CURL code. I need to retreive all the data in a table located at http://www.listenlive.nl/tvgenre.php?g=1&page=0 and parse the data to finish with an array that looks like this: $row[0][station_name] = '3BTV'; $row[0][stream_link] = '420'; $row[0][stream_type] = 'wma'; $row[0][country] = 'United Kingdom'; $row[0][genre][0] = 'Variety'; $row[0][genre][1] = 'Alternative'; $row[0][genre][2] = 'Culture'; $row[0][rating] = '1/5'; I need that for each rows of the table where the first array number would increment $row[1], $row[2] ... My PHP code is incomplete. I currently have a loop for all the TR's of the page ... and when i loop all the TD's inside the TR's it returns a load of crap ... I am unsure where to go from here. Any help would be apreciated thx This is my code: $ch = curl_init(); $categ[url] = 'http://www.listenlive.nl/tvgenre.php?g=1&page=0'; curl_setopt($ch, CURLOPT_URL, $categ[url]); curl_setopt($ch, CURLOPT_POST, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies); curl_setopt($ch, CURLOPT_COOKIE, $cookies); curl_setopt($ch, CURLOPT_REFERER, $categ[url]); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_USERAGENT, $nav); $data2 = curl_exec($ch); $dom2 = new DOMDocument(); libxml_use_internal_errors(true); $dom2->loadHTML($data2); $trs = $dom2->getElementsByTagName('tr'); foreach ($trs as $tr) { echo "<pre>"; print_r($tr); echo "</pre>"; }
  2. I need to send a cURL request containing a file to upload as well as a JSON string. I can get a properly formatted request when sending the JSON, but the file is throwing it off. $curl_file_object = '@'.$tmp_name $postData= array( 'JSON'=> json_encode($jsonParams), $reference => $curl_file_object, ); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $target); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // stop verifying certificate curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data;")); curl_setopt($curl, CURLOPT_POST, true); // enable posting curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); // post data curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // if any redirection after upload $response = curl_exec($curl); $info = curl_getinfo($curl); curl_close($curl); debug($info); Am I the first one needing to send file binary data along with a json string to a server at the same time?
  3. hi everyone, thanks in advance. i have one issue regarding cookie based authentication with curl. i have an application which calls a third party php url for user registration and authentication. when we called athentication with third party url using curl the result shows succes and cookie is building. again i need to call another url from same third party server which displays a flash. once the authentication is success the flash automatically logins. but for me flash ask for username and password, it should n't be like that. i hope my curl call not building cookie in right format. please check my code and give suggestions. <?php $result=$name=$pass=""; $name= $_SESSION["name"]; $pass=$_SESSION["pass"]; $ch = curl_init(); $cookie_file_path = 'my_cookie.txt'; $cookie_file_path = realpath($cookie_file_path); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); curl_setopt($ch, CURLOPT_VERBOSE, TRUE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //new ones curl_setopt($ch, CURLOPT_HEADER, 1); // here i am calling third party url for athentication curl_setopt($ch, CURLOPT_URL,"http://thirdpartyserver.com/checksession.php?username=".$name."&passme=".$pass); $result= curl_exec ($ch); if ($result==true) { //here i am calling the third party flash which is embed in this page. flash should automatically login with cookie. header( "refresh:1;url= http://myserver/testfolder/flashLoader.php" ); } ?> please let me my code is correct, and thanks for your suggestions. thanks vinz
  4. Hi guys, I wanted to make a script login to the website Marktplaats.nl, but it doesn't seem to work.. At the moment I can't post the code as it's on my laptop. Does anyone know how to login and maybe do other stuff on Marktplaats.nl with cURL? Kind regards, Kevin Ruhl.
  5. Fellow Php'ers, I'm a php learner. Beginner. Very enthusiastic enough to try to build my own web proxy. See how far I have reached. The following is cURL. It shows you a ui text box where you type a url and cURL would fetch that url. 1. Now, in that fetched url, there could be links like so: <a href="http://www.google.com">Google</a> <a href="http://yahoo.com">Yahoo</a> This script is supposed to precede 'proxified_page_test.php?url_to_proxify=' on all links. So now, the links present on the proxified page (cURL fetched page) should look like this: <a href="proxified_page_test.php?url_to_proxify=http://www.google.com">Google</a> <a href="proxified_page_test.php?url_to_proxify=http://yahoo.com">Yahoo</a> 2. Also, in that fetched url, there could be a search box, like the google search box. Search box containing search box code like so ... "....action = http://google.com/q?" Again, this script is supposed to precede 'proxified_page_test.php?url_to_proxify=' on all links including on those forms that forward you to their processor.php. So now, the links present on the proxified page (cURL fetched page) should look like this: "....action = proxified_page_test.php?url_to_proxify=http://google.com/q?" That way, if you do a search on the proxified page then the SERPs presented would contain links where proxified_page_test.php?url_to_proxify= have been added. That way, if you were viewing google and doing a search, the SERPs presented would list links that precede the "proxified_page_test.php?url_to_proxify=" so that the result links can also be proxified when clicked. ISSUE Problem is, if you type "http://www.google.com" then it does not fetch that page. What is hindering the fetch ? <?php /* ERROR HANDLING */ declare(strict_types=1); ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL); /* STEP 2: The IF gets triggered as soon as the "submit" button is clicked in the ui text box labeled: Url Following IF code deals with GET method. */ if(isset($_GET["url_to_proxify"]) === TRUE) { echo "IF got triggered!"; $url_to_proxify = filter_input(INPUT_GET, 'url_to_proxify', FILTER_VALIDATE_URL); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "$url_to_proxify"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_HEADER, 5); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $curl_result = curl_exec($ch); $domain = parse_url($url_to_proxify, PHP_URL_HOST); echo var_dump($domain); //Add proxy link on all links present on proxified page $pattern = array("http://", "https://", "http://www.", "https://www.", "localhost"); $replace = array("proxified_page_test.php?url_to_proxify=http://\".$domain\"", "proxified_page_test.php?url_to_proxify=https://\".$domain\"", "proxified_page_test.php?url_to_proxify=http://www.\".$domain\"", "proxified_page_test.php?url_to_proxify=https://www.\".$domain\"", "proxified_page_test.php?url_to_proxify=http://www.\".$domain\""); $string_replaced_data = str_replace($pattern, $replace, $curl_result); echo var_dump($string_replaced_data); //Add proxy link on all Image Links (Eg. Google Img File) $pattern = array('src="', 'src = "', 'src= "', 'src ="', "src='", "src = '", "src= '", "src='"); $replace = array('src="proxified_page_test.php?url_to_proxify=\".$domain\""', 'src = "proxified_page_test.php?url_to_proxify=\".$domain\""', 'src= "proxified_page_test.php?url_to_proxify=\".$domain\""', 'src ="proxified_page_test.php?url_to_proxify=\".$domain\""', "src='proxified_page_test.php?url_to_proxify=\".$domain\"'", "src = 'proxified_page_test.php?url_to_proxify=\".$domain\"'", "src= 'proxified_page_test.php?url_to_proxify=\".$domain\"'", "src ='proxified_page_test.php?url_to_proxify=\".$domain\"'"); $string_replaced_data = str_replace($pattern, $replace, $curl_result); echo var_dump($string_replaced_data); //Add proxy link on all links presented by the searchengine result pages (SERPS). Eg. Google Search Pages (SERPs) $pattern = array('action="', 'action = "', 'action= "', 'action ="', "action='", "action = '", "action= '", "action='"); $replace = array('action="proxified_page_test.php?url_to_proxify=\".$domain\""', 'action = "proxified_page_test.php?url_to_proxify=\".$domain\""', 'action= "proxified_page_test.php?url_to_proxify=\".$domain\""', 'action ="proxified_page_test.php?url_to_proxify=\".$domain\""', "action='proxified_page_test.php?url_to_proxify=\".$domain\"'", "action = 'proxified_page_test.php?url_to_proxify=\".$domain\"'", "action= 'proxified_page_test.php?url_to_proxify=\".$domain\"'", "action ='proxified_page_test.php?url_to_proxify=\".$domain\"'"); $string_replaced_data = str_replace($pattern, $replace, $curl_result); echo var_dump($string_replaced_data); print_r($curl_result); curl_close($ch); } else { echo "ELSE got triggered!"; //Html Form ?> <html> <body> <form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method = "GET"> Url: <input type = "text" name = "url_to_proxify" /> <input type = "submit" /> </form> </body> </html> <?php } ?>
  6. Php Guys, Are you aware of any function or method where I can prevent downloads ? Imagine a page with a lot of links. Like: links to pages and links to imgs or links to downloads. Now, imagine I fetched that page with curl and the user is viewing the links present on the page. Q1a. Now, if I were to prevent any downloads from the download links. How would I do it ? Q1b -. Any php function that manages this prevention ? Q1b - If not, then any workarounds you can think of ? I'm thinking of str_replacing the download links so they no longer showup as download links but as something else such as nothing. Q2a. How would you get your cURL script to spot a download link and get it to not appear on your user's screen ? Q2b. Would you get the script to check for the file extension that would reveal if it's a viewable file (html page, img file, etc.) or a downloading file ? Q2c. What are the long list of download file extensions ? When I cURL fetch or build my own web proxy or build my crawler, have to make sure they ignore download links.
  7. I've been puzzling over this for a few days now, and the Siteground L2 support isn't willing to help out here. I'm coding a Wordpress plugin to get affiliate tracking links from Tune/HasOffers. This is totally acceptable behavior AFAIK, and all I have to do is call a URL, and I'll be redirected to a landing page with whatever parm values I've specified. I have a development Linode, where this script works as expected. You can see the output here: http://new.burtlo.info/wp-content/plugins/lmpostback/test.php I've installed that same script on Siteground, but I get a zero length response: http://launchmoxie.com/wp-content/plugins/lmpostback/test.php I've tried a number of variations on making the call, and have tried a number of curl options as well. I'm still stuck. Any suggestions? Thanks in advance. Here's the code: <?php $aff_link = 'http://jump.launchmoxie.com/aff_c?offer_id=26&aff_id=793'; // create a new cURL resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $aff_link); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); // grab URL and pass it to the browser $response = curl_exec($ch); print_r ($response); echo 'strlen of response = ' . strlen($response); // close cURL resource, and free up system resources curl_close($ch); ?>
  8. I have two domains - http://domaina.com, http://domainb.com I'm calling domainb.com's url from domaina.com: file_get_contents('http://domainb.com/a.php'); In http://domainb.com/a.php, I'm trying to creating a session or cookie for domainb.com <?php setcookie("key", "value", time()+3600); session_start(); $_session["key1"] = "value1"; ?> But this code is not working. Please help in solving this issue. Thank you.
  9. Hello everybody I;m trying to post data to my facbook page (not on my profile wall) but whenever i try it keeps getting posted in my fan page but in different place . I want to post it using My Page name i the wall but it is getting posted in this section (in the left panel of my page..) I want to show in the page wall like all the posts is showing... Here is the script that i've used $touid = "xxxxxxxxxxxxxxxxx"; // This is the page id i'm using $token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // my access token of that page $msg = "Hello again"; $title = "TItle"; $uri = "http://www.google.com"; $desc = "description"; $pic = "http://i.imgur.com/JCdGh.png"; $action_name = "Google"; $action_link = "http://www.google.com"; echo FB_wallpost_wosdk($touid, $token, $msg, $title, $uri, $desc, $pic, $action_name, $action_link); function FB_wallpost_wosdk($touid, $token, $msg, $title, $uri, $desc, $pic, $action_name, $action_link){ if ( ($touid !="") && ($token !="") && ($msg != "") && ($title != "") && ($uri != "") && ($desc != "") && ($pic != "") && ($action_name != "") && ($action_link != "") ) { $url = "https://graph.facebook.com/".$touid."/feed"; $attachment = array( 'access_token' => $token, 'message' => $msg, 'name' => $title, 'link' => $uri, 'description' => $desc, 'picture'=>$pic, 'actions' => json_encode(array('name' => $action_name,'link' => $action_link)) ); // set the target url $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output $result = curl_exec($ch); curl_close ($ch); return $result; } else { return 0; } } My Access tokens have this scopes.. Whenever i post anything it getting posted as a visitors post in my fan page.... Pleas help guys... THank in advance....
  10. Hello, I want to download flight from Wizzair page. I've checked all headers which are sended when browser "create" request (the same which Ryanair few months ago). It looks like this in my browser: I'm entering at https://wizzair.com/pl-PL/Search, select everything (from-to, date arrival and departure) then click "Send" and I've got results. I've checked headers and I can see, that theres two requests to the following pages: 1) Search (here is created session ID saved in cookie, i've also sent POST parameters here), it returns error 302 then redirect to: 2) Select (theres no any post or get parameters, just requested session ID created before) and return results with flights. I was trying to achieve the same results by curl. I created curl request with the same POST parameters to Search page. I save sessionId to cookie, also create the same cookies as in browser. Then enter to Select page, use cookies saved before but nothing happens. First request return 302 error (the same happen in brower) Second request returns default Wizzair website without flight results If I use sessionId generated in my browser (not from curl request), second request show me correct results. Why it doesn't work in curl? Is there any request processed and saved JavaScript which is not processed by curl method? Code from my first requst where i'm sending post parameters in request $fields = array( 'cookiePolicyDismissed' => 'true', '__EVENTTARGET' => 'HeaderControlGroupRibbonSelectView_AvailabilitySearchInputRibbonSelectView_ButtonSubmit', '__VIEWSTATE' => '/wEPDwUBMGQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgEFXEhlYWRlckNvbnRyb2xHcm91cFJpYmJvblNlbGVjdFZpZXckQXZhaWxhYmlsaXR5U2VhcmNoSW5wdXRSaWJib25TZWxlY3RWaWV3JFN0dWRldFNlbmlvckdyb3VwwAw35gayQedhYJ8oz+CHlR8x2gWGvNOEfHfCOBjF/lk=', 'cff49415-63b6-4d31-b273-5eab61b6c327' => 'e2df7ef6-3abf-4eab-8110-51c30f30109a', 'HeaderControlGroupRibbonSelectView%24AvailabilitySearchInputRibbonSelectView%24OriginStation' => $from, 'HeaderControlGroupRibbonSelectView%24AvailabilitySearchInputRibbonSelectView%24DestinationStation' => $to, 'HeaderControlGroupRibbonSelectView%24AvailabilitySearchInputRibbonSelectView%24DepartureDate' => $dateStart, 'HeaderControlGroupRibbonSelectView%24AvailabilitySearchInputRibbonSelectView%24ReturnDate' => $dateBack, 'HeaderControlGroupRibbonSelectView%24AvailabilitySearchInputRibbonSelectView%24PaxCountADT' => '1', 'HeaderControlGroupRibbonSelectView%24AvailabilitySearchInputRibbonSelectView%24PaxCountCHD' => '0', 'HeaderControlGroupRibbonSelectView%24AvailabilitySearchInputRibbonSelectView%24PaxCountINFANT' => '0', 'WizzSummaryDisplaySelectViewRibbonSelectView%24PaymentCurrencySelector' => '00000000-0000-0000-0000-000000000000FULL', 'HeaderControlGroupRibbonSelectView%24AvailabilitySearchInputRibbonSelectView%24ButtonSubmit' => 'Szukaj'); //url-ify the data for the POST foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string,'&'); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0'); curl_setopt($ch, CURLOPT_HEADER,1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE_FILE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Host: wizzair.com', 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/*;q=0.8', 'Accept-Language: pl,en;q=0.7,en-us;q=0.3', 'Connection: keep-alive' )); curl_setopt($ch,CURLOPT_POST,count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); //execute post $result = curl_exec($ch); curl_close($ch);
  11. Hi, I have a PHP script using the cURL function. This script send the data by a web service. It works often without problem. Sometimes, he sent a double data : same data by two times. I checked the log file this script (by curl_getinfo) on "total_time" When this script works correctly (it send the data only one time) : the total_time is less than 6 second. but when the total_time is more than 7 second, (this is a casual/occasional situation), my script send same data by two times so it is double data! So the web service send the ACK(Acknowledgment) which takes a long time (more than 7 second) and then, the TCP send again same data to a web service. How can I avoid this doubling ? By increasing this time waiting / time limit ? How can I define this time limit for 12 second? Could you help me : Thanks
  12. I have never used cURL before and have hit a roadblock in my learning. I am trying to make a HTTP GET request to my Wowza server which uses the Rest API to return JSON results. I have authentication set to none on the server at the moment until I can get the script working. I have tested the code below with an external website and it works but, when I try to use it with the URL from the server with the Rest API it just times out. I can make the request in a browser fine, just not from the code. What am I missing or not doing correctly? $ch = curl_init("http://IP_TO_SERVER:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/instances/_definst_/incomingstreams/ncopeland"); // such as http://example.com/example.xml curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 0); $data = curl_exec($ch); curl_close($ch); print $data; The response should be this. { "serverName": "_defaultServer_", "sourceIp": "ncopeland", "isPTZEnabled": false, "applicationInstance": "_definst_", "name": "ncopeland", "isRecordingSet": false, "isStreamManagerStream": true, "isPublishedToVOD": false, "isConnected": true, "ptzPollingInterval": 2000 } -Thanks!
  13. Folks, Usually cURL works on my xampp. So, why not tonight ? I see white blank page! <?php /* ERROR HANDLING */ declare(strict_types=1); ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $url='https://oscarliang.com'; $ch=curl_init(); $timeout=5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // Get URL content $lines_string=curl_exec($ch); // close handle to release resources curl_close($ch); //output, you can also save it locally on the server echo $lines_string; ?>
  14. Hi! I'm trying to make an button that when it's pressed sends an http post to my home server. But my home server is runing on port 84 and i think that i'm not being able to send the post correctly because of this port. any help? my code now is this: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://homeserver.net:84/?device=35"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); The way I have the URL is correct? thanks!
  15. Hey Guys, I'm just starting to learn Curl so that I connect to an API. At the moment I have this php code: <?php //******************************************************************************// // // //THIS FILE TAKES A CURRENT JOB AND ADDS IT TO A PAL LABEL PROJECT // // // //******************************************************************************// // ******* TURN ON ERROR REPORTING *****// error_reporting(E_ALL); ini_set('display_errors', '1'); //**** SET THE HEADERS UP FOR AUTHENTICATION *****// $headers = array(); $headers[] = "X-SUBDOMAIN:XXXXXXXXXXX"; // Set the sub domain $headers[] = "X-AUTH-TOKEN:XXXXXXXXXX"; // Set the API Code $headers[] = "application/json"; $total = 50; // this is the max number of pages we will search. with 100 items on a page, and 100 items that means we can return 10,000 items $curl = curl_init(); //**** WE GET ALL OF THE ITEMS CURRENTLY IN THE CURRENT PROJECT AND PUT THEIR UNIQUE ID INTO THE ASSETS ARRAY ***// curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); curl_setopt($curl, CURLOPT_URL, 'https://api.current-rms.com/api/v1/products?page=1&per_page=100'); // allows up to 1 million products curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); // Send the request & save response to $resp $resp = curl_exec($curl); // Convert the response to an array $obj = json_decode($resp, true); // The Obj array currently contains every item in the DB and loads of useless info. We need to extract just the ID and the Name! If I print_r the $obj variable it returns this: I have cut the output down a bit, each item in the products array is about 50 lines long, The only information I actually need to recall is the first two lines which is [id] and the [name]. Is there a simple way that I can do this? So far I have tried to do a Foreach loop and create a new array, but this take a very long time (there are about 600 records!) there must be a much simpler way, where I can unset everything that I don't need, or only call the information that I need from the API? Here is the foreach loop that I used: foreach ($obj as $key) { foreach ($key as $id => $value) { if (!empty($value['name'])) { $products[] = array('Name'=>$value['name'], 'ID' => $value['id'] ); } } } **EDIT ** Once I have my array of ID's (which will be around 600 values long) I then need to get a list of serial numbers that are linked to these id's (there could be up to 100 per id) which will leave me with an array that will be huge! So far I have been getting gateway 504 error's, which I'm hoping is just due to the fact that I'm currently pulling out so much more information than I actually need, so I'm trying to make this more efficient and slim lined. I'm fairly new to PHP, and just do it as a hobby, so go easy on me please! Thanks AJLX
  16. Hi, I'm using the following code to grab a csv file from one website & keep it on my website. The code is working fine. <?php $url = 'http://thewebsite.com/export.aspx?type=csv&report=nameofthereport~8~'; $path = '/home/path/to/mywebsite.com/public_ftp/incoming/nameofthereport_Area_8.csv'; $fp = fopen($path, 'w'); $ch = curl_init($url); curl_setopt($ch, CURLOPT_FILE, $fp); $data = curl_exec($ch); curl_close($ch); fclose($fp); ?> Here's what I want to do next. I want to query a database, and replace nameofthereport and 8 with the results of the query. My code to query the database is below. <?php include("/home/path/to/mywebsite.com/public_html/db_connect.php"); //connect to the database $today = date('Y-m-d'); $query1=("SELECT * FROM `table_name` WHERE expiry > $today"); $result1=mysqli_query($GLOBALS["___mysqli_ston"], $query1); $num1=mysqli_num_rows($result1); if ($num1 > 0) { while ($data = mysqli_fetch_array($result1)){ $email_to = $data["email"]; $district = $data["district"]; $report = $data["report"]; } } ?> Based on the code above, I would like to replace nameofthereport with $report and 8 with $district Could you show me the code please? Thanks.
  17. I'm using multiple API's, all of which get called using cURL. Someone on Reddit recommended code that looks like this: function fetch($url, $the_id = null) { // Initiate the cURL fetch $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Send authorization header with the the ID. Without this, the query won't work if ($the_id) curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: '.$the_id)); $result = curl_exec($ch); curl_close($ch); // Put the results to an object return simplexml_load_string($result) or die("Error: Cannot create object"); } // Without auth id $test = fetch('http://forums.phpfreaks.com'); // With auth id $test = fetch('http://forums.phpfreaks.com', 't_v'); But when I then use the foreach to pull the data from the API, it produces no results. foreach($result->things->children() as $thing) { echo "<p>". $thing->cool_thing ."</p>"; echo "<p>". $thing->cooler_thing ."</p>"; } Whether I use echo fetch(parameters); or fetch(); it does get any results, unlike if I used it outside of a function.
  18. I have this code and its downloading file nicely. But I want to show a progress bar while downloading file from external server. My existing code shows progress bar but its not effective (ex. if i try to download two media file, one video and another audio, and video size is larger than audio size the audio finishes first and the progress bar shows 100% also suddenly it drops to 50% as the video is still downloading ). I mean it actually shows two progress and I need one. If I could get average percentage value of two progress that would be better. Any suggestion regarding this will be greatly appreciated. <?php set_time_limit ( 0 ); function define_progress_callback($i) { global $conn; curl_setopt($conn[$i], CURLOPT_PROGRESSFUNCTION, function ($resource,$download_size, $downloaded, $upload_size, $uploaded) { if($download_size > 0) $progress = round($downloaded / $download_size * 100); echo '<script language="javascript">$(".loader").loader("setProgress", '.$progress.');</script>'; echo str_pad("",1024," "); flush(); usleep(20000); }); } $urls = array("http://example.com/file.mp3", "http:/example.com/file.mp4"); $save_to='./tmp/'; $conn = array(); $fp = array(); $mh = curl_multi_init(); foreach ($urls as $i => $url) { $g = $save_to . basename($url); $conn[$i]=curl_init($url); $fp[$i]=fopen ($g, "wb"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // No certificate curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt ($conn[$i], CURLOPT_FILE, $fp[$i]); curl_setopt ($conn[$i], CURLOPT_HEADER ,0); curl_setopt($conn[$i],CURLOPT_CONNECTTIMEOUT,60); curl_setopt ($conn[$i], CURLOPT_MAXCONNECTS, 10); curl_setopt($conn[$i], CURLOPT_NOPROGRESS, false); define_progress_callback($i); curl_multi_add_handle ($mh,$conn[$i]); } do { $n=curl_multi_exec($mh,$active); } while ($active); foreach ($urls as $i => $url) { curl_multi_remove_handle($mh,$conn[$i]); curl_close($conn[$i]); fclose($fp[$i]); } curl_multi_close($mh); ?>
  19. somebody have an example or reference for PHP code that make login to a website and handle with the redirection after? thanks!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.