PHP - Curl Fetch Of Twitter Timeline Feed Not Working
Hello PHP Freaks!
I have the following PHP Curl code which is supposed to fetch the twitter timeline feed for a specific username and parse and display it on a page, but for some reason Curl is unable to fetch data from twitter: Code: [Select] <?php function get_data($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $data = curl_exec($ch); curl_close($ch); return $data; } $json = get_data("https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=digioz&count=2"); if ($json != false) { $obj = json_decode($json); foreach($obj as $var => $value) { echo "Message number: $var <br/>"; echo "Name: " . $obj[$var]->user->name; echo "Handle: " . $obj[$var]->user->screen_name . "<br/>"; echo "Message: " . $obj[$var]->text; echo "Created" . $obj[$var]->created_at . "<br/>"; echo "URL" . $obj[$var]->user->url . "<br/>"; echo "Location" . $obj[$var]->user->location . "<br/>"; echo "<br/>"; } } else { echo "Could not fetch Twitter Data"; } ?> Anyone have any idea why the data is not being fetched? If I copy and paste the URL into my browser window it returns results just fine, so I know the problem is not with the URL. Thanks, Pete Similar Tutorialsgood 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. Does anybody have any recommendations for PHP scripts to pull in a Twitter feed? I've tried several but each seem to just give me error messages! I basically just need a PHP alternative so that the tweets can be read by search engines. Thanks. Example is: https://twitter.com/statuses/user_timeline/kevinhart4real.xml I have all the relevant information I need that i'd like to go in the field, I just need to know how to dynamically create the file with the content and have it update at specific intervals. Any one have any ideas (with PHP) So far I have come up with this: Code: [Select] $link = mysql_connect('localhost','root',''); mysql_select_db('test',$link); $result = mysql_query('SELECT `nationid`,`ruler`,`nation`, `resource1`, `resource2`, `alliance` FROM `nation`'); $doc = new DomDocument('1.0'); $root = $doc->createElement('nationlist'); $root = $doc->appendChild($root); while($row = mysql_fetch_assoc($result)) { $nation= $doc->createElement('nation'); $nation = $root->appendChild($nation); foreach($row as $fieldname => $fieldvalue) { $child = $doc->createElement($fieldname); $child = $car->appendChild($child); //add data to the new element $value = $doc->createTextNode($fieldvalue); $value = $child->appendChild($value); } } $doc->save("nations.xml"); Now that generates 1 .xml file with all the details returned from my query. (also don't bash me for using mysql, it's a quick test) What I would like to do is create a new file for each record in my table and have only the values in that recorded saved to its respective file. Hi all. I'm using a cron job to pull the XML feed of my last five tweets, and using simplexml to parse and display the feed on my website. Here's the PHP I'm using--it works just fine, and displays exactly as I want it to: <?php $xml = simplexml_load_file('crontwitter.xml'); foreach ($xml->status as $status) { print "<p><span class=\"twittertext\">{$status->text}</span><br />"; print "<a class=\"twittertime\" href=\"http://twitter.com/#!/eaners/status/{$status->id}\" target=\"_blank\">"; echo date("j M Y, g:i A",strtotime($status->created_at)); print "</a></span></p>"; } ?> I'd like to add a touch more "intelligence" to this script, though. Namely, there are three things I'd also like to have this script do: I'd like to append "I" to any tweets that include the #fb hashtag, so that things display correctly (e.g., "I did such and such today" instead of just "did such and such today") I'd like to link to any other Twitter users mentioned (they would always be mentioned using the @username format) I'd like to link to a search for any other hash tag mentioned aside from #fb (they would always be included using the #tag format) I guess I'm not sure how exactly to further parse the XML file. I'll admit to being a relative newbie when it comes to PHP, so any assistance would be greatly appreciated! I am creating this feature for a client of mine that needs it working by tomorrow! I am trying to use cURL to grab the RSS feed he http://blogs.menshealth.com/fitness-pros/feed But all I get back is an empty string... Please help - I've been searching Google & this forum but haven't found anything that I can use that fixes this issue. $feed = getRssData(); echo "<pre>\n"; print_r( $feed ); echo "\n</pre>\n"; function getRssData() { // returns the feed array $requested_feed = "http://blogs.menshealth.com/fitness-pros/feed"; $ch = curl_init($requested_feed); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); $rss_data = curl_exec($ch); curl_close($ch); echo "RSS DATA: <br />\n" . $rss_data; $doc = new DOMDocument(); $doc->load($rss_data); $arrFeeds = array(); foreach ($doc->getElementsByTagName('item') as $node) { $itemRSS = array ( 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue ); array_push($arrFeeds, $itemRSS); } return $arrFeeds; } You can see a live test he http://pro-formpt.com/get_rss.php?feed=workout It only has a few parameters in it so I can use the same file to grab other RSS Feeds as well - but they all fail the same way. Like this one: http://pro-formpt.com/get_rss.php?feed=living Which should grab the feed from he http://blogs.menshealth.com/mh-life/feed I truly appreciate any suggestions! Thanks! hi i know eval is not best way to run php code via database but its required to me. What is happening i am reading a feed and if i use eval it just repeat same rss links but if i put a direct code it show proper feed. here is my code which works proper $xml = simplexml_load_file($feedurl); foreach ($xml->channel->item as $item) { echo $item->title . "\n"; echo $item->link . "\n"; } results of above code are fine. Code: [Select] Feed one title feed one link feed two title feed two link feed three title feed three link and so on for 10 times as 10 feeds are available...... But if i use eval my database contains <?php echo $item->title . "\n"; echo $item->link . "\n"; ?> and i run it like this $xml = simplexml_load_file($feedurl); foreach ($xml->channel->item as $item) { eval('?>' . $fromadatabase['code'] . '<?php '); } and i get this results Code: [Select] Feed one title feed one link Feed one title feed one link Feed one title feed one link and so on...... means it just repeat first feed for 10 times Thanks for any help. Hi, I have a problem with an RSS Feed. the error im getting on the W3C validator is this: This feed does not validate. * line 1, column 0: XML parsing error: <unknown>:1:0: syntax error [help] Query couldn't be executed In addition, interoperability with the widest range of feed readers could be improved by implementing the following recommendation. * "text/xml" media type is not specific enough [help] .htaccess AddType application/x-httpd-php .xml rss.php <? //Set XML header for browser header('Content-type: text/xml'); //Create the heading/channel info for RSS Feed $output = '<rss version=\"2.0\">'; $output .= '<channel>'; $output .= '<title>Muzo Feed</title>'; $output .= '<description>Your RSS Feed Description</description>'; $output .= '<link>http://mi-linux.wlv.ac.uk/~0703272</link>'; //Individual Items of our RSS Feed //Connect to a database and and display each new item in our feed //Connect to DB $host = "localhost"; //Name of host $user = "0703272"; //User name for Database $pass = "rachel123"; //Password for Database $db = "db0703272"; //Name of Database mysql_connect($host,$user,$pass); //Create SQL Query for our RSS feed $sql = "SELECT `title`, `webaddress`, `message`, `date_added` FROM `messages`ORDER BY `date_added` DESC LIMIT 0 , 15"; $result = mysql_query($sql) or die ("Query couldn't be executed"); //Create Loop for the individual elements in the RSS item section while ($row = mysql_fetch_array($result)) { $output .= '<item>'; $output .= '<title>'.$row['title'].'</title>'; $output .= '<link>http:/mi-linux.wlv.ac.uk/~0703272/blog.php'.$row['link'].'</link>'; $output .= '<message>'.$row['message'].'</description>'; $output .= '<date_added>'.$row['date'].'</pubDate>'; $output .= '</item>'; } //Close RSS channel $output .= '</channel>'; $output .= '</rss>'; //Display output in browser echo $output; ?> any ideas? Hello, I have this simple php form that updates the table, and also shows what the information in it is. Here it is: <strong>Update multiple rows in mysql</strong><br> <?php $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="test_mysql"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="500" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>Id</strong></td> <td align="center"><strong>Month</strong> <strong>Date</strong> </td> <td align="center"><strong>Lastname</strong></td> <td align="center"><strong>Email</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center"><?php $id[]=$rows['id']; ?><?php echo $rows['id']; ?></td> <td align="center"><input name="month[]" MAXLENGTH="3" size="3" type="text" id="month" value="<?php echo $rows['month']; ?>">- <input name="date[]" MAXLENGTH="2" size="2" type="text" id="date" value="<?php echo $rows['date']; ?>"> </td> <td align="center"><input name="lastname[]" type="text" id="lastname" value="<?php echo $rows['lastname']; ?>"></td> <td align="center"><input name="email[]" type="text" id="email" value="<?php echo $rows['email']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> </table> <?php // Check if button name "Submit" is active, do this if (isset($_POST['Submit'])) { for($i=0;$i<$count;$i++){ $month = $_POST['month']; $date = $_POST['date']; $lastname = $_POST['lastname']; $email = $_POST['email']; $name = $month."<br>".$date; $sql1="UPDATE $tbl_name SET name='$name[$i]', month='$month[$i]', date='$date[$i]', lastname='$lastname[$i]', email='$email[$i]' WHERE id='$id[$i]'"; $result1=mysql_query($sql1); } } if($result1){ header("location:update2.php"); } ?> <?php $result = mysql_query("SELECT * FROM test_mysql") or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Name</th> <th>Age</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['name']; echo "</td><td>"; echo $row['lastname']; echo "</td></tr>"; } echo "</table>"; ?> What it does is this, it gets the row from the database, echos it and I am able to edit it and then save. The thing is, it works with the updating but im trying to combine 2 variables into 1 and update that one also. Im trying to combine month and date textboxes into one variable in the database that is name. It for some reason updates the column name to A instead of what I had in the 2 fields month and date. Here is where I combine both fields into one. $name = $month."<br>".$date; And here is where $month and $date is set. $month = $_POST['month']; $date = $_POST['date']; Here is a picture. Im trying to make a php program that will grab all the user's tweets they have ever done.. I'm using curl to request the twitter page and scrape the html. It looks as though the maximum amount of tweets I can get is 20, which is the amount on the initial first page. There is some script that loads another 20 tweets once I scroll to the bottom of the page... Does anyone know how to make the page automatically load a certain amount so I can scrape more than the first 20 at once. i'm trying to print posts just like facebook timeline with infinite scroll jquery and php, mysql. i wrote a inner join mysql query to fetch posts from groups and updates. The problem is i'm plagued by duplicate posts and unable to separate the group posts from updates in raw data. i tried a couple of times to sepearate and place them in jumbotron classes but i fail. Though the code is lengthy i hope to find some corrections and answers by sharing it. i need to prevent duplicate posts coming up through the query and printing while the ajax request go through's too. PHP class query: public function totalUpdates($friend,$session,$var_id, $load) { try{ $sql2="select distinct g.*,u.avatar,u.user_id,up.* from group_posts as g " . " join user as u on uname=g.author_gp " . " join updates as up on u.uname=up.author" . " where g.gname='MEP news' and (up.update_id >:update_id_all or g.gp_id>:update_id_all) and up.author in(:friend, :session) order by time,pdate desc limit $load,5 "; //$sql2="SELECT distinct update_id,update_body,time,title,user_id_u,account_name,author,data FROM updates where author in(:friend,:session) and update_id not in(:update_id_all) order by time desc limit $load,5"; $stmth= $this->_db->prepare($sql2);//Check here syntax of $db $stmth->bindValue(":friend",$friend); $stmth->bindValue(":session",$session); $stmth->bindValue(":update_id_all",$var_id); //$stmth->bindValue(":update_id2",$update_id2); $stmth->execute(); return $stmth->fetchAll(); } catch (PDOException $ei){ echo $ei->getMessage(); } } PHP script that prints values: $f = array(); $ids= array(); $stmt= $conn->prepare("select friend_one, friend_two from friends where (friend_one=:session OR friend_two=:session) and (friend_one>=:session or friend_two>=:session) and accepted='1'"); $stmt->bindparam(":session",$_SESSION['uname']); $stmt->execute(); $f=$stmt->fetchAll(); $f_count=count($f); $ids= ff($f, $project); //$k=0; //for ($k=0;$k<count($ids);$k++){ //while($i<$f_count){ //$id=$v; //$i=0; //foreach ($update_id1 as $i => $v) { $ex= explode(",", $update_id1[0]); $unique=array_unique($ex); $im= implode(",", $unique); //fetch username from update table in db and inject it to the feed query. $imp_id="'" .join( "','", $ids)."'";
*we get the $sess_count and $load from javascript in home page and forward the logic if load*2 is greater than
var load=0; var sess_uname="<?php echo $session_uname;?>"; var f_uname="<?php echo htmlspecialchars($_GET['u']);?>"; var sess_count="<?php echo $total_sess_count;?>"; var f_count="<?php echo $total_friend_count;?>"; var funame="<?php echo $f_uname0;?>"; $(".message").html("<div style='display: flex; justify-content: center;'><h1>Loading Posts...</h1> "+spinner1+"</div>").show(); if(sess_uname==f_uname){ $(window).scroll(function(){ //alert($(window).scrollTop()); // alert($(window).scrollTop()+" "+$(document).height()-$(window).height()); if($(window).scrollTop()==$(document).height()-$(window).height()){ var sub=$(document).height()-$(window).height(); //lert(sub); // alert($(window).scrollTop()+" "+sub); load++; var ids1=[]; var ids=$(".i-select i").text(); ids1.push(ids); //var arr=$(ids).serializeArray(); var arrJSON=JSON.stringify( ids1); var strids=ids.toString(); var newids = strids.split(","); var len=newids.length; // alert(newids); // for(x=0;x<len;x++){ // alert('ids:- ' + newids[x] +" len:- "+ len); var newid1=newids[load]; // alert(newids[x]); var first=$(".i-select i:first").text(); var last= $("i:last").text(); //console.log(first+"--1---2-- "+last); // alert(load+" "+sess_count); if(load * 5< sess_count){ $(".message").html("<h1>no more posts to show </h1>"); } else{ $.post("st&com.php", {"load":load,"sess_count":sess_count,"update_id2":last,"update_id1":arrJSON},function(data){ $(".message").html(spinner1).show(); $("#status_area").append(data); $(".hide").hide(); $(".message").html(spinner1).hide(); }); } } }); }else { $(window).scroll(function(){ if($(window).scrollTop()==$(document).height()-$(window).height()){ load++; // alert($(window).scrollTop()+" "+$(document).height()-$(window).height()); if(load *2 >f_count){ $(".message").html("<h1>no more posts to show here</h1>"); }else{ $.post("status_list.php", {funame:funame, load:load},function(data){ $(".message").html(spinner1).show(); $("#status_area").append(data); $(".hide").hide(); $(".message").html(spinner1).hide(); }); } } }); } sample output: Array ( [gp_id] => 103 [0] => 103 [pid] => 0 [1] => 0 [gname] => MEP news [2] => MEP news [author_gp] => aboutthecreator [3] => aboutthecreator [type] => a [4] => 0 [title] => qwertyu [5] => 2 [data] => [6] => <div>Etiam iaculis nunc ac metus. Praesent egestas tristique nibh.</div> <div> </div> <div>Fusce ac felis sit amet ligula !qwerty pharetra condimentum. Integer ante arcu, accumsan a, consectetuer eget, posuere ut, mauris.</div> <div> </div> <div>Proin viverra, ligula sit amet ultrices semper, ligula arcu tristique sapien !bart, a accumsan nisi mauris ac eros. Sed in libero ut nibh placerat accumsan.</div> <div> </div> <div>Phasellus leo dolor, tempus non, auctor et, hendrerit quis, nisi. Sed a libero. !qwerty</div> [pdate] => 2019-12-19 22:28:04 [7] => 2019-12-19 22:28:04 [vote_up] => 0 [8] => 0 [vote_down] => 0 [9] => 0 [group_id] => 25 [10] => 25 [author_id] => 142 [11] => 142 [avatar] => ThuJul1821235420191075.jpg [12] => ThuJul1821235420191075.jpg [user_id] => 142 [13] => 142 [update_id] => 381 [14] => 381 [update_body] => Lorem ipsum dolor sit amet,consetetur sadipscing elitr, no sea takimata sanctus est Lorem ipsum dolor sit amet. no sea takimata sanctus est Lorem ipsum dolor sit amet. no sea takimata sanctus est Lorem ipsum dolor sit amet. no sea takimata sanctus est Lorem ipsum dolor sit amet. sed diam voluptua. Lorem ipsum dolor sit amet, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, Lorem ipsum dolor sit amet, <a href="home.php?u=shan2batman">@shan2batman</a><br /><br />Lorem ipsum dolor sit amet,consetetur sadipscing elitr, sed diam voluptua. !qwerty Lorem ipsum dolor sit amet, consetetur sadipscing elitr, Lorem ipsum dolor sit amet, At vero eos et accusam et justo duo dolores et ea rebum. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, Stet clita kasd gubergren, <br /><br />Lorem ipsum dolor sit amet,sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, Stet clita kasd gubergren, consetetur sadipscing elitr, sed diam voluptua. sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, At vero eos et accusam et justo duo dolores et ea rebum. sed diam voluptua. no sea takimata sanctus est Lorem ipsum dolor sit amet. <br /><br />Lorem ipsum dolor sit amet,sed diam voluptua. Lorem ipsum dolor sit amet, sed diam voluptua. sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, At vero eos et accusam et justo duo dolores et ea rebum. sed diam voluptua. sed diam voluptua. Stet clita kasd gubergren, <br /><br />Lorem ipsum dolor sit amet,no sea takimata sanctus est Lorem ipsum dolor sit amet. Stet clita kasd gubergren, At vero eos et accusam et justo duo dolores et ea rebum. consetetur sadipscing elitr, At vero eos et accusam et justo duo dolores et ea rebum. sed diam voluptua. Lorem ipsum dolor sit amet, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, Stet clita kasd gubergren, <br /><br />Lorem ipsum dolor sit amet,consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, At vero eos et accusam et justo duo dolores et ea rebum. sed diam voluptua. sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. sed diam voluptua. <br /><br />Lorem ipsum dolor sit amet,consetetur sadipscing elitr, At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. sed diam voluptua. consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, <br /><br />Lorem ipsum dolor sit amet,Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At vero eos et accusam et justo duo dolores et ea rebum. consetetur sadipscing elitr, At vero eos et accusam et justo duo dolores et ea rebum. At vero eos et accusam et justo duo dolores et ea rebum. no sea takimata sanctus est Lorem ipsum dolor sit amet. sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, consetetur sadipscing elitr, <br /><br />Lorem ipsum dolor sit amet,Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam voluptua. Stet clita kasd gubergren, Lorem ipsum dolor sit amet, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, <br /><br />Lorem ipsum dolor sit amet,At vero eos et accusam et justo duo dolores et ea rebum. sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, At vero eos et accusam et justo duo dolores et ea rebum. consetetur sadipscing elitr, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, sed diam voluptua. Stet clita kasd gubergren, <br /><br /> [15] => Lorem ipsum dolor sit amet,consetetur sadipscing elitr, no sea takimata sanctus est Lorem ipsum dolor sit amet. no sea takimata sanctus est Lorem ipsum dolor sit amet. no sea takimata sanctus est Lorem ipsum dolor sit amet. no sea takimata sanctus est Lorem ipsum dolor sit amet. sed diam voluptua. Lorem ipsum dolor sit amet, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, Lorem ipsum dolor sit amet, <a href="home.php?u=shan2batman">@shan2batman</a><br /><br />Lorem ipsum dolor sit amet,consetetur sadipscing elitr, sed diam voluptua. !qwerty Lorem ipsum dolor sit amet, consetetur sadipscing elitr, Lorem ipsum dolor sit amet, At vero eos et accusam et justo duo dolores et ea rebum. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, Stet clita kasd gubergren, <br /><br />Lorem ipsum dolor sit amet,sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, Stet clita kasd gubergren, consetetur sadipscing elitr, sed diam voluptua. sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, At vero eos et accusam et justo duo dolores et ea rebum. sed diam voluptua. no sea takimata sanctus est Lorem ipsum dolor sit amet. <br /><br />Lorem ipsum dolor sit amet,sed diam voluptua. Lorem ipsum dolor sit amet, sed diam voluptua. sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, At vero eos et accusam et justo duo dolores et ea rebum. sed diam voluptua. sed diam voluptua. Stet clita kasd gubergren, <br /><br />Lorem ipsum dolor sit amet,no sea takimata sanctus est Lorem ipsum dolor sit amet. Stet clita kasd gubergren, At vero eos et accusam et justo duo dolores et ea rebum. consetetur sadipscing elitr, At vero eos et accusam et justo duo dolores et ea rebum. sed diam voluptua. Lorem ipsum dolor sit amet, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, Stet clita kasd gubergren, <br /><br />Lorem ipsum dolor sit amet,consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, At vero eos et accusam et justo duo dolores et ea rebum. sed diam voluptua. sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. sed diam voluptua. <br /><br />Lorem ipsum dolor sit amet,consetetur sadipscing elitr, At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. sed diam voluptua. consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, <br /><br />Lorem ipsum dolor sit amet,Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At vero eos et accusam et justo duo dolores et ea rebum. consetetur sadipscing elitr, At vero eos et accusam et justo duo dolores et ea rebum. At vero eos et accusam et justo duo dolores et ea rebum. no sea takimata sanctus est Lorem ipsum dolor sit amet. sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, consetetur sadipscing elitr, <br /><br />Lorem ipsum dolor sit amet,Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam voluptua. Stet clita kasd gubergren, Lorem ipsum dolor sit amet, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, <br /><br />Lorem ipsum dolor sit amet,At vero eos et accusam et justo duo dolores et ea rebum. sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, At vero eos et accusam et justo duo dolores et ea rebum. consetetur sadipscing elitr, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, sed diam voluptua. Stet clita kasd gubergren, <br /><br /> [url] => [16] => [time] => 2018-11-10 22:58:36 [17] => 2018-11-10 22:58:36 [host] => [18] => [19] => 0 [20] => 0 [21] => qwertyu [user_id_u] => 142 [22] => 142 [account_name] => aboutthecreator [23] => aboutthecreator [author] => aboutthecreator [24] => aboutthecreator [25] => a [26] => )
Hi, I want to fetch some xml data from google website to my website using curl library. i tried. it display nothing to me even my error display is enabled. can any one guide me with small example how can i get sml content using curl. Thanks I have an integration with a third party that utilizes a SOAP API. On my current server AND my local environment, this works fine. I recently deployed a new server and it seems that cURL isn't doing anything. *The code is identical on all three installations. The "error" that I am seeing is no response at all (no response and no error, however, I can see that it is a "Resource"). After much trial and error, I tried creating a simple cURL example to test try to rule out other issues as the code itself is quite complex. My simple example, that also fails, is as follows: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "google.com"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); $err = curl_error($ch); print_r($err); echo $output; curl_close($ch); This does the same thing. On local, I get a "301 Moved" notice, on the new server, it is just a white screen. I have confirmed that php has curl installed in via command line (php -m) and using phpinfo(); in my code. It is definitely enabled. What would cause cURL to not have a response AND not have an error? My thought is a server setting, but I can't seem to find what might be causing this. Edited July 7, 2020 by rklocknerUsers make entries into a form on my site which are then sent to a remote server which generates a variable length page of results for the users perusal. I want the results to be displayed on my site but I discover that iframe height is a problem so I am trying PHP in a separate file to avoid an iframe. Then maybe I can cache the result pages and display them without any height difficulties and not having to fiddle with javascript. The first PHP code I try is prevented from working and I discover that the apparent cause is the issue of fopen and fsockopen etc. being set to off by the host that I use because of security concerns: $url="http://remote_server.cgi"; foreach($_POST as $key => $value) {$url .="$key=" . urlencode($value) . "&";} $array = file($url);] The host has cURL so I try that but the form entries are not being accepted as they are with a direct post from the form: $URL="http://remote_server.cgi"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $URL); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST); curl_exec ($ch); curl_close ($ch); In case useragent is a problem at the remote server, I added: curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); I know all entries are received by the separate file by using: print_r($_POST); But the remote server still says "Error in form found. You are not authorized etc. etc... " Apparently the post data is not being sent like the form sends it. Any suggestions? I have never used cURL before but I need to use it for developing a facebook application. What I am trying to do is create a status update scheduler. There are two tables in my database. One table has generic updates for each day of the week an the other had special events. My script checks the day, checks to see if there is a special event in the future on that day, and if there is reminds guests of the upcoming event. If there is no event it posts the generic status. Code: [Select] <?php include('config.php'); $result2 = mysql_query("select facebook_id,facebook_access_token from admin where username='users'"); $row = mysql_fetch_array($result2); $facebook_id = $row['facebook_id']; $facebook_access_token = $row['facebook_access_token']; $day = date('N'); $result2 = mysql_query("select * from events where date > CURDATE() order by date ASC") or die(mysql_error()); $num_rows = mysql_num_rows($result2); if($num_rows == 0) { $result2 = mysql_query("select * FROM alerts WHERE id='$day'") or die(mysql_error()); $row1 = mysql_fetch_array($result2); echo 'There are no events just alerts'; } else { while($row = mysql_fetch_array($result2)){ if(date('N',strtotime($row[date])) == $day) { $id = $row['id']; $result1 = mysql_query("SELECT * FROM events WHERE id = $id") or die(mysql_error()); $row1 = mysql_fetch_array($result1); } else { $result1 = mysql_query("SELECT * FROM alerts WHERE id = $day") or die(mysql_error()); $row1 = mysql_fetch_array($result1); } } } $params = array('access_token' => $facebook_access_token, 'message' => $row1[alert_message], 'name'=> $row1[alert_name], 'caption' => $row1[alert_caption], 'link' => $row1[alert_link], 'description' => $row1[alert_description], 'picture' => $row1[alert_picture] ); $url = "https://graph.facebook.com/$facebook_id/feed"; $ch = curl_init(); curl_setopt_array($ch, array( CURLOPT_URL => $url, CURLOPT_POSTFIELDS => $params, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_VERBOSE => true )); $result = curl_exec($ch); ?> The problem seems to be occurring when the While loop is accessed. I have used 'echo' to follow the variables through the script and it all seems to be working. However if I try and execute the cURL and the While Loop has run then it does not seem to work. I know the cURL part works becuase if the variables cause the first IF statement default to ELSE then it runs fine. Any help would be GREATLY appreciated. Ive tried everything and cannot get this POST to work, page comes up blank. The output of curlgetinfo() shows: Code: [Select] Array ( [url] => http://app.alliedinsurance.com/find_agent/calcpage4_1_popup.cfm?RequestTimeout=180 [content_type] => text/html; charset=UTF-8 [http_code] => 200 [header_size] => 329 [request_size] => 450 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.172622 [namelookup_time] => 0.02064 [connect_time] => 0.092116 [pretransfer_time] => 0.092244 [size_upload] => 0 [size_download] => 509 [speed_download] => 2948 [speed_upload] => 0 [download_content_length] => 0 [upload_content_length] => 0 [starttransfer_time] => 0.172563 [redirect_time] => 0 ) The whole code Im using: Code: [Select] <h2>Please Enter Zip Code</h2> <p> <form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>"> <input type="text" size="10" maxlength="10" name="zipcode" tabindex="1" value="<?php echo $_POST['zipcode'];?>" /> <input type="submit" value="Search" name="submit" tabindex="2" /> </form> <br /> <?php if(isset($_POST['submit'])) { $zipcode = $_POST['zipcode']; $userAgent = 'Mozilla/5.0 (Windows NT 6.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1'; $mercurl = "http://app.alliedinsurance.com/find_agent/calcpage4_1_popup.cfm?RequestTimeout=180"; $postcom = "City=&State=AR&ZipCode=" . urlencode($zipcode) . "&Miles=" . urlencode('20') . "&SubmitThis=Submit"; $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); curl_setopt($ch, CURLOPT_URL,$mercurl); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_TIMEOUT, 100); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HEADER_OUT, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt'); curl_setopt($ch, CURLOP_REFERRER, "http://app.alliedinsurance.com/find_agent/find_an_agent_popup.cfm"); curl_setopt($ch,CURLOPT_POST, 1); curl_setopt($ch,CURLOPT_POSTFIELDS,$postcom); $html = curl_exec($ch); print_r(curl_getinfo($ch)); $html = @mb_convert_encoding($html, 'HTML-ENTITIES', 'utf-8'); curl_close( $ch ); echo $html; ?> Hi everyone
I've look all other the web for a work around that.
basically my problem is:
if i use file_get_contents or curl to get www.google.fr, there is NO problem. i get the data i want
but when i try to use it on another target it doesn't work. it loads and loads for couple seconds and finally says that it could not retrieve informations.
the target is not blocked as i can personnally use it on my webhost, but some people on other webhosts can't.
A friend of mine told me that it was because some webhosts blocks unsecure targets.
Is there any way around it?
$context = stream_context_create(array( 'http' => array( 'header' => "Authorization: Basic " . base64_encode("admin:$password") ) )); $data = file_get_contents("http://TARGETHOST:29015/status.json", false, $context); $status = json_decode($data); var_dump($status);(And again this works on my webhost, i can query like that any servers i want, but others can't use this they get a timeout trying it (when doing a file_get_contents on google works)) I am trying to create a remote login to one website using mine. The users will need to enter their username and password on my site, and if they are registered to my website, their login credentials will be sent to another website and a page will be retrieved.
I am stuck at sending the users' data to the original site. The original site's viewsource is this..
<form method=post> <input type="hidden" name="action" value="logon"> <table border=0> <tr> <td>Username:</td> <td><input name="username" type="text" size=30></td> </tr> <tr> <td>Password:</td> <td><input name="password" type="password" size=30></td> </tr> <td></td> <td align="left"><input type=submit value="Sign In"></td> </tr> <tr> <td align="center" colspan=2><font size=-1>Don't have an Account ?</font> <a href="?action=newuser"><font size=-1 color="#0000EE">Sign UP Now !</font></a></td> </tr> </table>I have tried this code, but not works. <?php $username="username"; $password="password"; $url="http://www.example.com/index.php"; $postdata = "username=".$username."&password=".$password; $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 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_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_REFERER, $url); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt ($ch, CURLOPT_POST, 1); $result = curl_exec ($ch); header('Location: track.html'); //echo $result; curl_close($ch); ?>Any help would be appreciated, Thanks in advance. I have a CURL code that fetches some XML content from a remote server. I get the expected output on my localhost (XAMPP on windows). But from the live site(hosted on Linux), I get the CURL error:'couldn't connect to host'. function DownloadUrl($Url, $p){ // is curl installed? if (!function_exists('curl_init')){ die('CURL is not installed!'); } // create curl resource $ch = curl_init(); // set url curl_setopt($ch, CURLOPT_URL, $Url); curl_setopt ($ch, CURLOPT_POSTFIELDS, $p); curl_setopt ($ch, CURLOPT_POST, 1); //return the transfer as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // $output contains the output string $output = curl_exec($ch); if($output === false) echo 'Curl error: ' . curl_error($ch); else print $output; // close curl resource to free up system resources curl_close($ch); } Hi All, My goal is to process all redirects serverside and simply return the user to the 'final' URL. Here's my function to get the final URL: PHP Code: function get_final_url($url){ global $final_host; $redirects = get_all_redirects($url); if (count($redirects)>0){ $final_url = array_pop($redirects); if(substr($final_url,0,7) != 'http://' && !empty($final_host)) { $final_url = 'http://'.$final_host.$final_url; } return $final_url; } else { return $url; } Here's the cURL execution: $ch2 = curl_init(); curl_setopt($ch2,CURLOPT_URL,$url); curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch2,CURLOPT_POST,''); curl_setopt($ch2,CURLOPT_POSTFIELDS,''); curl_exec($ch2); curl_close($ch2); For some reason, this works no problem, posts any data over to the URLs serverside, redirects serverside, and passes the client to the final URL, with none of the redirection displayed via HTTPWatch or any similar debug utility. Sometimes, however, it does show phases of redirection. Any insight into what I might be doing incorrectly? Thanks SO much in advance. E Hello! I have a twitter button. But I would like to have a form button's action to activate the "tweet/share" link. Why? Because I want to record in mySQL database the fact that someone has in fact clicked the link to tweet. How I was thinking about doing... But really have no idea is like so. <form action="tweet.php" method="POST"> <input type="button" name="tweet" value="ip address" /> </form> then in the tweet.php I would have php insert the gathered IP address (ive got this part working with a geocoder class) into the database as confirmation. Then the php code would execute the hyperlink / java which is this: <a href="http://twitter.com/share" class="twitter-share-button" data-url="http://mycontent.com" data-count="horizontal" data-via="person-to-tweet-at">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> Activating the link as if someone where to click the link, but automatically. Basically I am looking for a way to record who clicks the Twitter button. Any guidance on this topic would be much appreciated. |