Jump to content
MakeWebGames

Floydian

Members
  • Posts

    900
  • Joined

  • Last visited

    Never

Everything posted by Floydian

  1. Re: How to use sprintf? http://criminalexistence.com/ceforums/i ... ic=16644.0 Read that forum post. It explains *why* to use sprintf. To summarize: it formats a string..., but do read the post...
  2. Floydian

    coding help

    Re: coding help lol for real, google that shiznit or search the forum. there's been at least a dozen other posts asking the SAME EXACT THING Hope that helps...
  3. Re: How to use sprintf? The definitive answer to that is _no_ There is _no_ one function, one if block, one code sample, or one *anything else* that can simply be applied _willy_nilly_ and expected to be secure programming technique. Do I use sprintf in code that is secure? You bet. Can code with sprintf be insecure? You bet. Is sprintf helpful for securing code? Double edge sword there... I could be helpful in making it less secure. Why is sprintf helpful in making code more secure? Because it formats strings. Hope that helps...
  4. Re: Jail_Reason * PHP-Games > * Webdev and programming (Non Game related) > * PHP/MySQL > * PHP Databases > * Post reply ( Re: Jail_Reason )   Just in case ya didn't notice what forum this was ;)
  5. Re: Need help with simple sql please LOL this is why I stay out of the MCCODES section. Can't ya'll keep your crap over there?
  6. Re: Need help with simple sql please A complete lack of detail will almost certainly be met with a complete lack of a solution for you. You haven't provided any SQL details, like what tables you're talking about, or what the queries are that are the problem. We have no idea what your "index" or your "profile" deal is. Please note the (None Game related) title of the parent forum, and thus I assume this has nothing to do with MCCODES. Although the content of your post belies my assumption...
  7. Re: Eregi - Ereg The PHP manual does not list it as deprecated. That's normally the first step before something is removed. ereg isn't bad, but it can be tricky to use. Perhaps that's what they meant was bad about it.
  8. Floydian

    while loop

    Re: while loop You're welcome Crazy-T and mikemastah   Do keep in mind that if you ever do something like $blah = $_GET['id']; $foo = $_GET['amount']; $$blah = $foo; That you have a SERIOUS SECURITY risk. Use variable variables with caution :)
  9. Floydian

    while loop

    Re: while loop Variable variables....   $$shopitems['name'] // assuming $shopitems['name'] holds the value of grenades is equivalent to: $grenades http://us2.php.net/manual/en/language.v ... riable.php
  10. Floydian

    while loop

    Re: while loop You've got the right idea, but you also have syntax errors: $new = (${$shopitems['name']} + $_POST[$shopitems['id']]); You've got a $ and a { and } just sitting in there, as if you are in a string context and you are not in a string context there.
  11. Floydian

    while loop

    Re: while loop It does appear that you would be able to loop through all the rows in the table that way. I'm not sure why you take an 'id' and multiply by 'costs'. I could see a 'qty' * 'costs'. But perhaps your naming conventions are just diff than mine. So, I dun really get what exactly this code accomplishes, but it will iterate over all rows in that table. ;)
  12. Re: (no clear way to describe) please read Cool, glad that worked ;)
  13. Re: (no clear way to describe) please read Can you put up a link to the page?
  14. Re: (no clear way to describe) please read By the way, you would have to remove style="display: none;" from the lefttext div or else applying the class will do nothing...
  15. Re: (no clear way to describe) please read Place in css file: .lefthead.totoggle + div.lefttext { display: none; }   JS Script <script type="text/javascript"> function hideText(aNode) { if (aNode.className === 'lefthead') { aNode.className = 'lefthead totoggle'; } else { aNode.className = 'lefthead'; } return false; } </script>   Hope that helps :P
  16. Re: (no clear way to describe) please read Alrighty, then that means you need to remove that id="totoggle" since you're using it more than once. Only the first instance of totoggle could ever be used, so it's pointless to have that in there. The easiest way to do what you want is to add and remove classes. If you setup the lefthead class like this: .lefthead.totoggle + div.lefttext { display: none; } Then when the lefthead is clicked on, simply add the totoggle class to itself. The + modifier that works in IE 7 (among others) will target the adjacent sibling. so in your function, pass the "this" into it and do something like this.style.className = 'lefthead totoggle'; or this.style.className = 'lefthead'; And that will toggle the display on that lefttext Hope that helps...
  17. Re: (no clear way to describe) please read I'm highlighting the changes I'm making: The text in red is not going to be used at all. The text that is struckthrough is taken out completely. The text in green is modified slightly. <script type="text/javascript"> <!-- function hideText(aNode) { var totoggle=aNode.nextSibling; var style = document.getElementById(totoggle).style; style.display = (style.display == 'none') ? "block" : "none"; return false; } //--> </script> Here is the modified script. <script type="text/javascript"> <!-- function hideText(aNode) { var style = document.getElementById('totoggle').style; style.display = (style.display == 'none') ? "block" : "none"; return false; } //--> </script>   Hope that helps...
  18. Re: css columns Try adding a div with clear: both after a and b, but in c.   <div id="c"> <div id="a"> </div> <div id="b"> </div> <div id="blocker" style="clear: both; width: 100%"> </div> </div>   That will cause the "blocker" div to expand c ;) Hope that helps...
  19. Yeah, I know, there are many scripts available for logging and script execution timing. I'm posting this script in the hopes that some folks find it useful. The purpose of this script is: the script provides a simple logging interface that logs messages and sorts them into seperate categories. All log messages can be retrieved as an array which can then be easily displayed. This script will be packaged with the next version of the Horizons Game Engine. [Click here for info on the Horizons Game Engine. I personally didn't include anything to format log output because the Horizons Game Engine already has a function that takes an array and pretty prints it for you. Therefore, Horizons Game Owners should use the decho() function to format log data output. As a convenience, this class also provides a simple timing facility that acts like a stopwatch. Each time you set the stopwatch the script will set a data point for that. When you finish timing the script, you can output script execution data in tabular format with the provided interface. It will give you the total execution time, the time interval between each data point, and a running tally of total time at each data point. If you have any problems using the script, please post your questions here. This script does require php >= 5.0.0. If someone wants to make it php < 5 compatible, that's great. And if anyone wants to add or alter the script, that's great as well. All I ask is that you keep the main doc block and list any changes you make.   <?php /** * @author Floydian * @link [url="http://www.phphorizons.com"]http://www.phphorizons.com[/url] * @version 1.0.0 * @license Free to use, modify, and distribute so long as this doc block is maintained and present * in any copies of this software and any modification, if made, must be noted. * This software is provided as is and with no guarantees of anything * at all. Use at your own risk ;) * * @desc * A class for logging messages or any kind of data. * Messages can be arrays, but will probably be strings * most of the time. * * The ErrorCount property will count how * many individual logs have been recorded * across all instances of the Logger class. * * The BC_SCALE property allows the bc math function * scale to be set across all instances of this class. * Setting this also sets the scale used by the round() * function within this class. */ class Logger { static $ErrorCount = 0, $BC_SCALE = 4; protected $logs = array(), $chrono = array(); /** * Records messages into a set of arrays * determined by the $types passed in. * Each new $type sets a new array of logs. * Therefore it's possible to log multiple * types of things with one instance of the log * class. * * @param string $type * @param mixed $message */ function log($type, $message) { if (is_null($type) or strlen($type) < 1) { $type = 'General'; } if (!isset($this->logs[$type])) { $this->logs[$type] = array(); } $count = array_push($this->logs[$type], $message); $this->chrono[] = array('type' => $type, 'key' => $count - 1); self::$ErrorCount++; } /** * Gets the last log entry. * It returns an array in the form of ('type' => $type, 'message' => $message) * * @return array */ function getLastLog() { $count = count($this->chrono); if ($count < 1) { return array(); } else { $type = $this->chrono[$count]['type']; return array('type' => $type, 'message' => end($this->logs[$type])); } } /** * Gets the last log entry of a particular type. * It returns an array in the form of ('type' => $type, 'message' => $message) * * @param string $type * @return array */ function getLastLogByType($type) { if (!isset($this->logs[$type])) { return array(); } else { return array('type' => $type, 'message' => end($this->logs[$type])); } } /** * Returns the raw array used to store log messages. * This method and Logger::getLogsByType() * are the only two methods that output log data in array form * that don't do so in the ('type' => $type, 'message' => $message) format. * The format is instead an array of types, each having an array of messages * numerically indexed. * * @return array */ function getAllLogs() { return $this->logs; } /** * Returns an array of logs in chronological order. Logs are * output as an array of ('type' => $type, 'message' => $message) arrays. * * @return array */ function getAllLogsChrono() { $log_list = array(); foreach ($this->chrono as $log_address) { $type = $log_address['type']; $log_list[] = array('type' => $type, 'message' => $this->logs[$type][$log_address['key']]); } return $log_list; } /** * Returns all logs that are of the type specified. * This method and Logger::getAllLogs() * are the only two methods that output log data in array form * that don't do so in the ('type' => $type, 'message' => $message) format. * The format is instead a numerically indexed array of messages. * * @param string $type * @return unknown */ function getLogsByType($type) { if (!isset($this->logs[$type])) { return array(); } else { return $this->logs[$type]; } } /** * List the number of logs recorded * in this instance of the Logger class. * * @return integer */ function getLogCount() { return count($this->chrono); } /** * Provides rudimentary script execution * timing facilities. Executing this * method more than once will set * multiple data points. * * @param string $message */ function setTimer($message = '') { $this->log('SCRIPT TIMER', array(microtime(true), $message)); } /** * Gather and format script execution * timing data. * * @return string */ function getTimerResults() { $timers = $this->getLogsByType('SCRIPT TIMER'); $timer_log = ''; $start_time = null; $last_time = null; $running_total = 0; $count = 0; bcscale(self::$BC_SCALE); foreach ($timers as $data) { if (is_array($data)) { $count++; $time = $data[0]; $message = $data[1]; if (is_null($start_time)) { $start_time = $time; $last_time = $time; } $diff = bcsub($time, $last_time); $running_total = bcadd($running_total, $diff); $timer_log .= <<<EOT <tr> <td style="text-align: right; padding-right: 10px"> $count </td> <td style="text-align: right; padding-right: 10px"> $diff </td> <td style="text-align: right; padding-right: 10px"> $running_total </td> <td style="text-align: left"> $message </td> </tr> EOT; $last_time = $time; } } if ($count > 0) { $total_time = round($last_time - $start_time, self::$BC_SCALE); return <<<EOT <table> <tr> <th> Count </th> <th> Increment </th> <th> Total </th> <th> Message </th> </tr> $timer_log <tr> <td colspan="3"> Total execution time: $total_time seconds </td> </tr> </table> EOT; } else { return "No timing data found..."; } } }
  20. Floydian

    Serializing data

    Re: Serializing data @ Vali, that's a very good point. And definitely worth mentioning. @ a_bertrand, I normally recommend using JSON when one needs to serialize data that will be needed for use in languages other than PHP. Another good point for sure.
  21. Floydian

    Serializing data

    I'm sure lots of folks already know how to serialize data using PHP. I'm sure there's plenty of debate to be had about when and where to use serialized data. My purpose here is this: I made a script that demonstrates how to handle serialized data for a friend. Just the basics. And since I made the demo script, I figured I might as well post it for anyone that might find it helpful. As with many things, this one deal isn't a cure all. It's not going to turn your world upside down. But it may be the perfect solution for one problem. The script is commented, and it should be fairly self explanatory. Running this script requires a valid mysql connection in order for the db escaping to work. Here's a link to a working example of this script: www.steelbreeze.us   <?php error_reporting(E_ALL); // You need a valid mysql connection to run this file mysql_connect('localhost', 'xxxxxxxxxxxx', 'xxxxxxxxxxx'); // This represents an items_bartered column and one row (i.e., items bartered on one item) // One master array of item/userid pairs, so // Doing a foreach on the master array ($items) gives a $value['item_id'] and $value['them_id'] $items = array( array('item_id' => 10, 'them_id' => 34), array('item_id' => 56, 'them_id' => 154), array('item_id' => 67, 'them_id' => 576), array('item_id' => 13, 'them_id' => 359), array('item_id' => 67, 'them_id' => 207), array('item_id' => 78, 'them_id' => 833), array('item_id' => 2, 'them_id' => 488), ); // serialize the array $serialized_items = serialize($items); echo "<h3>Serialized array</h3>"; echo $serialized_items .' '; // We need to escape this before storing it in the db, or it will fail $serialized_items_esc = mysql_real_escape_string($serialized_items); echo "<h3>Serialized and db escaped array</h3>"; echo $serialized_items_esc .' '; /* Please note that I'm not using the db escaped array. Since storing that _string_ in the db will remove the slashes added during the escaping, we won't have slashes to deal with when unserializing. */ // Now we'll unserialize the array: $unserialized_items = unserialize($serialized_items); echo "<h3>Unserialized array</h3>"; var_export($unserialized_items); // Now, what happens if the string we tried to unserialize couldn't be unserialized? echo "<h3>Unserialize error</h3>"; $string = 'this string can not be unserialized'; unserialize($string); echo "<h3>Unserialize error suppression</h3>"; $string2 = 'this string can not be unserialized'; $string2 = @unserialize($string2); echo "The variable we unserialized couldn't be unserialized, thus the unserialize function outputs: "; var_dump($string2); echo "<h3>Handling the new variable</h3>"; /* Since we will either get a value from our unserialized variable or a boolean false, that leaves the door open for that result to be anything from a string, to a number, an array, or an object. Thus we need to check if the variable is an object. */ echo ' $string2 could not be unserialized...</p>'; if (!is_array($string2)) { echo "\$string2 is not an array..."; } else { // do the foreach loop here } echo ' $unserialized_items was successfully unserialized...</p>'; if (!is_array($unserialized_items)) { echo "\$unserialized_items is not an array..."; } else { foreach ($unserialized_items as $value) { var_export($value); echo ' '; } }
  22. Re: Can you make a variable have a name like "legs"?   $spot = rand(1,3); switch ($spot) { case 1: $attackspot = 'legs'; case 2: $attackspot = 'arms'; case 3: $attackspot = 'head'; default: // no default } echo "You attacked {$r['username']} and hit their $attackspot doing $mydam damage.";   It sounds like you're looking for something like that. You can include hundreds of files into one script. It acts as if the script was already in the script. So, you have to make sure they jive together, or else you get errors... Hope that helps...
  23. Re: this scrpit requires an action Try doing a var_dump($_REQUEST['action']; and see what that outputs.
  24. Re: this scrpit requires an action Just for shts and giggles, have you tried replacing switch($_GET['action']) with switch($_REQUEST['action']) ?hope that helps...
  25. Re: Stop people from using IE on website The voice of wisdom: Check it out, IE 8 is largely standards compliant. IE 7 supports a large set of standards. Yes, IE 7 isn't where it should be, but IE 8 has gone a long way towards getting there. IE 6 is being more and more marginalized and looks to be at or below a 10% market share by the end of the year. IE 7 supports transparent pngs and as has already been mentioned, triggering standards mode using a Doc Type makes IE 7 very usable. Safari is very standards compliant. Opera is as well. There really isn't any reason to turn away folks from your web site. If people complain, you can simply just trash the mail if you don't feel like responding. All in all, if you are using good css technique, your pages should be fairly easy to get rendered in all major browsers with the exception of IE 6. The *css hack will allow you to target IE 7 and the _css hack will allow you to target IE 6. IE 8 shouldn't have any need of css hacks (we hope). If you are floating elements on page, float everything! At least float all your divs. Even better is using a css framework to lay out your page. If you are having problems with javascript in a particular browser, then use a javascript library to abstract out the browser incompatibilities that are plaguing you. It takes some time to get a good method down that works on all the major browsers, but it's very doable. The problem I see most often is, a css lay out problem is almost always caused by something more foundational in the lay out that isn't right. So, it's very very important that you start with a really good css framework for you site, or else you will have problems later on. Always keep in mind that browsers handle margins differently. Sometimes margins overlap with other elements and sometimes they don't. If something won't align, try removing margins, wrap that element in another element, and apply padding to the parent element you made as a wrapper. Doing so can provide a more cross browser method of applying css margins.   EDIT: One last bit of advise: never rely on pixel perfect layouts. Everything must have a gutter. A tolerance so to speak. If you're cutting up images and trying to lay them out next to each other and you expect them all to line up in every major browser, you're living in dreamland.
×
×
  • Create New...