Jump to content

gizmola

Administrators
  • Posts

    5,945
  • Joined

  • Last visited

  • Days Won

    145

Everything posted by gizmola

  1. I started blogging back before anyone called it a blog. At the time, people called them "personal home pages." For me there were a few different purposes: - A way for me to collect notes on things for my own reference - To publish things for family and friends that I otherwise might have put in a letter Eventually this evolved into my writing the occasional entry about topics that interested me enough to do research. Some of these posts were howto's, some just contained material for talks I've given, and some stood alone as magazine style articles. I think at this juncture, there's an entire sub-culture and set of rules that have built up around "blogging" but the basic idea continues to be, chronologically presented article format postings. That the web allows for categorization and indexing of this material, certainly explains why they have gotten so much traction.
  2. All sessions do is give you a serverside persistence mechanism for data associated with a browser instance. It's up to you whether or not you actually want to set session variables and give them data. A session can be expired but that is based on when it is first created. If I understand you, what you want to make sure is that if someone hasn't done anything in over an hour, you want them to have to relog in? If that's the case, then go with a session variable called something like 'last_activity'. What you would then want to do is something like this: $currtime = time(); // get UNIX timestamp if (($_SESSION['last_activity'] + 3600) > time()) { // Hour since last activity, log em out // Do unsetting of $_SESSION['login'], session_destroy(), session cookie backdating etc. } else { $_SESSION['last_activity'] = time(); } This decouples the last_activity from your login time, and still gives you your inactivity timeout function. Since it's all serverside, it should be impervious to issues with local user time. This is all off the top of my head, so code may have syntax issues or logic errors
  3. Well, you asked why you didn't see any methods for document and couldn't understand how its instance variables were being set. An IDE that can search through code is helpful in these types of examples. Now for the new code there's no quesiton of scope. There is an instance of Registry, only it is a static class. In this case, Registry has a set of static methods and a static variable in it. They do this to implement the "singleton" design pattern, because the implication is that the application should have one and only one registry. This is often referred to as the "Registry" pattern. final class Registry { static private $data = array(); static public function get($key) { return (isset(self::$data[$key]) ? self::$data[$key] : NULL); } static public function set($key, $value) { self::$data[$key] = $value; } static public function has($key) { return isset(self::$data[$key]); } } ?> Notice that the class defines: static private $data = array(); Inside a class, this defines the $data variable as being a "class" variable. In other words, no matter how many objects of class registry one might create, they will allow share the $data variable. Now to the question of how a language can allow for static method calls. Basically what happens is that when you make static method calls like: Registry::set('config', $config); The environment needs to in essence, manufacture an internal object, so that the static method can be executed. You could think of that as: php makes this object, runs the method and discards it immediately. In this case, however, because Registry::set adds elements to the static class variable $data, its contents can be accessed via the static get method at a later time. So what you see happening is that they are creating instances of various objects that will be needed, and sticking them into the Registry, so that the application can make use of them at a later time without having to worry about how to get access to the object without having to pass it via parameter, or having a huge number of global variables floating around.
  4. You should read up on how to do joins. Probably everything you want to do can be done in one query.
  5. I agree that you have the extra tag, but that doesn't effect the PHP -- only your html output. Still it should be cleaned up.
  6. There's a number of obvious issues with the code you've presented. The way we work here, is that we require the people asking questions to help narrow things down to the pertinent area. In reading your original post, you have this line: </pre> <li>"; ?>Photos</li If as you say, you want to pass that along to the Photos URL using a GET parameter, then you'd need to have that parameter as part of the URL. Perhaps that's part of the problem? Later you have this code: $index = array( "main" => "DisplayAlbums.php?title=$getValue" , "photo" => "DatabaseConnectionBackup.php" ); You then use this array to do an include. The include needs a local file, which "DisplayAlbums.php?title=$getValue" is not. So if the code executes for page=main, then this is not going to work. If your code is in the file DisplayAlbums.php, then the $getValue variable will be available to it, because an include simply inserts the code of the included file into the current script at the point it is called. All script variables will be seen by that script, so it's free to reference $getValue in queries. We don't have the code to analyze of course.
  7. gizmola

    Empty pages

    There could be any one of a hundred problems. Are there any errors in the error log when this occurs? Do you have access to the server via ssh so that you can see what's happening in the OS?
  8. Ok, so the session files (assuming the default session handler) are stored on the file server. These session files can have a lifetime set up for them, based on the session configuration variable session.gc_maxlifetime. Using cookies, the connection between the session id and the session file is made, and this can be somewhat constrained using a cookie_lifetime, but this should not be set to a short amount of time (as in your example) because the time corresponds to the server time, and you can not control or ascertain what the client's local time is. In a note on the gc_maxlifetime, there are two variables that controll when the garbage collection is run. These are described on the manual page. Keep in mind, that in a situation where you have low traffic (development mode) it is possible that you will not generate enough requests to hit the threshold which would trigger the garbage collection, so it's entirely possible that you will have session files that hang around long after they should have expired. Enough background -- now to your problem. The first issue I see is that it seems you only want people to be logged in for an hour. Is that really what you want? This would mean that a person using your site continuously is going to be logged out after an hour, assuming you implement this control Your best bet is to control this within the session. If you determine using your login time, that the hour has expired, by checking it against the current server time, then you could do something like this (see the session_destroy php.net page for more info). $_SESSION = array(); // If it's desired to kill the session, also delete the session cookie. // Note: This will destroy the session, and not just the session data! if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); } // Finally, destroy the session. session_destroy();
  9. It seems you have things pretty well down now. You are correct that document is pretty much just a storage class, used to keep track of information later used by the MVC views. It has no moving parts, so you know that other code must be writing to it. You can think of the class variables in document as a sort of temporary scratch pad, that will be set in other places. For example if you look in the /controller/account/login.php as an example you'll find this: $this->document->title = $this->language->get('heading_title'); As you surmised the document class also aids in providing language support.
  10. Are you sure you're getting a result? A result set can return anywhere from 0 to many rows. I think your assumption is that there will only be one row, but it could be possible that you're getting more than one. If you only ever want one row, then you might consider a different fetch function. At any rate, how about modifying to something like this to start. One minor nitpick, but you should try and strive for always having being/end tags, so I stuck in your closing p tag. while($row1 = mysql_fetch_array($result1)) { echo " "; }
  11. Ok, I'll play. Let's try this: $sql = "INSERT into iqsmart VALUES (NULL, {$_POST['name']}, '$points')";
  12. First congrats on getting your first game demo out. I'm not sure what you mean by that. Of course, Flash runs on the client, and there's no way to control the client environment. If it's a network game, you can take steps to encrypt/decrypt the client protocol, but at the end of the day, you can't really prevent people from doing what they want to something running on their own computer.
  13. Ok, so, just to nitpick, php doesn't have pointers. It has various variable types, and the one you are talking about is called a "resource". When I'm not getting is why you want to use a class, if all you're not going to encapsulate the native methods, and all you want to do is store the handle and then get it back out of the object again. The technical answer to why your example writetext didn't work is probably that, as I stated, you were passing the resource variable by value. In the process a copy is made and this is probably squashing the resource. Try modifying that function call so that the parameter passes by reference, although again, an instance variable internal to the class doesn't need to be passed at all -- it's already available from $this->. If you want to write a getPS method, then return &this->ps; HTH
  14. Some people that I know who are interested in this area, have said good things about Moodle.
  15. vivekme -- all of those systems have plenty of sample code to investigate. There are loads of templates you can install and then examine the source for, and there are components/modules etc, you can install and then read the source code for. That's the beauty of PHP. There is no substitute for installing these yourself and working with them. Rather than asking people to send you code (which will never happen) I'd suggest that you install them, and then attempt to build a site yourself. In the process you'll learn how to use them, and when you have questions, you can ask here or in the respective support communities.
  16. Xylex reminded me of one other item -- turn on the mysql slow query log, and look at that for queries that are hammering the db's. This could indicate that you have queries that need rewriting or indexes that are needed. You can also do explain's on those queries to see what's going on with them. I agree with his query cache tuning, although that assumes your using the myisam engine. There are similar adjustments you can make if you're using innodb, but you have to read the innodb docs for those. There's an excellent performance tuning tool called innotop you should check out, if you're using innodb. For caching, I think you jumped over that suggestion far too quickly. There's a huge difference between smarty (which I'm completely cool with) and using memcache. Memcache is distributed in memory caching for your data, not for rendered pages. If you want to know what is being used by myspace, facebook, livejournal and countless others, to allow them to scale, it's memcache. It's very simple to implement and can drastically lower the drain caused by your db's, especially when it's a read heavy environment like the one I'm assuming you have. As for the curl bots, I'd suggest you start by dropping them to a page with some contact info, and if you want to deal with individual exceptions you can always code that in via custom user agent string you agree upon or IP range.
  17. Ok, so my recommendation would be at very least to do a junction box type architecture. You can do this pretty easily without a lot of rewrite, by putting at the heart of your index.php a large switch statement. Your urls then become index.php?page=contact etc. You can then use a simple mod_rewrite config to have pretty url's like: http://www.draconicmedia.com/page/portfolio This hides the fact that you're using PHP, but also has the benefit of providing maintainability. You only need to have the header() & footer() in the index.php controller script, and you do includes of the appropriate script based on the page parameter. You also get those search engine friendly url's. Right off the top, there's no reason for your home to link to index.php. It should just be http://draconicmedia.com/, or relatively, just "/" as your target. Last but not least I 100% agree with DarkSuper -- you should have no advertising, other than for your own services.
  18. Actionscript files are simple text now, so yes, you can write them with any editor. Flex is actually more than just Actionscript -- it includes the mxml markup language, and was designed for people to build applications. So a lot of flex builder is designed to support the mxml, in a, as you said, dreamweaver like fashion. You certainly don't flex builder to write actionscript code, although people that are doing a lot of it have told me they like it. You can also run the flex builder as a plugin to eclipse which is the IDE I personally use these days, although there is also a free actionscript plugin named ASDT that gives you some solid support for actionscript syntax. For external assets, you can bring them into the .swf using the [Embed(source="...")] or there's a loader class that lets you load external assets at run time. So you don't strictly speaking absolutely have to package all your assets using flash. Chances are you will still want to get a copy of flash, but strictly speaking, yes you can develope full flash swfs without it. This assumes that a lot of your games are going to involve programmatic manipulation of sprites. For books: O'Reilly's essential Actionscript 3.0, and there's a book on games specific development called Actionscript Game programming university that's a pretty quick read and has some great example apps.
  19. I haven't looked at the code in question, but zend_config from the zend framework provides an example of how this can be done easily. With Zend_config you can create configuration files defining simple arrays, and the zend_config takes the arrays as input, and then allows you to access elements using the nested object element syntax. If this is similar to what OpenCart is doing, this code should help explain how it can be done using the built in __get() method. If you have read about php 5 special methods, __get, if it exists for a class will be called if the accessor being specified does not exist in the class definition. This allows you to call some code, and resolve the accessor dynamically. /** * Zend_Config provides a property based interface to * an array. The data are read-only unless $allowModifications * is set to true on construction. * * Zend_Config also implements Countable and Iterator to * facilitate easy access to the data. * * @param array $array * @param boolean $allowModifications * @return void */ public function __construct(array $array, $allowModifications = false) { $this->_allowModifications = (boolean) $allowModifications; $this->_loadedSection = null; $this->_index = 0; $this->_data = array(); foreach ($array as $key => $value) { if (is_array($value)) { $this->_data[$key] = new self($value, $this->_allowModifications); } else { $this->_data[$key] = $value; } } $this->_count = count($this->_data); } /** * Retrieve a value and return $default if there is no element set. * * @param string $name * @param mixed $default * @return mixed */ public function get($name, $default = null) { $result = $default; if (array_key_exists($name, $this->_data)) { $result = $this->_data[$name]; } return $result; } /** * Magic function so that $obj->value will work. * * @param string $name * @return mixed */ public function __get($name) { return $this->get($name); } Hopefully you can understand what this code does. If you have further questions about it, ask.
  20. fry2010, You actually don't strictly *need* to buy flash, although for making a lot of the assets I'm sure you'll eventually want to have in, however, you can now use the flex sdk to compile actionscript. As for games, I worked on this site, where the games parts are flash: http://pickteams.com/#home There are sites like these: http://www.omgpop.com/ or http://www.kongregate.com/games/preecep/desktop-tower-defense-1-5 or the grand daddy of this idea: http://www.newgrounds.com/portal/view/59593
  21. You know that they are bots because of user-agent? If so, simply refuse them based on that. Smarter bot writers can trick you, but it will cut out the dumb ones. As for performance here's a couple of tricks of the big boys. - Serve your static images etc, using a light weight web server like lighthttpd - make sure you've minified your javascript - To lessen load on your db's implement memcache to cache your results. - Go through your Apache server config and make sure you are using the fewest apache modules possible. - Use a php opcode cache like APC.
  22. Well, there's 2 answers. First off, using a streaming server, you inherently get the seek ahead capability. Of course the streaming server is expensive, and introduces the reliability and quality problems inherent to streaming. Then there is either buying or hacking your own seekable progressive download server. Although this thread is rather old, it does provide source to a player/server solution that provides jumping ahead. http://www.flashcomguru.com/index.cfm/2005/11/2/Streaming-flv-video-via-PHP-take-two
  23. For the type of games you describe, and the web environment, I agree entirely with paulman --- Flash/Actionscript is the way to go.
  24. Yeah, the reason that your session code doesn't work is that a session is relative to a single browser instance. There's a number of different approaches to this, each having its own issues. One method would be to use a custom session handler that stores the session information in a database. You would need to add an extra column to store the username in the session table and add some extra code. There are examples around you can find of how to accomplish this, some of which are linked off the php.net manual page for session handlers. I would not add an online flag, because usually people don't "logout" of a server, they simply navigate away or close their browser. Even sessions have this issue, although there's a built-in mechanism that cleans up expired sessions. If you do want to utilize a database flag, then I'd suggest you make it a DATETIME column named "lastlogin" or something similar. What you then code, is something that shows you all the people who have a lastlogin DATE within a certain number of minutes This works well, and is simple, however, the problem you have is that you need the date to be updated when users navigate to other pages, so you need some code to handle that. All those updates can put quite a lot of strain on the database, and can cause locking issues. An improvement over the general idea, is to have a table that does nothing but store "page views" with the time -- so for example, you might have only the username and a timestamp. When a user who is logged in, visits a page, you create a routine that inserts a row into this table. Again, you can query it within a time range (last 15 minutes for example) and doing a GROUP BY on the username, you have your list of logged in users, without the concern that you'll be creating too many update locks on your user table. This method works very well and doesn't degrade in performance even if you don't delete old rows from it, so long as you have the right indexes on the datetime and username columns. I'd recommend this solution over the others.
×
×
  • 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.