Actually, instead of checking in the first place, why not flat out insert it, and if it fails, continue? It would be quicker, and there is no chance for a race condition of another thread somehow inserting the same key just before another thread inserted the key just after the while loop finished. You would need to make sure the column for the code is set to primary or unique index though.
[code=php]while (true)
{
// Generate...
User Profile
Collapse
-
Based on what I see, it will work. But, you could improve it by making a method that will guarantee that it will get a result it can insert on the first try (no while loop with an unknown break point), so that if/when the database gets filled with these values, you don't pound the database while trying to find a value that has not been used. Also, instead of doing that while loop wrapped around the rand(0,9) call, you could simply do rand(0,999)...Leave a comment:
-
Locking Threads & Preventing Race Conditions
I've been trying to find a suitable method for preventing race conditions in my own code.
Currently I'm using a file and the flock function to prevent code in other threads from executing at the same time.
For example:
[code=php]<?php
$pointer = fopen ('./thread.lock', 'a+');
flock ($pointer, LOCK_EX);
// Code from here on in other threads cannot run at the same time.... -
I'm just wondering as to how I can do that on the old install I have of it (which is 32-bit, not 64-bit)?
Do I copy the new file to the old installation, or is mysqldump not dependent on either?Leave a comment:
-
"Table Does Not Exist" (But It Does?)
I copied the files from my "test" database on my old server (MySQL was not running) to my new server ("./mysql/data/test" folder), and after starting the server, SHOW TABLES; shows all of the tables that are supposed to be there, but running a SELECT * FROM `configuration` ; (for example) returns "test.configura tion does not exist).
I've tried the following repair statement since I'm not too familiar with backing... -
Ah, alright. I was not confused on how XSLT worked. But more so on the fact that all these tutorials said never to use CSS as XSLT is the W3C recommended way for styling XML (as if XSLT was a drop-in complete replacement of CSS), so I thought XSLT provided something similar to CSS, as well as the structure changes.
Edit: I don't like to do the transformation server-side. I already can do it without XML/XSLT using the Templating Engine...Leave a comment:
-
Before I Dive In To XML/XSLT
I've got a quick question. I've been using HTML/XHTML for years upon years upon years, and finally used XML for the first time in one of my applications that I developed using Ajax. I fully understand how to write XML, but not so much of XSLT. I took a quick look at XSLT, and I'm a little puzzled on how to do more of the flat out fancy effects that I can do in CSS. Can I do absolutely everything I can do in CSS (opacity, floating, z-index, shadows,... -
Alright, final thing to do to make it all work.
Edit: Solved! I'm going to try this in a different way; using onsubmit in the form.
On line 107, I have an onkeypress event.
How would I get "event" in there to act just like it would if I were to put it on the HTML element itself?Code:this.message.onkeypress = function () {chat.character (event);}
...Code:<input onkeypress="chat.character (event);
Leave a comment:
-
I actually figured out why I was getting no errors. I threw in an alert for each function that was called, and it always stopped at client, and didn't continue to handle. It was because in my haste for a fix, I replaced this.connection with just this.
So actually my object construction method seems to be performing perfectly fine, and this. is inheriting (I think) the way I want it to now. So now I'm just fixing errors, and looking...Leave a comment:
-
Oh, I forgot to include this, as I never gave any way to show the page that is using the chat.js file. So here is how I'm currently calling it.
...Code:window.onload = function () { chat.Initialize ( document.getElementById ("history"), "./index.php5?mode=retrieve2&list=history&room=<?php print (str_replace (' ', '+', $room)); ?>&build=<?php print ($build); ?>",Leave a comment:
-
I'm a little tired at this point, so I'm kind of just trying random things. I updated my code a little bit, so it looks more similar to second example you gave me, and I added a bit of code at the very last line of the chat.js file. I also split the "initiation " into two things rather than one (hence the extra line of code at the very bottom).
I'll look up the way you described on Google tomorrow to give me some more time...Leave a comment:
-
Alright, I've tried the that = this method, didn't work. Tried that = this (well, chat = this, and library = this) and enclosing the function calls in an anonymous function. Still was getting a "undefined" issue. So I tried doing window.library = this, got half undefined, half not undefined (really confused me there), even with all references to "this" replaced with window.library in all functions except the main one. All to no...Leave a comment:
-
"this" Keyword Inheritence Workaround
Alright, another question to pin on the experts. :D
I have an issue with "this" keyword in this case. The way I got around it before was to use a window property, but in this case I'm trying to keep everything within the context of the object.
So... Basically, this is referring to what I wanted it to refer to before (well, it worked in Mozilla, but not in IE, so I used the window workaround to fit both browsers).... -
Alright, it looks like (I guess) their original documentation they uploaded must have had some kind of bug, because now the entire documentation uses a \ for separators of namespaces, whereas it used to not. It makes a whole lot more sense now. :)
So instead of:
I'll...Code:::main :: $configuration -> get ('some_value'); $module = new ::module :: session :: login :: main (); $module -> render_login_box ();Leave a comment:
-
appendChild not attaching anchor link as expected
I have a simple XMLHttpRequest that grabs a list of messages from my server (I posted a question for a different aspect of this earlier)
I have decided to improve on it a little by adding in things that my message logger does (server-side) to turn things like:
or:Code:http://www.example.com
into URLs automatically by slapping onCode:http://example.com
...Code:<a href="http://www.example.com" target="_
-
Yup, I posted a snapshot of my session handler here in fact (I didn't test it, I just finished writing the 800 or so lines of code, it didn't even work in that state, just produced an error, then a fatal error). My code was deleted because I broke the posting guidelines. :)
The current state is 7,900 lines (including the support classes it relies on), and works flawlessly.
You can probably find a much smaller one that conforms...Leave a comment:
-
Firefox employs security protocols which do not let you do this. Internet Explorer works because it doesn't really employ many of the things Firefox does to keep a user safe. (The reason this is here is to prevent one from being able to XSS attacks)
I'm afraid there's not much you can do to get around it.
Edit: This seems more like a JavaScript/Ajax issue, not PHP.Leave a comment:
-
I've had a slight spark of genious of my old days of using the PHP session handler...
It looks like it's not being fully killed (typical)
If logout.php doesn't stop the session entirely; kill the old one, and leave it by starting a new one with a different identifier entirely.
Try this in logout.php:
...Code:$_SESSION = array(); // Destroy the variables. session_unset (); // Destroy the variables?! (It's
Leave a comment:
-
I believe that if they start their session inside of the members subdirectory, their session will not persist outside of the members subdirectory.
You mentioned a login box on the funtions.php file so they do not have to go to the members control panel; if this doesn't forward you to a file in members on the form submission, you may have two different sessions going. And when you logout in the members panel, you may be destroying that...Leave a comment:
-
I'm using the PHP 6 builds as well as that's my intended release platform for my current content management system program I'm building.
Right now I've got all my variables held in a single class named main in the global namespace (I plan to put it in its own namespace) so in modules that I keep in their separate namespaces (to prevent conflicts as the modules you can have are unlimited) I can reference to any class I have by using things...Leave a comment:
No activity results to display
Show More
Leave a comment: