Jump to content

hellonoko

Members
  • Posts

    213
  • Joined

  • Last visited

Everything posted by hellonoko

  1. First its nice if you put your code in code Hit the # button above. Next... if ($hpos !== false) { $high = substr_replace($high, "", $hpos); } $photo_display .= "{$photo}' width='{$wide}' height='{$high}' />"; //THIS ONE DOESN’T DISPLAY } else Wtf are {? if your using a $variable you need to break out of single quotes? $photo_display .= '"'.$photo.'" width="'.$wide.'" height="'.$high.'"/>'; or something. Here is how i display a image from a db on a page of mine. echo "<td><img src=../images/thumbs/t_".$row[image]." /></td>";
  2. $ip=$_SERVER['REMOTE_ADDR']; You might want to also store that they have voted in a cookie to double check it.
  3. Well you will want to set the format you return the time(); in before you compare them. It depends on if your comparing unix time stamps or dates and times you put in. In your format. There are a lot of usefull functions for time in php. Take a search for 'php time.' This link look like it has some info also: http://www.ozzu.com/programming-forum/compare-time-with-php-t69163.html
  4. Forgot to mention you should also add or die(mysql_error()); After your sql statements and any errors will show up and that always helps.
  5. Not sure if this make sense but. Say the session is empty or wrong. Then your: if ($result = mysql_query($sql)) Is going to return nothing. And so your return $amount; will return empty? Maybe put in a if ct_session_id == EMPTY or NULL then set a value for $amount. if session != empty do SQL else return $amount = 0; Not sure if that is right or makes sense?
  6. You should probably put you code up so we can see it? You could also do something were rather than having two tables you had one table and a 'fruit type' column then you could: SELECT * FROM fruit WERE fruittype = 'citrus' AND bruised = 'FALSE' You could use a union to combine queries and then display the results.
  7. I am using strpos() to compare URLS. However in my function it doesn't seem to return anything. When I copy the bit of code out into its own page or outside of my function it works. Any ideas? Code is on line 74. Thanks. <?php //error_reporting(E_ALL); //echo $site_url = 'http://www.empreintes-digitales.fr/'; $target_url = "http://www.empreintes-digitales.fr"; //$target_url = 'http://redthreat.wordpress.com/'; //$target_url= 'http://www.kissatlanta.com/blog/'; //$target_url= 'http://www.empreintes-digitales.fr/'; $url = ""; $link = ""; $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; crawl_page( $target_url, $userAgent); function crawl_page( $target_url, $userAgent) { $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); curl_setopt($ch, CURLOPT_URL,$target_url); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $html = curl_exec($ch); if (!$html) { echo "<br />cURL error number:" .curl_errno($ch); echo "<br />cURL error:" . curl_error($ch); exit; } // // load scrapped data into the DOM // $dom = new DOMDocument(); @$dom->loadHTML($html); // // get only LINKS from the DOM with XPath // $xpath = new DOMXPath($dom); $hrefs = $xpath->evaluate("/html/body//a"); // // go through all the links and store to db or whatever // for ($i = 0; $i < $hrefs->length; $i++) { $href = $hrefs->item($i); $url = $href->getAttribute('href'); $links_1[$link] = $url; //echo $absolute_links[$link] = relative2absolute($target_url, $url); //echo '<br>'; //if the $url does not contain the web site base address: http://www.thesite.com/ then add it onto the front echo gettype($url); echo gettype($target_url); echo '<b>'; echo $pos = strpos($url , $target_url); echo '</b>'; if ( $pos == FALSE ) { echo 'INCOMPLETE: '.$url; echo '<br>'; } else { echo 'COMPLETE: '.$url; echo '<br>'; } } }
  8. Will take a look but still not sure what is up with my code. When I have it in a page on it own it works. But in the full code below it fails. <?php //echo $site_url = 'http://www.empreintes-digitales.fr/'; $target_url = "http://www.empreintes-digitales.fr/"; //$target_url = 'http://redthreat.wordpress.com/'; //$target_url= 'http://www.kissatlanta.com/blog/'; //$target_url= 'http://www.empreintes-digitales.fr/'; $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; crawl_page( $target_url, $userAgent, $site_url, $url); function crawl_page( $target_url, $userAgent , $site_url, $url ) { $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); curl_setopt($ch, CURLOPT_URL,$target_url); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $html = curl_exec($ch); if (!$html) { echo "<br />cURL error number:" .curl_errno($ch); echo "<br />cURL error:" . curl_error($ch); exit; } // // load scrapped data into the DOM // $dom = new DOMDocument(); @$dom->loadHTML($html); // // get only LINKS from the DOM with XPath // $xpath = new DOMXPath($dom); $hrefs = $xpath->evaluate("/html/body//a"); // // go through all the links and store to db or whatever // for ($i = 0; $i < $hrefs->length; $i++) { $href = $hrefs->item($i); $url = $href->getAttribute('href'); $links_1[$link] = $url; //if the $url does not contain the web site base address: http://www.thesite.com/ then add it onto the front if ( strpos($url , $target_url) === FALSE ) { echo 'INCOMPLETE: '.$url; echo '<br>'; } else { echo 'COMPLETE: '.$url; echo '<br>'; } } } ?>
  9. Well.... I am pretty sure you query is bad. $data = mysql_query("SELECT * FROM users WHERE 'name' = " . $user . ";"); Should be: mysql_query("SELECT * FROM users WHERE name = $user") Here is example query from a page of mine: $query = "SELECT rank FROM ideas WHERE id=$delete_idea" or die (mysql_error()); The OR DIE is good will show you if mysql is messing up. You could also put: error_reporting(E_ALL); At the top of your page to force it to report every tiny error.
  10. I am using the below code to compare a base url : http://www.site.com/ to a list of scraped urls. If the scraped url ($url) does not contain the base url ($target_url) it combines the two to make a full url. so files/login.php turns into www.site.com/files/login.php However. It doesn't seem to be comparing correctly. For sites that do contain the base URL already it will turn them into www.site.com/index.htmlwww.site.com/index.html I have tried with strcmp() also. Any ideas? if ( strstr($url , $target_url) === FALSE ) { echo 'INCOMPLETE: '.$url; //echo $target_url.$url; echo '<br>'; } else { echo 'COMPLETE: '.$url; echo '<br>'; }
  11. And this time I did solve it. I was not passing the variable to my function.
  12. Actually that was not it because if I put the variable down near the code it works but at the top of the page if fails.
  13. Had nothing to do with POST for some reason though.... having the "<br><br>' in the variable caused problems. idk.
  14. I have a simple site scraper that uses CURL. I was just adding some code to it that compares certain links to the base site address and then completes them if necessary. For example if it scans: index.php it makes that link into http://www.site.com/login.php My problem is that $site_url (line 3) at the very top of the page echos correctly. But then when I get down to line 91 where I have put in a echo to test it. Nothing. Empty. These are the only two times it is called. Where is it going? I even tried adding a echo at the very bottom end of my code to make sure it wasn't just me using it in the wrong place or something. Any ideas? Thanks. <?php echo $site_url = 'http://www.empreintes-digitales.fr<br><br>'; $target_url = 'http://www.empreintes-digitales.fr/index.php?post=794'; //$target_url = 'http://redthreat.wordpress.com/'; //$target_url= 'http://www.kissatlanta.com/blog/'; //$target_url= 'http://www.empreintes-digitales.fr/'; $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; crawl_page( $target_url, $userAgent); function crawl_page( $target_url, $userAgent) { $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); curl_setopt($ch, CURLOPT_URL,$target_url); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $html = curl_exec($ch); if (!$html) { echo "<br />cURL error number:" .curl_errno($ch); echo "<br />cURL error:" . curl_error($ch); exit; } // // load scrapped data into the DOM // $dom = new DOMDocument(); @$dom->loadHTML($html); // // get only LINKS from the DOM with XPath // $xpath = new DOMXPath($dom); $hrefs = $xpath->evaluate("/html/body//a"); // // go through all the links and store to db or whatever // for ($i = 0; $i < $hrefs->length; $i++) { $href = $hrefs->item($i); $url = $href->getAttribute('href'); $links_1[$link] = $url; echo $url; echo '<br>'; } for ($i = 0; $i < $hrefs->length; $i++) { $href = $hrefs->item($i); $url = $href->getAttribute('href'); $find = ".mp3"; $pos = strpos($url, $find); if ($pos === false) { } else { // function to store to db //storeLink($url,$target_url); echo 'File: '; echo $url; echo '<br>'; $last_slash = strripos( $url ,"/"); $clean_file_name = substr( $url , $last_slash + 1 , strlen($url) ); //fixes the url if it does not have a FULL address echo $site_url; if ( strstr( $url , $base_url) != TRUE ) { echo '<b>BROKEN URL</b><br>'; echo $base_url; $url = $base_url . $url; echo 'FIXED URL: '.$url.'<BR>'; } exit(); echo 'From: '; echo $target_url; echo '<br>'; //directory to copy to (must be CHMOD to 777) $copydir = "/home2/sharingi/public_html/scrape/scraped/"; $data = file_get_contents($url); $file = fopen($copydir . $clean_file_name, "w+"); fputs($file, $data); fclose($file); //$savefile="tempimg/".time().".jpg"; //$ch = curl_init ($copydir); //$fp = fopen ($copydir . $clean_file_name, "w+"); //curl_setopt ($ch, CURLOPT_FILE, $fp); //curl_setopt ($ch, CURLOPT_HEADER, 0); //curl_exec ($ch); //curl_close ($ch); //fclose ($fp); //echo "Coppied!"; //echo "<br><br>"; } } } ?>
  15. I am using the below script to scrape mp3s from a music blog. However after copying about 5 songs I receive this error: Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 26738688 bytes) in /home2/sharingi/public_html/scrape/scrape.php on line 78 Is there anyways I can change my code so that I don't do this. Somehow clearing memory between file copies? Thanks <?php $target_url = 'http://redthreat.wordpress.com/'; $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); curl_setopt($ch, CURLOPT_URL,$target_url); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $html = curl_exec($ch); if (!$html) { echo "<br />cURL error number:" .curl_errno($ch); echo "<br />cURL error:" . curl_error($ch); exit; } // // load scrapped data into the DOM // $dom = new DOMDocument(); @$dom->loadHTML($html); // // get only LINKS from the DOM with XPath // $xpath = new DOMXPath($dom); $hrefs = $xpath->evaluate("/html/body//a"); // // go through all the links and store to db or whatever // for ($i = 0; $i < $hrefs->length; $i++) { $href = $hrefs->item($i); $url = $href->getAttribute('href'); $find = ".mp3"; $pos = strpos($url, $find); if ($pos === false) { } else { // function to store to db //storeLink($url,$target_url); echo $url; echo '<br>'; $last_slash = strripos( $url ,"/"); $clean_file_name = substr( $url , $last_slash + 1 , strlen($url) ); echo '<br>'; //echo $target_url; //echo '<br><br>'; //directory to copy to (must be CHMOD to 777) $copydir = "/home2/sharingi/public_html/scrape/scraped/"; $data = file_get_contents($url); $file = fopen($copydir . $clean_file_name, "w+"); fputs($file, $data); fclose($file); echo "Coppied!"; echo "<br><br>"; } } ?>
  16. I have a script that creates a xspf playlist from a directory of files. However when I try to make the playlist random by using: shuffle(); instead of arsort(); the script write 0 1 2 3 etc to the XML file rather than the file names as arsort(); does. The line in question is 59: shuffle($arr); Any ideas? <?php //require_once("/flashupload2/config.php"); //////////////////////////////////////////////// /////////////////////////////////////////////// $username = "sharingi_music"; $password = "music"; $hostname = "localhost"; $db_connect = mysql_connect( $hostname , $username, $password) or die ("Unable to connect to database"); mysql_select_db( "sharingi_music" , $db_connect); ///////////////////////////////////////////////// //////////////////////////////////////////////// // create doctype $dom = new DOMDocument("1.0"); // display document in browser as plain text // for readability purposes //header("Content-Type: text/plain"); // create root element $root = $dom->createElement("playlist"); $dom->appendChild($root); // create attribute node $version = $dom->createAttribute("version"); $root->appendChild($version); // create attribute value node $versionValue = $dom->createTextNode("1.0"); $version->appendChild($versionValue); // create attribute node $xmnls = $dom->createAttribute("xmlns"); $root->appendChild($xmnls); // create attribute value node $xmnlsValue = $dom->createTextNode("http://xspf.org/ns/0/"); $xmnls->appendChild($xmnlsValue); // create track element $trackList = $dom->createElement("trackList"); $root->appendChild($trackList); $dir = '/home2/sharingi/public_html/REPOSITORY/'; foreach (glob( $dir.'*.*') as $filename) { $arr[$filename] = filemtime($filename); } shuffle($arr); foreach($arr as $key => $value) { if ( $key !== "/home2/sharingi/public_html/REPOSITORY/filelist3.php" && $key !== "/home2/sharingi/public_html/REPOSITORY/index.php" ) { $key = str_replace( "/home2/sharingi/public_html/REPOSITORY/" , "" , $key); //echo $key; //echo '<br>'; // create track element $track = $dom->createElement("track"); $trackList->appendChild($track); // create child element of track called location. $location = $dom->createElement("location"); $track->appendChild($location); //create location link $link = $dom->createTextNode("http://www.site.com/REPOSITORY/". $key); $location->appendChild($link); // create child element of track called title. $title = $dom->createElement("title"); $track->appendChild($title); ///get the song name// $result = mysql_query("SELECT SONG FROM songs WHERE HIDDENNAME = '$key'"); while ($row = mysql_fetch_row($result)) { $songname = $row[0]; } //create title data $songTitle = $dom->createTextNode("$songname"); $title->appendChild($songTitle); } } // save and display tree $dom->save("playlist.xspf"); mysql_close ( $db_connect); ?> <object type="application/x-shockwave-flash" width="400" height="170" data="http://www.site.com/fullplayer/xspf_player.swf?playlist_url=http://www.site.com/fullplayer/playlist.xspf"> <param name="movie" value="http://www.site.com.com/fullplayer/xspf_player.swf?playlist_url=http://www.site.com/fullplayer/playlist.xspf" /> </object>
  17. What about a javascript popup window instead of a alert. You could use focus() to bring it to the front so they see it? Then you can have whatever page inside the popup with options for the user to click.
  18. I am new to XML and trying to do a RSS tutorial. I am receiving the following error, </channel> is almost at the bottom: XML Parsing Error: not well-formed Location: http://www.sharingizcaring.com/rss/ Line Number 1, Column 3: </channel> ---------^ Code: <? class RSS { public function RSS() { require_once ('mysql_connect.php'); } public function GetFeed() { return $this->getDetails() . $this->getItems(); } private function dbConnect() { DEFINE ('LINK', mysql_connect (DB_HOST, DB_USER, DB_PASSWORD)); } private function getDetails() { $detailsTable = "webref_rss_details"; $this->dbConnect($detailsTable); $query = "SELECT * FROM ". $detailsTable; $result = mysql_db_query (DB_NAME, $query, LINK); while($row = mysql_fetch_array($result)) { $details = '<?xml version="1.0" encoding="ISO-8859-1" ?> <rss version="2.0"> <channel> <title>'. $row['title'] .'</title> <link>'. $row['link'] .'</link> <description>'. $row['description'] .'</description> <language>'. $row['language'] .'</language> <image> <title>'. $row['image_title'] .'</title> <url>'. $row['image_url'] .'</url> <link>'. $row['image_link'] .'</link> <width>'. $row['image_width'] .'</width> <height>'. $row['image_height'] .'</height> </image>'; } return $details; } private function getItems() { $itemsTable = "webref_rss_items"; $this->dbConnect($itemsTable); $query = "SELECT * FROM ". $itemsTable; $result = mysql_db_query (DB_NAME, $query, LINK); $items = ''; while($row = mysql_fetch_array($result)) { $items .= '<item> <title>'. $row["title"] .'</title> <link>'. $row["link"] .'</link> <description><![CDATA['. $row["description"] .']]></description> </item>'; } $items .= '</channel> </rss>'; return $items; } } ?>
  19. Oh wow. I had a huge bowl of stupid for breakfast. Thanks.
  20. I'm sure this is something simple I am just not seeing but I can't find it. What am I missing here? Parse error: syntax error, unexpected ';' in /home2/sharingi/public_html/emocowgirl/admin/ideas.php on line 23 Line 23 is: $result = mysql_query("SELECT * FROM IDEAS WHERE ID = '$ideatoedit'"); <?php //////////////////////////////////////////////// /////////////////////////////////////////////// $username = "sharingi_emo"; $password = "emo"; $hostname = "localhost"; $db_connect = mysql_connect( $hostname , $username, $password) or die ("Unable to connect to database"); mysql_select_db( "sharingi_emocowgirl" , $db_connect); ///////////////////////////////////////////////// //////////////////////////////////////////////// $action = $HTTP_GET_VARS['action']; $ideatoedit = intval($HTTP_GET_VARS['item']); if ( $action == "edit") ( $result = mysql_query("SELECT * FROM IDEAS WHERE ID = '$ideatoedit'"); while ($row = mysql_fetch_row($result)) { } echo '<form action="ideas.php" method="get" name="ideas" id="ideas">'; echo '<label>'; echo '<textarea name="idea" id="idea" cols="45" rows="5">'.$row['idea'].'</textarea>'; echo '</label>'; echo '<label>'; echo '<textarea name="image" id="image" cols="45" rows="5">'.$row['image'].'</textarea>'; echo '</label>'; echo '<label> <br>'; echo '<input type="submit" name="update" id="update" value="Update...">'; echo '</label></form>'; ) else ( echo '<form action="ideas.php" method="get" name="ideas" id="ideas">'; echo '<label>'; echo '<textarea name="idea" id="idea" cols="45" rows="5"></textarea>'; echo '</label>'; echo '<label>'; echo '<textarea name="image" id="image" cols="45" rows="5"></textarea>'; echo '</label>'; echo '<label> <br>'; echo '<input type="submit" name="add" id="add" value="It Hurts...">'; echo '</label></form>'; ) ?> <?php $idea = $HTTP_GET_VARS['idea']; $image = $HTTP_GET_VARS['image']; if ($idea != "") { $query = mysql_query("SELECT * FROM ideas WHERE idea = '$idea'"); $rows = mysql_num_rows($query); if ( $rows == 0 ) { mysql_query("INSERT INTO ideas ( IDEA, IMAGE ) VALUES ( '$idea' , '$image' )") or die (mysql_error()); } } ///display everything $result = mysql_query("SELECT * FROM ideas"); while ($row = mysql_fetch_assoc($result)) { echo '<a href="ideas.php?action=edit&item='.$row['id'].'"><img src="http://www.emocowgirl.com/images/pencil.png" alt="Edit" width="16" height="16" border="0"></a>'; echo $row['idea']; echo " | "; echo $row['image']; echo '</br>'; } ?>
  21. I am trying to design a way in wich I could automate the following of download links in PHP. For example: https://www.yousendit.com/transfer.php?action=batch_download&batch_id=TTZuZXR6Y1M3bUN4dnc9PQ Or: http://www.zshare.net/audio/5176345521c01f22 I would like to automate the downloading of files from sites like these so that I could batch download a series of links. I have made something similar before where a PHP script I wrote would load a HTML page from myspace and scan it for certain content. I think in this case what I would need to do is depending on the site allow for processing of multiple pages or delays. How would I accomplish this with PHP? Also some download sites use a header pushing the download rather a direct link to the file. How would I incorporate that into something like file_get_contents() fopen() and fputs() Is php capable of this kind of thing? Thanks, ian
  22. I am trying to build a XML document like this one dynamically: <?xml version="1.0" encoding="UTF-8"?> <playlist version="1" xmlns="http://xspf.org/ns/0/"> <trackList> <track><location>file:///mp3s/song_1.mp3</location></track> <track><location>file:///mp3s/song_2.mp3</location></track> <track><location>file:///mp3s/song_3.mp3</location></track> </trackList> </playlist> My code so far: <?php // create doctype $dom = new DOMDocument("1.0"); // display document in browser as plain text // for readability purposes header("Content-Type: text/plain"); // create root element $root = $dom->createElement("playlist"); $dom->appendChild($root); // create child element $item = $dom->createElement("track"); $root->appendChild($item); // create text node $item = $dom->createElement("location"); $root->appendChild($item); // save and display tree $dom->save("playlist.xml"); ?> For some reason the createElement location tag is not working. But I am very new to XML so I am not sure what I am doing. Thanks, ian
  23. I found this solution that seems to work well. function compareDates($date1,$date2) { $date1_array = explode("-",$date1); $date2_array = explode("-",$date2); $timestamp1 = mktime(0,0,0,$date1_array[1],$date1_array[2],$date1_array[0]); $timestamp2 = mktime(0,0,0,$date2_array[1],$date2_array[2],$date2_array[0]); return ($timestamp1 - $timestamp2); } $daystillupload = compareDates( $date = date('Y-m-d'), $lastuploaddate) / 86400;
  24. Tried: $daystillupload = strtotime(date('Y-m-d')) - strtotime($lastuploaddate); And: $daystillupload = date('Y-m-d') - strtotime($lastuploaddate); Both return: 1226989592 $lastuploaddate contains 2008-11-18
  25. echo $daystillupload = date('Y-m-d') - "2008-11-18"; Is my code to compare the current date with the last login date and display how many days since a person last logged in. This should return 1. But returns 0? What am I doing wrong. Thanks, ian
×
×
  • 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.