PHP - Curl Request Append Response
Hello, I am trying to do multiple curl requests and get the response for each one output to the screen. I have wrote the following code, but only appear to be getting the last response when outputting $result. What am i doing wrong? Is there a way to wait for each curl request to be completed before appending to $result so I can see them all? Thanks very much if (isset($_POST['submit'])) { $result = array(); foreach ($textAr as $line) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate"); $result[] = curl_exec ($ch); } curl_close ($ch); echo "<pre>"; print_r($result); echo "</pre>"; }
Similar TutorialsA HTTP request is made to the server, Slim creates a Request and Response object, content in the Request is sent to another server using cURL via Guzzle, Guzzle returns its own Response, and content from Guzzle's response must be returned by the original Slim response. Would you recommend white-listing or black-listing response headers, and which specific headers? Similarly, would you recommend white-listing or black-listing the request headers sent via cURL, and which specific headers? Thanks <?php use Psr\Http\Message\ResponseInterface as Response; use GuzzleHttp\Psr7\Response as CurlResponse; class ApiResponder { public function delete(Response $httpResponse, CurlResponse $curlResponse) { return $this->proxy($httpResponse, $curlResponse); } //other public methods... private function proxy(Response $httpResponse, CurlResponse $curlResponse) { foreach($this->getResponseHeaders($curlResponse) as $name=>$value) { $httpResponse=$httpResponse->withHeader($name, $value); } return $httpResponse->withBody($curlResponse->getBody())->withStatus($curlResponse->getStatusCode()); } private function getResponseHeaders(Response $httpResponse):array { //Blacklist headers which should be returned to original client. TBD whether I should whitelist headers instead. $blacklist=['Date'=>null, 'Server'=>null, 'X-Powered-By'=>null, 'Access-Control-Allow-Origin'=>null, 'Access-Control-Allow-Methods'=>null, 'Access-Control-Allow-Headers'=>null, 'Set-Cookie'=>null]; return array_diff_key($curlResponse->getHeaders(), $blacklist); } /** * This method doesn't really exist in this class, but is just included to show which headers I am forwarding in the cURL request. */ private function getRequestHeaders($clientRequest):array { $whitelist=['connection'=>null,'accept'=>null,'accept-encoding'=>null,'accept-language'=>null,'content-type'=>null,'content-length'=>null]; return array_intersect_key($clientRequest->getHeaders(), $whitelist); } }
I have an application which receives multiple requests at once and it advantageous to process them as a group. I am thinking I should be doing something like the following, however, as I just came up with it on my own, would appreciate a critique. Is this a common design pattern or should I be doing something differently? Note that I have three questions asking specific questions in the below code (look for the comments with question marks).
Thanks <?php class Request { private $response, $data; public function __construct(array $data) { $this->data=$data; return $this->response=new Response($this); } public function getResponse():Response { return $this->response; } public function updateResponse($results):self { $this->response->setResults($results); return $this; } } <?php class Response { private $request, $results; public function __construct(Request $request) { //I don't really see the need for this. Any need? $this->request=$request; } public function setResults($results):self { $this->results=$results; return $this; } public function getResults() { return $this->results; } }
<?php class Container implements \Iterator { private $position = 0; private $requests, $response; public function __construct(WorkerObject $worker, array $inputArray) { $this->requests=[]; $this->responses=[]; foreach($inputArray as $i =>$inputData) { $this->requests[$i]=new Request($inputData); $this->responses[]=$this->responses[$i]->getResponse(); } //Should WorkerObject be responsible to execute Request::updateResponse() method? $worker->process_requests(...$this->requests); //Or should I iterate over my requests upon completion and execute updateResponse() method? } public function __construct() { $this->position = 0; } public function rewind() { $this->position = 0; } public function current() { return $this->responses[$this->position]; } public function key() { //Will this work? return $this->requests[$this->position]; } public function next() { ++$this->position; } public function valid() { return isset($this->responses[$this->position]); } } <?php //... $container=new Container(new WorkerObject, $inputArray); foreach($container as $request => $response) { //... }
I need to make my client's site distinguish among different tabs in the same browser. (See http://www.phpfreaks.com/forums/index.php?topic=357772.0 for background.) I create a tab ID when the user first visits the site in a particular tab, and I'm passing it from page to page as a parameter. This seems to be the only way to do what I need. The tab ID is always passed through POST so that the user won't see it. If it were visible, users could make trouble (or more likely get in trouble) by adding or removing the ID themselves. This is not simple where a page is loaded by a hyperlink. The anchor tag passes parameters via GET, period. The solution I found is to link to a script named post.php, which takes the real link target and the tab ID as parameters, sends the browser a form that passes the tab ID to the real link target via POST, and auto-submits the form via JavaScript. This works, but it requires two round trips to the browser to load a page. It's also a pain to code. Is there a more efficient way to do this... perhaps a way to make the server send the browser a POST response, even though it made a GET request? If it matters, the server is Apache 2.x. Hi, I'm posting a form using curl: Code: [Select] <?php //create the final string to be posted using implode() $post_str = implode ('&', $post_items); //Initialize cURL and connect to the remote URL $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://leads..html' ); //Instruct cURL to do a regular HTTP POST curl_setopt($ch, CURLOPT_POST, TRUE); //Specify the data which is to be posted curl_setopt($ch, CURLOPT_POSTFIELDS, $post_str); //Tell curl_exec to return the response output as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); //Follow 302 redirect curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Timeout in seconds curl_setopt($ch, CURLOPT_TIMEOUT, 30); //verify https curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //Execute the cURL session $response = curl_exec($ch ); //Close cURL session and file curl_close($ch); echo $response; $resp = explode("\n\r\n", $response); $header = explode("\n", $resp[0]); echo "<pre>"; print_r($header); echo "</pre>"; ?> The response is: success: https://www-somesite.html or Array ( => success: https://www-somesite.html ) My question is how to get the returned URL and redirect the user to it? Probably easy but seems to be beyond my very limited php knowledge. Thanks. I have been using PHP CURL to obtain stock data... The URL is
https://trade.plus50...ntName=Facebook
Essentially, it is supposed to return date, time, and price of stock tick data
But it returns stuff like "HrCy/h6wsw4esLL+HrCzDh6wsw4esLMOHrCzDh6wsu4esLLeHrCy7h6wsu4esLL"
So... I would like to know, what is this format, and how do I decode it? Thanks
Here is the full response....
{"InstrumentName":"Facebook","InstrumentID":1350,"StartPointDate":"2014-12-19 20:42:45.837","LastPointDate":"2014-12-19 20:59:59.463","SellRate":"MuHrCzHh6wsx4esLMuHrCzHh6wsy4esLMuHrCzLh6wsy4esLMuHrCzLh6wsz4esLMuHrCzDh6wsw4esLMOHrCzDh6wsv4esLMOHrCzDh6wsw4esLL+HrCy/h6ws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fh6wso4esLJ+HrCyjh6wso4esLKeHrCyjh6wso4esLKeHrCy3h6wss4esLLuHrCy3h6wsv4esLL+HrCy7h6wsv4esLL+HrCzHh6wsy4esLMuHrCzLh6wsz4esLM+HrCzXh6ws04esLNOHrCzTh6ws04esLNuHrCzXh6ws14esLNeHrCzbh6ws24esLNuHrCzfh6ws34esLN+HrCzfh6ws44esLN+HrCzjh6ws34esLNuHrCzfh6ws24esLNuHrCzbh6ws24esLNuHrCzbh6ws14esLNeHrCzXh6ws04esLNeHrCzfh6ws24esLNuHrCzjh6ws54esLOeHrCzrh6ws64esLOuHrCzvh6ws64esLOeHrCznh6ws54esLOuHrCzjh6ws64esLOuHrCzvh6ws74esLOuHrCzvh6ws64esLOuHrCzvh6ws64esLO+HrCzvh6ws74esLOeHrCzjh6ws44esLOOHrCzjh6ws44esLOOHrCzjh6ws34esLN+HrCzfh6ws34esLN+HrCzfh6ws34esLN+HrCzfh6ws34esLN+HrCzbh6ws24esLNeHrCzTh6ws04esLNeHrCzXh6ws04esLNeHrCzbh6ws34esLNuHrCzXh6ws24esLN+HrCzfh6ws24esLN+HrCzfh6ws34esLN+HrCzfh6ws24esLN+HrCzfh6ws24esLNuHrCzXh6ws04esLNOHrCzTh6wsz4esLMuHrCzLh6wsy4esLMuHrCzPh6wsz4esLM+HrCzPh6wsz4esLM+HrCzPh6wsz4esLM+HrCzPh6wsz4esLNOHrCzTh6ws04esLNOHrCzTh6ws04esLNOHrCzPh6ws04esLNOHrCzPh6ws04esLNOHrCzTh6ws04esLNOHrCzPh6wsz4esLMuHrCzPh6wsy4esLM+HrCzLh6wsz4esLMuHrCzPh6wsy4esLM+HrCzPh6wsz4esLM+HrCzLh6wsy4esLMuHrCzLh6wsy4esLM+HrCzPh6wsz4esLM+HrCzPh6wsz4esLMuHrCzPh6ws04esLNOHrCzXh6ws14esLN+HrCzfh6ws34esLN+HrCzjh6ws34esLNeHrCzXh6ws24esLNeHrCzXh6ws14esLNeHrCzXh6ws14esLNeHrCzXh6ws14esLNeHrCzXh6ws04esLNOHrCzTh6ws04esLNOHrCzTh6ws04esLNOHrCzTh6wsz4esLM+HrCzPh6wsz4esLNOHrCzPh6ws04esLNOHrCzTh6ws04esLNOHrCzXh6ws04esLNeHrCzXh6ws14esLNuHrCzfh6ws34esLN+HrCzfh6ws24esLNuHrCzfh6ws24esLNeHrCzXh6ws04esLNOHrCzXh6ws04esLNOHrCzXh6ws24esLNuHrCzbh6ws24esLNeHrCzTh6ws14esLNeHrCzTh6ws04esLNOHrCzTh6ws04esLNOHrCzTh6ws04esLNOHrCzTh6ws04esLNOHrCzPh6wsz4esLM+HrCzPh6wsz4esLM+HrCzPh6wsz4esLM+HrCzPh6wsz4esLMuHrCzLh6wsx4esLMeHrCzHh6wsx4esLMeHrCzDh6wsv4esLMOHrCzDh6wsw4esLL+HrCy/h6wsv4esLMOHrCzLh6wsy4esLL+HrCy/h6wsv4esLMOHrCy/h6wsv4esLMeHrCzHh6wsy4esLM+HrCzPh6wsy4esLMuHrCzLh6wsy4esLM+HrCzLh6wsy4esLM+HrCzPh6wsz4esLMuHrCzPh6wsz4esLM+HrCzPh6wsy4esLMuHrCzHh6wsz4esLMeHrCzHh6wsx4esLMeHrCzLh6wsx4esLL+HrCy7h6wsw4esLMeHrCzDh6wsx4esLMOHrCzHh6wsw4esLL+HrCy/h6wsr4esLK+HrCynh6wso4esLKeHrCybh6wso4esLKOHrCybh6wsl4esL","DeltaDateTime":"AAAAAMgGAAC4EQAAChQAAP4WAABIHAAAcSMAABosAABUNAAAMD4AALZJAAAHUQAAIF0AAGJmAAA8bwAAhXgAAH2AAABAiAAA3o8AANKXAADAnwAAZqgAAGGwAAA3twAALsMAAOnIAACSzAAA79EAAPDXAAAg5AAA+O0AAADxAADw+wAAsAMBAOUIAQCODQEApBUBAGsZAQAUIgEAGisBABUzAQAAOwEAxD8BAPxIAQDMUAEA3lgBAHpcAQBrZAEARnMBAJx7AQCafQEACoEBANqDAQDYhgEA4Y4BAECXAQB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F6vDAChtAwADsMMACnNDADw1QwAxt0MAG7kDADa5gwAGOoMAPLxDABL+wwA5gINABQMDQCHFA0A/hwNAE4nDQByMA0A6DINAC81DQAuPQ0AJUQNAPVGDQDSSQ0AYEwNAIZPDQBdUg0A2lQNAH5XDQD0XQ0AAGYNANptDQAwdw0A5H0NAE2ADQAHhQ0AaogNAAyRDQDsmA0AQqINAH6rDQA3tA0AXrwNAPLEDQCmzg0A4NYNALTeDQBj5w0AYu8NAGT3DQDG/w0ALAgOAN8QDgAQGQ4ACyEOACQpDgA6MQ4AUDkOAC5BDgA9SQ4ADE8OAGFXDgCuXA4A218OAHZiDgCAZw4AR3EOAGJ3DgDieQ4AGXwOAJl+DgC/gA4Am4sOAJaTDgDumQ4AaKIOAMumDgAJrw4A4bgOALvADgD2yQ4A0MwOAOjWDgDP3g4AEuUOAIztDgAQ9g4AhvgOAIgADwBqBA8ASgwPAHQODwAeFA8Aix0PANYfDwBFIg8AnCcPAL4pDwD/Kw8A8TQPAEA9DwBmPw8AQEcPALpKDwA6Ug8AwFQPANZWDwDlWQ8Aq1wPAHFfDwD0YQ8AN2cPAElpDwDWaw8AWnMPAPF1DwCteA8AenwPAFaGDwDGiQ8A6IsPANGVDwDxmA8AF5sPAL6hDwD8pA8AH6cPAMSqDwCHrQ8AALAPAH2yDwCMtA8ApLYPAAvADwCaxQ8A","CurrentTime":"2014-12-21 12:36:48.939","PrecisionDigits":2,"SpreadPipsCount":5,"IsDynamicSpread":false}
Hi all, I'm using curl to post some data, and the response is (assuming no errors) either <boolean>true</boolean> or <boolean>false</boolean>. So if I use simplexml_load_string, the result is returned as an object. I'm trying to make this a boolean so I can handle the response, but it doesn't seem to be working....checking for false didn't stop anything from happening. Here's the problem code: Code: [Select] $result = curl_exec($ch); $xml = settype(simplexml_load_string($result),"boolean"); if (curl_errno($ch) || $xml === false) { throw new Exception(curl_error($ch)); }
Hello guys, <?xml version="1.0" encoding="utf-8"?> <string xmlns="http://tempuri.org/">false</string>
Unfortunately the curl returns something that I can't parse to XML and get the value "false" $soap_do = curl_init(); curl_setopt($soap_do, CURLOPT_URL, $url ); curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true ); curl_setopt($soap_do, CURLOPT_POST, true ); curl_setopt($soap_do, CURLOPT_POSTFIELDS, $soap_request); curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header); curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($soap_do); $xml = simplexml_load_string($result); return $xml; How do I parse this SOAP response? Thank you very much You would think the answer would be all over the Internet and easy to find, but it’s not. I have searched many times, and in all the multitude of search results I have still never found an adequate usable answer. The MOST you ever find is someone saying how easy it is with PHP, but they don’t tell you how, even when the person they are answering asks them (odd). You can be that one in a billion person who finally answers it for real and helps someone out. I have a simple HTML form with data fields first_name, last_name, email, phone, country, a few hidden inputs, and a single submit button, like so: (Please note: the method is GET, not Post.) <form action="https://MyDomainOnMyServer.com/MyPHPScript.php”> <input type="text" name="first_name" value="" /> <input type="text" name="last_name" value="" /> <input type="text" name="email" value="" /> <input type="text" name="phone" value="" /> <input type="hidden" name="type" value="type123"> <input type="hidden" name="project" value="new123"> <select required name="country"> <option value="">Choose your country</option> <option value="US">United States</option> <option value="CA">Canada</option> <option value="GB">United Kingdom</option> <option value="Many More">Many More Countries</option> </select> <input type="submit" value="Submit Form" /> </form> NOTE: Originally, the form action would have been: action="https://TheirExampleDomainOnTheirRemoteServer.com/TheirRemotePHPScript.php" name="form1234" Upon clicking the single submit button only, what I need to have happen is this: 1. Send me an email to whatever@whatever.tld containing all the form submission data 2. Place the form submission data into a MySQL database having the corresponding data fields 3. Send the form submission contents including the hidden input values to "https://TheirExampleDomainOnTheirRemoteServer.com/TheirRemotePHPScript.php" name="form1234" AS IF that had remained set as the original form action to begin with So basically what I’m trying to obtain is the cleanest possible PHP script that will do those three things, which is essentially what others have asked for over the years in search results I have found, but no one has ever provided it in a clear instance that works. If I can just see such a script, I should be able to see how it works and then do what I need. Thanks. Reply hi everyone, can you please kindly check my code for error Code: [Select] $xmltosend = "<?xml version='1.0'?>\r\n". "<soap:Envelope xmlns:soap='http://www.w3.org/2001/12/soap-envelope' soap:encodingStyle='http://www.w3.org/2001/12/soap-encoding'>\r\n". "<soap:Body xmlns:m='https://www.trustwave.com/'>\r\n". "<request>\n". "<authentication>\n". "<username>username</username>\n". "<password>password</password>\n". "</authentication>\n". "<operation>getResellerProducts</operation>\n". "<params>\n". "<int>12345</int>\n". "</params>\n". "</request>\n". "</soap:Envelope>\n"; $reqheader = "POST /index.php HTTP/1.1\r\n". "Host:www.trustwave.com\r\n". "Content-Type: application/soap+xml; charset=utf-8\r\n". "Content-Length: ".strlen($xmltosend) ."\r\n\r\n"; $url = 'https://testapi.ssl.trustwave.com/3.0/'; // fake - obviosly! $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $xmltosend); curl_setopt($ch, CURLOPT_POST, true); // what to post curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $reqheader); curl_setopt($ch, CURLOPT_USERPWD, "username:password"); $result = curl_exec($ch); curl_close($ch); print $result; im getting this error Code: [Select] Authorization Required This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required. anyone pleeeaassseee...!!! tia I want to be able to send a GET request to another website for example i want to be able to run this http://www.mywebsite.com/blog.php?clear_cache= using curl but when i use curl the website is loaded into my own heres my code Code: [Select] $curl = curl_init(); $json_url = $_SESSION['blog_base'] . 'blog.php?empty_cache='; curl_setopt ($curl, CURLOPT_URL, "$json_url"); $ANSWER=curl_exec ($curl); curl_close ($curl); I am testing a url for http post request. It connects to the site then it is disconnected. In fire fox it is giving error that the "connection was reset". In google chrome it is giving error that "Unable to load the webpage because the server sent no data". Following is the script. I am new to curl and also new to http request response. The provider of this site tells me that everything is ok and it is sending data but i am not getting any data or any header of this site. <?php $data = '<?xml version="1.0" encoding="UTF-8"?><Request><Source ClientID="test_xml" Password="1234" /><RequestDetails Language="En"><SearchHotelPriceRequest><ServiceDestination DestinationType="city" DestinationCode="477" /><ImmediateConfirmationOnly>1</ImmediateConfirmationOnly><PeriodOfStay><CheckInDate>2012-03-01</CheckInDate><Duration>3</Duration></PeriodOfStay><Rooms> <Room NumberOfRooms="1" NumberOfAdults="2" /> </Rooms></SearchHotelPriceRequest></RequestDetails></Request>'; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, 'https://62.218.28.13:8443/monWebService/Request/v2'); curl_setopt($ch, CURLOPT_POST, $data); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $data = curl_exec($ch); curl_close ($ch); echo $data; ?> Hey people of php freaks recently, I've been having issues changing a discord webhook [curl] post request to a website [curl] post request. My knowledge in PHP is very limited so, I really would appreciate some help This is the function: function postToDiscord($message) { $data = array("content" => $message, "username" => "Payouts Bot"); $curl = curl_init("https://discordapp.com/api/webhooks/591662537293168650/eyme87xmCuKne4njucoDSqzojq78NaS9x7t4sgP9m-l5EmrvUeZegkM4wok-L-UdBDxo"); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); return curl_exec($curl); } Currently the discord bot transfers the message into a discord channel and, I do not want that. I want it to transfer it onto a website page. As, I said i'm not very keen on this so please help me.
Edited July 3, 2019 by LegitSpiderman Can you see if a request (post/get) is from a curl request or an actual user? I am trying to defeat a little bit of fraud. Hi, Could somebody please explain to me why the following code returns a 400 error. I've been sitting looking at it for hours and I can't see anything wrong with it, but then again I don't know too much about cURL. Code: [Select] <?php // INSTANTIATE CURL. $curl = curl_init(); // CURL SETTINGS. curl_setopt($curl, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/96966578.xml"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0); // GRAB THE XML FILE. $response = curl_exec($curl); // Get information about the response $responseInfo=curl_getinfo($curl); // Close the CURL connection curl_close($curl); curl_close($curl); // Make sure we received a response from Twitter if(intval($responseInfo['http_code'])==200){ // Display the response from Twitter $content .= "Success code response:". $response; }else{ // Something went wrong $content .= "Error: " . $responseInfo['http_code']; } // SET UP XML OBJECT. $xmlObjTwitter = simplexml_load_string( $response ); $content .="<h3>Your last 10 twitter posts....</h3>\n" ; $content .= "<ul> \n"; $tempCounter = 0; foreach ( $xmlObjTwitter -> item as $item ) { // DISPLAY ONLY 10 ITEMS. if ( $tempCounter < 11 ) { $content .= "<li><a href=\"{$item -> guid}\">{$item -> title}</a></li> "; } $tempCounter += 1; } $content .="</ul>\n"; echo $content ; ?> Doing something wrong, but don't see it. How should one retrieve a POST parameter? My $request->toArray()['html'] works, but I am sure it is not the "right way". <?php namespace App\DataPersister; use ApiPlatform\Core\DataPersister\DataPersisterInterface; use Symfony\Component\HttpFoundation\RequestStack; class ArchivePersister implements DataPersisterInterface { public function __construct(RequestStack $requestStack) { $request = $requestStack->getCurrentRequest(); syslog(LOG_ERR, '$request->getMethod(): '.$request->getMethod()); syslog(LOG_ERR, '$request->getContent(): '.$request->getContent()); syslog(LOG_ERR, '$request->request->get(html): '.$request->request->get('html')); syslog(LOG_ERR, '$request->query->get(html): '.$request->query->get('html')); syslog(LOG_ERR, '$request->get(html): '.$request->get('html')); syslog(LOG_ERR, '$request->toArray(): '.json_encode($request->toArray())); syslog(LOG_ERR, '$request->toArray()[html]: '.$request->toArray()['html']); } } output $request->getMethod(): POST $request->getContent(): {"project":"/projects/1","description":"","html":"<p>{{ project_name }}</p>"} $request->request->get(html): $request->query->get(html): $request->get(html): $request->toArray(): {"project":"\/projects\/1","description":"","html":"<p>{{ project_name }}<\/p>"} $request->toArray()[html]: <p>{{ project_name }}</p> good day dear community, i am workin on a Curl loop to fetch multiple pages: i have some examples - and a question: Example: If we want to get information from 3 sites with CURL we can do it like so: $list[1] = "http://www.example1.com"; $list[2] = "ftp://example.com"; $list[3] = "http://www.example2.com"; After creating the list of links we should initialize the cURL multi handle and adding the cURL handles. $curlHandle = curl_multi_init(); for ($i = 1;$i <= 3; $i++) $curl[$i] = addHandle($curlHandle,$list[$i]); Now we should execute the cURL multi handle retrive the content from the sub handles that we added to the cURL multi handle. ExecHandle($curlHandle); for ($i = 1;$i <= 3; $i++) { $text[$i] = curl_multi_getcontent ($curl[$i]); echo $text[$i]; } In the end we should release the handles from the cURL multi handle by calling curl_multi_remove_handle and close the cURL multi handle! If we want to another Fetch of sites with cURL-Multi - since this is the most pretty way to do it! Well I am not sure bout the string concatenation. How to do it - Note I want to fetch several hundred pages: see the some details for this target-server sites - /(I have to create a loop over several hundred sites). * siteone.example/?show_subsite=9009 * siteone.example/?show_subsite=9742 * siteone.example/?show_subsite=9871 .... and so on and so forth Question: How to appy this loop into the array of the curl-multi? <?php /************************************\ * Multi interface in PHP with curl * * Requires PHP 5.0, Apache 2.0 and * * Curl * ************************************* * Writen By Cyborg 19671897 * * Bugfixed by Jeremy Ellman * \***********************************/ $urls = array( "siteone", "sitetwo", "sitethree" ); $mh = curl_multi_init(); foreach ($urls as $i => $url) { $conn[$i]=curl_init($url); curl_setopt($conn[$i],CURLOPT_RETURNTRANSFER,1);//return data as string curl_setopt($conn[$i],CURLOPT_FOLLOWLOCATION,1);//follow redirects curl_setopt($conn[$i],CURLOPT_MAXREDIRS,2);//maximum redirects curl_setopt($conn[$i],CURLOPT_CONNECTTIMEOUT,10);//timeout curl_multi_add_handle ($mh,$conn[$i]); } do { $n=curl_multi_exec($mh,$active); } while ($active); foreach ($urls as $i => $url) { $res[$i]=curl_multi_getcontent($conn[$i]); curl_multi_remove_handle($mh,$conn[$i]); curl_close($conn[$i]); } curl_multi_close($mh); print_r($res); ?> I look forward to your ideas. Trying to simply append each error message into the error.message div.
We can get only one of the error messages at time to display in notification div.
We just want each field with error to display in notification div.
Can anyone give some direction, we mssing:
Error Message loop
if((data.row_id).length > 0) { $.each(data, function(error_code, message ) { if(errorCode == $.trim(data.error_code) && errorCode != -1 ){ error_message = data.message; return false; } }); }Print out Error Message(display) var spanerrorgen = $('.error.message').contents().find('h4').html(error_message); var appenderrorgen = $('.error.message').contents().find('h4'); $($fieldref).each(function(){ $(spanerrorgen).append(appenderrorgen); }); errorFields.notify.showNotification(".error"); Though I've been tinkering with PHP for a number of years, I'm mostly a front end developer/designer (HTML5, XHTML, CSS). In other words, please go easy on me. I am working on a site where we're pulling data from mysql. Each row that has a column for dimensions which look like this: 20x10x5 Here's what I have so far: $dimensions = explode("x",$row['DIMENSIONS']); $x_separated = implode("x", $dimensions); echo "$x_separated"; What I would like to do is append an "inches" or "in" to each value in the array. The resulting values should look like this: => 20in [1] => 10in [2] => 5in And after the implode, would then look like this: 20in x 10in x 5in Any help from the more experienced coders here is much appreciated. Thanks! hi, i have this xml: <?xml version="1.0" encoding="ISO-8859-1" ?> - <link4> <nome>Tove</nome> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> <nome>sdsd</nome> <id>116</id> </link4> and i want simple append more elements "nome" and id inside of link4 how can i do that i using php 4 thanks a lot for your help I can't seem to find an answer on this one. I've figured out how to add key/value pairs, add to the beginning and end - but the question here is how do you append to each value within an array? Let's say I wanted to add the word 'go'. From: Array ( => Bruins [1] => Rangers [2] => Leafs ) To: Array ( => GoBruins [1] => GoRangers [2] => GoLeafs ) Seems simple enough but Google isn't being friendly today. |