
Floydian
Members-
Posts
900 -
Joined
-
Last visited
Never
Content Type
Profiles
Forums
Events
Everything posted by Floydian
-
I set it to display 40 pms per page. I'll delete 40 at a time..... done Cheers
-
Hello, and lemme say right off that I know this sounds lazy... My inbox is full. Can't new pms push the oldest one out of the inbox. I mean, for real, I can't be bothered to be deleting pms all the time. It'd be great if this was automatic. Also, there's hundreds of pms in there. Perhaps I can get you guys to just delete them all for me. Thanks and cheers
-
And that's an excellent reason, in general, to use a javascript library since these browser incompatibilities are taken care of for you.
-
Signature, my image is not showing up
Floydian replied to Floydian's topic in Feedback and Site Support
That's what's up ;) Thanks for checking it out. -
Hello, I've put in a signature and the image size is 530 x 73 pixels, and the file size is 6.33 KB. The editor shows the image is there, but the preview doesn't and it doesn't show up in the real signature. What am I doing wrong? PS, I have attached the image I'm using the for signature and I've attached a screen shot of the signature as it was being edited. [attach]1319[/attach] [attach]1320[/attach]
-
Kudos for posting that code blueDevil. Might I suggest packaging it as an object? That would allow the function names to be cleaned up a bit. [js] var textCount = { getID: function (supplied_ID) { var ID = null; if(document.layers) { ID = document.layers[supplied_ID]; } else if(document.all) { ID = document.all[supplied_ID]; } else if(document.getElementById) { ID = document.getElementById(supplied_ID); } return ID; }, fill: function (elementID, counterID, max_allowed_chars) { var element = this.getID(elementID); var counterElement = this.getID(counterID); counterElement.innerHTML = max_allowed_chars - element.value.length; }, create: function (elementID, counterID, max_allowed_chars) { var element = this.getID(elementID); var counterElement = this.getID(counterID); if(element.value.length > max_allowed_chars) { element.value = element.value.substring(0, max_allowed_chars); } else { counterElement.innerHTML = max_allowed_chars - element.value.length; } } } // textCount.create('foo', 'bar', 20); // textCount.fill('foo', 'bar', 20); [/js]
-
Re: CSS parent child divs and margins What does this have to do with javascript?
-
Re: CSS based menu script What does this have to do with javascript?
-
Re: How to use JSON for configuration settings Can you be more specific Vali? I talked about pros and cons, in relation to editing a JSON config file. Perhaps your question was already answered.
-
Re: Replace Here you go POG1: http://criminalexistence.com/ceforums/i ... ic=29999.0 Hope that helps.
-
A common problem for sites is how to set up a configuration file so that the settings can be easily edited and then used in php scripts. Storing config settings as a php script has the problem of being difficult to edit dynamically. It's a great option if all edits are going to be done manually though. Another option is to use JSON for storing the configuration settings. This has a few advantages over other methods. Many computer languages have native JSON encoding/decoding capabilities (inlcuding PHP >= 5.2). This means that your JSON config files can be used in multiple languages without any hassle at all! It is true that people have been using XML to do this. JSON is without question a more compact form and faster to parse as well. Without further ado, let's dig into some code. First up is a sample JSON encoded configuration file. {"constants":{"ONE":1,"TWO":2,"THREE":3},"setting_1":true,"setting_2":false,"setting_3":"\/home\/blah\/public_html\/","setting_4":false,"setting_5":"http:\/\/www.example.com\/","extracts":{"dog":"Spot","cat":"Skittles"}} I think the array structure of the JSON string should be fairly easy to see. Look for the { and }. I personally do not write JSON by hand. It's easy enough to make a php array and JSON encode it. Of course the point of using JSON is that you would make a script that edits the configuration file and saves the settings as JSON notation. So you wouldn't normally be editing by hand anyways. I save the config file as a .js file. This does mean that it's visible to the public if it's located in a public folder. Therefore, you should not have the config file in a public folder if you put a .js extension on it. Putting a .php extension isn't any good either because PHP will just output this as raw text. You really should have your config settings safely tucked away, so this shouldn't be a problem. Here is a sample script that loads the JSON string and does a few things with it as a demonstration. This script will dynamically create new constants and it will add variables to the symbol table as well. <?php // Load the configuration settings from the config.js file into the $configs array: $configs = json_decode(file_get_contents('./config.js'), true); // Define the constants set in the $configs['constants'] array: foreach ($configs['constants'] as $key => $constant) { defined($key) or define($key, $constant, true); } // Extract variables from the $configs['extracts'] array into the current symbol table: extract($configs['extracts']); // Display the results: printf('<pre>Constants%1$s%5$\'-10s%1$sONE: %2$s%1$sTWO: %3$s%1$sTHREE: %4$s%1$s%1$sExtracts%1$s%5$\'-16s%1$sdog: %6$s%1$scat: %7$s%1$s</pre>', "\n", ONE, TWO, THREE, '', $dog, $cat); These two scripts can be seen live here -> http://www.steelbreeze.us/play_ground/json/ I hope this helps :)
-
Re: Replace Hey POG1, you didn't answer my question, so I might be off base here. Here's my suggestion: Store your data in JSON format. Bring it into your script with file_get_contents and json_decode (using the second parameter of true so that you force it to be an array). Then call export(). You should see all the keys in the array become local variables. And all of this should be super fast. Hope that helps.
-
Re: Replace Are you able to control how the data is stored or does it have to be stored in the format stated?
-
Re: Database class for PHP 5+ and MySQL (Help) You don't know what you're getting if the value is public. Hence the need for visibility control, i.e., "So you always know what your getting / setting". Cheers Since your DTO is no different than a plain old variable (i.e, no methods, and no visibility), I think you're "optimized" argument can actually be applied against your DTO. You might as well just use a variable and be done with it.
-
Re: Database class for PHP 5+ and MySQL (Help) I'm sorry to say, but your "dto" is also lacking encapsulation. Firstly, it should have a myCounterDTO::increment() method so that the counter variable doesn't have to be modified directly. Secondly, since this is a static class, with all members static, it should be using the singleton pattern. If you did that, you could hide the counter variable, and only allow access to the methods that operate on it. increment() and get() perhaps a reset() Cheers
-
Re: Database class for PHP 5+ and MySQL (Help) I'd definitely disagree with that. Just for a basic refutation of your argument Vali, let's consider a query counter. You can have a static counter, but then anyone, anywhere, can set it anytime. I.e., the principle of encapsulation is broken. A query counter should only be set internally by the database class. You may say this is trivial, but if the query counter can be blown out, then the db connection resource can be blown out! Without setting the connection resource as protected/private, you cannot be guaranteed that your connection won't be blown out. Now, I respect that you personally don't see the value in this, so I'm only posting this response for the folks that may need to know this information.
-
Re: Database class for PHP 5+ and MySQL (Help) Vali, you didn't reply at all to what I said about visibility...
-
Re: Database class for PHP 5+ and MySQL (Help) Doing that means that all the properties need to be public, and that means that you have no visibility control. Being able to use $this gives you visibility control. If you want to ensure that only one instance of a class is instantiated, the singleton pattern should be used instead of making everything in the class static. The standard php singleton pattern uses a getInstance() method, which gives access to the singleton in any scope, so you get the best of static class methods, but also the visibility control of non static classes. Hope that helps.
-
Re: Database class for PHP 5+ and MySQL (Help) Yeah that's it Karlos. My personal opinion is that the close function should be it's own method. Database::close(); And then the destructor should call Database::close(); A minor detail, and it's my personal pref. What you have is theoretically sufficient since it's a good assumption that the connection would only be closed upon destroying the DB object, but it's not quite as thorough. ------------------------- I noticed you've got your property declarations stacked: protected $Connect, $ConnectStatus = false; public $TotalQueries, $Affected = null; That's fine, and I used to do that as well (the Horizons Database class has it, in fact :P ), but I've since learned that in order to get code documentation and code completion in IDE's, those really need to be seperate lines. /** * The MySQL connection resource * * @var resource */ protected $Connect; /** * Are we currently connect? * * @var boolean */ protected $ConnectStatus = false; /** * How many queries have we done? * * @var integer */ public $TotalQueries = 0; /** * How many rows were affected by the last query. * * @var mixed */ public $Affected = null; Now, when you type in $this->Conne ---- you will see the doc block above Database::Connect in a pop up to remind you or others using your code of what Database::Connect is for. Depending on the IDE and how it handles this stuff, you can get code documentation for public references to the class as well. $db = new Database(); $db->Con ---- and you will get code documentation here as well. If you do something weird like: $db = Database::getInstance(); This would be the *singleton* instantiation method, you're getInstance doc block should have a: @return Database Which will tell the IDE that $db = Database::getInstance(); is creating and storing a Database object in $db.
-
Re: First attempt at securing files. Eruondo, the key is understanding the input and the output. For instance, a MySQL field is an INTEGER and you want to match a value to that field. You need to have an integer to match it up with. Using abs() -- which removes the negative sign from a number and intval which converts a variables type to integer can be used on "user input" to create a safe positive integer. Escaping it using mysql_real_escape_string() or using htmlentities() or trim() are all pointless because you have an integer now. The converse is true. Once you have "cleaned" a string, you wouldn't use intval() or abs() on it.
-
Re: First attempt at securing files. $money = clean($ir['money'] + $moneygain); $price = clean($ir['crystals'] - $bribes); You're still doing way to much without any sort of specific goal in mind here. It's like having 10 pad locks on a cardboard door. You might feel safe, but you haven't understood the door you put the padlocks on. There's two ways I see this going. One is: You might be the kind of person that just does this as a hobby, tosses the pasta and sees if it sticks to the ceiling, and hopes for the best. That kind of person won't ever dissect all the functions and all of the code they use in order to understand what is happening. They rely on "forum code reviews" to ensure that their code doesn't have exploits in the hopes that the forum folks will find bugs before their players exploit them. The second kind of person you might be, is the kind of person that really does want to understand this stuff. If you are person one, I have nothing for you. You're a hobbyist, so if you get bad consequences from your code, then at least hopefully you had fun with your dabblings. If you are person two, then I highly suggest you study up on each of the functions you're using and try to understand exactly why they're being used. You're never going to get a good and full review of your code for free. So if you're serious, study up.
-
Re: First attempt at securing files. Wow, that's like trying to dance with three left feet... It's like using four fire extinguishers to put out a candle. It's like eating pie with five spoons. Overkill? Yes Would said overkill lead to security flaws or bugs? Yes
-
Re: My Login/Reg forms not working The action on the form is empty. Clicking the button does make the page load, but perhaps you need to fill in the action so the form submits to an "authentication" type page. :S Hope that helps...
-
The code snippet below will generate a random number within a certain distance from zero. $variance is a percentage, with 100% being equal to a distance of -1 to 1, and 50% being equal to a distance of -0.5 to 0.5. /** * Generates a random number within a given range. * * @param float $variance * A range above and below zero. * @return float * A number greater than or less than zero within a range defined by $varience. */ function deviation($variance) { return (mt_rand(0, $variance * 200) - $variance * 100) *0.0001; } The value returned can be then be multiplied against another value and added to itself. This can be useful if one needs to take crime exp and randomize it: $crime_exp = 100; $variance = deviation(5); $crime_exp = $crime_exp + $crime_exp * $variance; Sample code: <?php function deviation($variance) { return (mt_rand(0, $variance * 200) - $variance * 100) *0.0001; } for ($x = 1; $x <= 30; $x++ ) { $crime_exp = 100; $variance = deviation(5); $crime_exp = $crime_exp + $crime_exp * $variance; echo $crime_exp; echo "\n"; } Sample output: 104.12 99.79 95.94 101.6 99.02 104.06 95.01 95.56 95.04 97.4 101.99 95.35 95.62 104.19 100.49 100.25 98.19 101.89 98.05 104.86 99.58 99.24 104 101.17 104.99 98.42 100 95.33 95.82 103.02
-
Re: Checking if an IP is (maybe) a proxy Hey a_bertrand, $knownRouters=array("ubicom/","allegro-software","rompager"); Would that list allow AOL users through? I'm thinking that list there is for folks who use dial up or whatnot. If that's correct, then the list could be a lot longer, I presume. That's some nice code, thanks for posting it.