Jump to content

supertrucker

Members
  • Posts

    171
  • Joined

  • Last visited

Everything posted by supertrucker

  1. Wow, I feel a little dumb now! I was calling the method with '::' instead of '->', thanks!
  2. Hello,I have written a custom class that is going to handle all of my CRUD operations for my "user" table. Below is the class: <?php class UserDb { const TABLE = "users"; const KEY_ID = "Id"; const KEY_EMAIL = "email"; const KEY_JOIN_DATE = "joinDate"; const KEY_VERIFIED = "verified"; const KEY_LAST_LOGIN = "lastLogin"; const KEY_FIRST_NAME = "firstName"; const KEY_LAST_NAME = "lastName"; const KEY_PASSPHRASE = "passphrase"; private $db = null; public function __construct() { $this->db = new PDO( 'mysql:host=' . HOST_NAME . ';dbname=' . DATABASE_NAME . ';charset=utf8', DATABASE_USER, DATABASE_PASS ); $this->db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } public function userExists($email) { $sql = $this->db->prepare("SELECT * FROM " . self::TABLE . " WHERE " . self::KEY_EMAIL . " = :email"); $sql->execute(array(':email' => $email)); $row_count = $sql->rowCount(); if ($row_count > 0) { return true; } else { return false; } } public function insertUser($user = null) { if (is_null($user)) { $user = new User(); } } } ?> When I run this, I get: Can anyone tell me what I've done wrong? I've never worked with classes in php before.Thank you in advance!
  3. I'm trying to add an RSS feed engine to my site. I have the meat and potatoes portion completed, now I need the engine that syndicates them. Here's the example from the W3Schools site: <?xml version="1.0" encoding="ISO-8859-1" ?><rss version="2.0"><channel> <title>W3Schools Home Page</title> <link>http://www.w3schools.com</link> <description>Free web building tutorials</description> <item> <title>RSS Tutorial</title> <link>http://www.w3schools.com/rss</link> <description>New RSS tutorial on W3Schools</description> </item> <item> <title>XML Tutorial</title> <link>http://www.w3schools.com/xml</link> <description>New XML tutorial on W3Schools</description> </item></channel></rss> My question is this: As you add new items to your RSS XML, do the new ones go at the beginning, or the end of it? Does it not matter? How many items should you have in your XML before you start removing them from the XML? Do you need to remove them from the XML, or should this thing just be allowed to grow as big as Jupiter? Should the XML show the MOST recent item only?I've been searching online for a good part of the afternoon and can't seem to find the answer, perhaps a bad choice of keywords . I appreciate any feedback, and yes, I'm aware this is not a PHP specific question, but the engine will be written in PHP and there isn't a forum here for RSS Edit:Ok, found this on a website: I suppose this pretty much answers my questions, but I still wonder if there is an unspoken rule of no more than 15 items. I wouldn't want specific aggregators blocking my syndicate because I have more than 15 items. Also, do the new items go at the top or bottom of the XML? What do you think?Once again, to answer yet another of my own questions, the newer items go at the beginning of the example, here's a sample!<?xml version="1.0"?><rss version="2.0"> <channel> <title>Liftoff News</title> <link>http://liftoff.msfc.nasa.gov/</link> <description>Liftoff to Space Exploration.</description> <language>en-us</language> <pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate> <lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate> <docs>http://blogs.law.harvard.edu/tech/rss</docs> <generator>Weblog Editor 2.0</generator> <managingEditor>editor@example.com</managingEditor> <webMaster>webmaster@example.com</webMaster> <item> <title>Star City</title> <link>http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp</link> <description>How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia's <a href="http://howe.iki.rssi.ru/GCTC/gctc_e.htm">Star City</a>.</description> <pubDate>Tue, 03 Jun 2003 09:39:21 GMT</pubDate> <guid>http://liftoff.msfc.nasa.gov/2003/06/03.html#item573</guid> </item> <item> <description>Sky watchers in Europe, Asia, and parts of Alaska and Canada will experience a <a href="http://science.nasa.gov/headlines/y2003/40may_solareclipse.htm">partial eclipse of the Sun</a> on Saturday, May 31st.</description> <pubDate>Fri, 30 May 2003 11:06:42 GMT</pubDate> <guid>http://liftoff.msfc.nasa.gov/2003/05/30.html#item572</guid> </item> <item> <title>The Engine That Does More</title> <link>http://liftoff.msfc.nasa.gov/news/2003/news-VASIMR.asp</link> <description>Before man travels to Mars, NASA hopes to design new engines that will let us fly through the Solar System more quickly. The proposed VASIMR engine would do that.</description> <pubDate>Tue, 27 May 2003 08:37:32 GMT</pubDate> <guid>http://liftoff.msfc.nasa.gov/2003/05/27.html#item571</guid> </item> <item> <title>Astronauts' Dirty Laundry</title> <link>http://liftoff.msfc.nasa.gov/news/2003/news-laundry.asp</link> <description>Compared to earlier spacecraft, the International Space Station has many luxuries, but laundry facilities are not one of them. Instead, astronauts have other options.</description> <pubDate>Tue, 20 May 2003 08:56:02 GMT</pubDate> <guid>http://liftoff.msfc.nasa.gov/2003/05/20.html#item570</guid> </item> </channel></rss> So one more question to go!
  4. Any ideas on how to back up a db on a hosted platform? It has phpadmin for the user interface, but I'm at a loss for the best method of backing this up, short of exporting each table manually...
  5. In theory you are correct, but there, unfortunately, are scenarios where developers don't follow the typical rules. Here's a standard favicon declaration: <link rel="shortcut icon" href="favicon.ico" /> Sometimes, I've seen people do this: <link rel="shortcut icon" href="/images/favicon.ico" /> Or even this: <link rel="shortcut icon" href="myicon.ico" /> So, best practice would probably, I'm assuming, be to do a preg_match for the "myicon.ico". My problem is just that I seem to be struggling with reg exps.Tips?
  6. Thanks guys, Teng84 hit it on the nail, never ran across those functions before, very handy!I run a very large mobile internet directory, and some of the links are in the formats listed above. That's why I needed to be able to break each link down, so I can display their pretty icons. I have it working now, but I'm not entirely happy with my quick fix. I need to write a preg_match statement. Anyone decent at writing reg exp's? I tried and butchered it.
  7. supertrucker

    Url Function

    Perhaps I'm over thinking this, but here is the scenario:Link 1: http://www.example.comLink 2: http://www.example.com/Link 3: http://www.example.com/index.phpLink 4: http://www.example.com/index.php?var=123Link 5: http://www.example.com?var=123All of these links are pointing to the exact same location, but they are all different. I need a method to break down any version to just the http://www.example.com so I can append the address to http://www.example.com/favicon.ico.Things get even more confusing with addresses like:1: http://www.example.com.au/2: http://www.example.com.au/dir/index.php?var=123...where all I need is the http://www.example.com.au part.Any tips on how to achieve this? I'm clunking my head against a wall right now in frustration :)Thanks!
  8. I guess I need to do a little reading up on Javascript. When it comes to mobile applications, using Javascript isn't practical since not all mobile browsers support it. However, that's beginning to change as the newer phones sport more advanced browsers. Even most of the dumb phones I've had included a simple subset of Javascript, but I've never read anywhere when it's okay to use it for mobiles, just always do what you can for the user server side.For personal use, however, I will have to play around with it and see what cool stuff I can do client side.Thanks for the support!
  9. The solution is solved, but if you're curious, the intent was the following:1. A bookmarklet uses Javscript to forward the current page address to extract.php.2. Extract.php uses cUrl to extract the pages meta data.3. Extract.php forwards this new information to a link submission form, submitlink.php.4. Submitlink.php receives the data and prefills out a form with the data collected. User reviews data and submits the data.Works great now that I'm using $_sessions like I should have from the get go! Of course, now that I think about it, couldn't javascript have been used to extract all the metadata in the first place?What's a bookmarklet? Little piece of javascript that you save as a bookmark. Works wonderfully for forwarding web pages, saving bookmarks for social bookmarking sites, etc.
  10. The solution is solved, but if you're curious, the intent was the following:1. A bookmarklet uses Javscript to forward the current page address to extract.php.2. Extract.php uses cUrl to extract the pages meta data.3. Extract.php forwards this new information to a link submission form, submitlink.php.4. Submitlink.php receives the data and prefills out a form with the data collected. User reviews data and submits the data.Works great now that I'm using $_sessions like I should have from the get go! Of course, now that I think about it, couldn't javascript have been used to extract all the metadata in the first place?What's a bookmarklet? Little piece of javascript that you save as a bookmark. Works wonderfully for forwarding web pages, saving bookmarks for social bookmarking sites, etc.
  11. Thanks for the reply, I was thinking about this one way too hard! Used Sessions, problem solved, hate it when that happens!
  12. That's just it, how do you preserve post data with a redirect?
  13. Is there a way to send POST data with the header function? I.e., right now, I'm doing this:header("Location: http://blah.com?reallylongdatahere");...which is breaking, I'm assuming because the GET method I'm using has a 100 character limit. Any ideas?
  14. Thank you, that second link has a very well put together explanation!
  15. I'm having trouble understanding how the preg_match function works, furthermore, the code examples I read further confuse me! I use this code below as part of a "bookmarklet" for my site, but the code was essentially copy and pasted (it's utilizing cUrl functions). I basically understand what the preg_match function does, it parses text. What I don't understand is how get it to do what you want. The code below works for getting the "<title>" tag from a remote web page. Could somebody please explain the different parts of the preg_match function below? For instance, what are all the slashes "\/" for? What's with the (.+)? Why does the closing title tag have two slashes? What does the "/siU" mean? include("get_web_page.php"); $url=$_REQUEST['URL']; $header=get_web_page($url); $content=$header['content']; $url=$header['url']; $cerror=$header['errno']; /* get page's title */ preg_match("/<title>(.+)<\/title>/siU", $content, $matches); $title = $matches[1]; Thanks for any help!
  16. Just a follow up, that this code worked perfect, makes my life a lot easier now that I can easily search for "orphaned" records in my db!Thanks again!ST
  17. If anything I learned two new ways of doing something. That first example looks perfect, JSG, thanks! As far as that second one could you elaborate on the e.*? Is that a form of wildcard? I've used, '%test%' before, but that form looks new to me, I'll have to look that one up.Thanks for all your help!
  18. Here's my sql statement in english: Is there a valid way of writing a single statement like this, without doing multiple statements from my php code?Thanks in advance!ST
  19. It's most definitely there. I use that table pretty heavily throughout my scripts, the two fields in it are "DirId", which is the index, and "Title", which is just a descriptive name. In anycase, I think it may have something to do with the fact that this is a multi-dimensional array, and that I'm just referencing it incorrectly. I found an example online somewhere that shows an example of sorting/referencing a multidimensional array, but I couldn't get it to apply to my situation.
  20. Here's what I want to do. Retrieve a bunch of rows from a table in a database and store them in an array. Take one part of those rows, say field 'Title' and prepend the title with a particular string. Sort the array alphabetically using the 'Title' field. However, part of my logic isn't right, and I'm getting unexpected results, just at step one.Here's my code so far function ShowDirectoryList($sel){ include("global_vars.php"); $sql="SELECT * FROM wapdirectory ORDER BY ParentId"; $line=0; echo "<br/>Current category: $sel<br/>"; $con = mysql_connect($dbhost,$dbu,$dbp); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($dbname, $con); $result = mysql_query($sql); echo '<select name="ParentId">'; echo '<option value="">No Category</option> '; while($row = mysql_fetch_array($result)) { $psql="SELECT Title FROM wapdirectory WHERE DirId='$row[ParentId]' ORDER BY ParentId, Title"; $parent=ExecuteSQL($psql, TRUE); $parent=$parent['0']; if ($sel != $row['DirId']) $selected=""; else $selected='selected="selected" '; echo '<option value="'.$row['DirId'].'" '.$selected.'>'.$parent."/".$row['Title'].'</option>'; // TEST if (isset($sort)) { $sort = array_merge($sort, $row); } else { $sort = $row; } // TEST } echo "</select>"; foreach($sort as $row[]) { echo $row['DirId']; }} The part that I am confused about is... foreach($sort as $row[]) { echo $row['DirId']; } ...which generates this error: I expect it to just spit out every 'DirId' in the $sort array. Am I confusing my logic somehow? I appreciate any help!
  21. Ok, this makes no sense. With the exception of one or two lines that were "//" out, I decided to retype the entire example by hand instead of copying and pasting. The script ran flawless! Is it possible, and I ask because it made a difference, that the "$" in his example, and the "$" in my example were different? I started changing punctuation such as the dollar signs one at a time (by retyping them) and the errors finally changed, moving on to the next one. All punctuation, that I replaced with the identical symbol.I don't get this one, I mean I do, because it's fixed, but I still don't understand why!
  22. I found this example on another website (here). I added only a couple things to it, to make it work the way I wanted to, but it doesn't get past "Line 4". The error I receive is: I double checked my php.ini file, and "allow_url_fopen = On". I'm sure that I'm doing something really silly here, but my brain is tired. Any ideas?<?php//$url = $_REQUEST['URL'];$url="http://example.com";$fp = fopen($url, "r");$content = "";while( !feof( $fp ) ) {$buffer = trim( fgets( $fp, 4096 ) ); $content .= $buffer;}$start = '<title>'; $end = '<\/title>';preg_match( "/$start(.*)$end/s", $content, $match ); $title = $match[ 1 ];$metatagarray = get_meta_tags( $url ); $keywords = $metatagarray[ "keywords" ]; $description = $metatagarray[ "description" ]; $nURL="http://zerorubbish.com/submitlink.php?EditMode=0&LinkAddress=$url&LinkName=$title&LinkDescription=$description"; header("Location: $nURL");?><html><head><title>Extract.php</title></head><body>Test.</body></html>
  23. I am on a shared host, StartLogic to be precise. I ran another example I found on http://php.net for fsockopen and it ran flawlessly: <?php$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);if (!$fp) {echo "$errstr ($errno)<br />\n";} else {$out = "GET / HTTP/1.1\r\n";$out .= "Host: www.example.com\r\n";$out .= "Connection: Close\r\n\r\n";fwrite($fp, $out);while (!feof($fp)) {echo fgets($fp, 128);}fclose($fp);}?> So that works. I tried the examples that came with the Pear library for the "SmartIRC", and the standard PHP examples I found, and I keep running into the same error, "Permission Denied". Apparently there is no real documented error codes for SmartIRC so it doesn't really help much [Error code (851)]. Is it possible that the shared server I'm on is denying server requests to go through a specific port?? I.e., 6667 which is the most common port used with IRC. This wouldn't make much sense, though, when they preinstalled the SmartIRC Pear libraries on their servers for us!I'm confused. All I wanted was a simple IRC bot to keep a channel open!
  24. Here's the script in its' entirety: <?php//So the bot doesnt stop.set_time_limit( 0 );ini_set( 'display_errors', 'on' );class IRCBot{ var $socket; function __construct( $config ) //Connects to the server defined later. { $this->socket = fsockopen( $config['server'], $config['port'] ); $this->login( $config ); $this->main(); } function login( $config ) //Sets the bot's Nick and password, as defined later. { $this->send_data( 'USER', $config['nick'].' iscripting.net '.$config['nick'].' :'.$config['name'] ); $this->send_data( 'NICK', $config['nick'] ); } function main() //Gets data from server to display in browser. { $data = fgets( $this->socket, 128 ); echo nl2br( $data ); flush(); $ex = explode(' ', $data); if( $ex[0] == 'PING' ) $this->send_data( 'PONG', $ex[1] ); //Plays ping-pong with the server to stay connected. $command = str_replace( array( chr(10), chr(13) ), '', $ex[3] ); switch( $command ) //List of commands the bot responds to from a user. { case ':!join': $this->join_channel( $ex[4] ); break; case ':!quit': $this->send_data( 'QUIT', 'Fail.' ); break; } $this->main(); } function send_data( $cmd, $msg = null ) //displays stuff to the broswer and sends data to the server. { if( $msg == null ) { fputs( $this->socket, $cmd."\r\n" ); echo '<strong>'.$cmd.'</strong><br />'; } else { fputs( $this->socket, $cmd.' '.$msg."\r\n"); echo '<strong>'.$cmd.' '.$msg.'</strong><br />'; } } function join_channel( $channel ) //Joins a channel, used in the join function. { if( is_array( $channel ) ) foreach( $channel as $chan ) $this->send_data( 'JOIN', $chan ); else $this->send_data( 'JOIN', $channel ); } } //Example connection stuff. // IP is actually irc.villageirc.net, I tried the ip when the nice url didn't work $config = array( 'server' => '66.79.171.227', 'port' => 6667, 'nick' => 'IsABot', 'name' => 'BotName', 'pass' => 'meh', ); $bot = new IRCBot( $config ); ?>
  25. I would just break down and sign up with a host. Most of them are really inexpensive, I've been using StartLogic and have been fairly content. Lots of tools, features, not a lot of restrictions, and nice vdeck administrative interface.
×
×
  • Create New...