Wolphie
-
Posts
682 -
Joined
-
Last visited
Never
Posts posted by Wolphie
-
-
Is it possible to intentionally hang an AJAX application to listen for any incoming data?
For example, you have a chat room... you open a connection to get any new messages... if they're are no new messages then keep the connection open until a message is available. But have a timeout interval so it doesn't cause any over head?
Correct me if I'm wrong about anything, it's just I'm creating a chat application and would like to know the most efficient and viable method of retrieving messages, the user list etc..
-
Not entirely sure which forum this should be in, although it's also a PHP issue.
I'm developing a MySQL based chat room which uses AJAX to send/retrieve messages and the user list.
Now, I'm faced with a dilemma. What would be the best way to go about retrieving the messages and user list?
Most AJAX based chat rooms use setTimeout() with a small interval to query the PHP script every x number of milliseconds, this would cause a lot of over head.
I've read somewhere about 'hanging AJAX' which basically means AJAX makes a request to a PHP script and if the PHP script has no new data, it will 'hang' there until new data is available. Now this would reduce over head dramatically, but I have no idea how to go about it.
Has anybody experimented with this technique or would using setTimeout() be the best approach here?
Thanks.
-
Never mind I found the problem, I'm using AJAX to make this request, therefore data has already been sent when the setcookie() function is called.
-
I have a problem when trying to remove cookies.
I use
setcookie('COOKIE_NAME', '', time() - 3600);
To remove the cookie, however, the cookie isn't being removed.
Anyone had a similar issue?
-
list() doesn't write the values to an array. The result is already returned as an array i.e. mysql_fetch_array();
-
The multi part/form data part allows files to be attached to the form. It's the same principle as what you get on a letter, at the bottom; if the letter contains enclosed documents it will have "ENC" at the bottom to indicate that documents are attached to the letter.
-
Luckily you have functions like mysql_real_escape_string(), htmlentities() etc.. to help you with user inputted data sanitation. But yes, as DW said; everything relating to magic quotes will be deprecated.
-
I see your problem, but why does it sometimes return two kills? Which would you need to actually use in that case aswell?
Adam
If "kills_" or what ever is stored as an array key, then PHP should display an error if it exists twice (could be wrong). Regardless though, from my experience, if it's a key then the first array element will be overwritten by the second.
-
Slashes will not always have slashes
Sorry, bit sleepy.
Should be: "Quotes will not always have slashes"
-
Slashes will not always have slashes if it's removed. Since most people remove them any way before inserting data into the database. Yes, I think from reading about it that everything related to magic quotes will be removed.
-
I don't fully understand what you mean. Perhaps if you provided the code that you have relevant to the question, I may be able to assist you. Unless anybody else could offer me a bit of clarity?
-
just check if the input fields are missing (all inclusive example):
<?php if(!$_POST['blah']) { echo "nothing entered <br />"; } ?> <form action = '' method = 'post'> <input type = 'text' name = 'blah'> <input type = 'submit' value = 'submit'> </form>
Surely wouldn't $_POST['blah'] come back true regardless if it exists in the form? I could be wring but if it were me, I'd be checking the string length.
if (empty($_POST['blah']) { // Error... }
-
In order for us to help you, we need to see your code. There is clearly a problem whether it be user error or the server, there is still a problem. So for us to understand and try to locate/solve the problem, providing the code would be a great help, along with any other information you can provide about the server it's running on.
-
For us to have ideas and to help you, we'd need to see the code to begin with. However, file transfers can timeout depending on the liability, bandwith, speed and usage of the line you're using to connect to the internet.
-
I would recommend a little bit of nifty JavaScript. I would suggest having a form that displays only one text field, have a link or a button next to that text field so when users clicked it, you would append another text field and so on.
For the PHP side of things, I would suggest making these into an array. I.e.
<input type="text" name="guests[]" id="guests" />
Note the []! This will make "guests" an array.
For example:
echo $_POST['guests'][0]; // Guest 1 echo $_POST['guests'][1]; // Guest 2 // And so on..
-
Oh I know about strlen, but I just heard that you could check the length of the string using regular expressions. I guess you can only check how many iterations of the rule has been performed. Thanks, guys, this solved my problem and thanks for the detailed description kratsg. Thanks again neil.
-
I think you're going about this the wrong way. I would use this:
// Database connection statements... $password = mysql_real_escape_string($_POST['password']); /** * Always use mysql_real_escape_string() on user inputted data. I would also perform extra security checks. Such as username length, and * check for HTML elements and escape them with htmlentities(); */ $username = mysql_real_escape_string($_POST['username']); // sha1($password) depending on which encryption function you used when the user signed up. $check = sprintf("SELECT `id`, `username`, `password` FROM `dbname` . `users` WHERE `username` = '%s' AND `password` = '%s' LIMIT 1", $username, sha1($password)); $result = mysql_query($check); if (mysql_num_rows($check) > 0) { // Log in valid... } else { // Log in failed... }
-
Yes, I only want to check that the length of the string is between 0 and 70 characters in length.
-
He means that, before you begin the loop you have queried the database and stored the query inside two variables, $query and $result. Once you begin the loop, these variables are overwritten by the new query therefore overwriting the old query and stopping the loop.
Again, he is also right. Depending on the amount of users you have, updating every user would be a huge strain on the server. I would suggest only updating the current users' energy when they visit a page that displays their energy level, for example their statistics page. Make this energy increase periodically.
The user would be none the wiser, since it would all be happening behind the scenes. They will only know what they are told.
-
Okay, I'm beginning to understand it a bit more now.
So, I'll try again based on my original rule..
if (preg_match('/[^A-Za-z\d]{0,70}/', $str) { // Error... }
Would that do as I explained before? Or is "{0,70" still incorrect? If so, could you provide an example please?
-
Thanks for the description both of you. It's much appreciated.
kratsg, do you have any advice about limiting the length of the string? Between 0 and 70 characters long?
Also, if possible could you explain what the "+", "/" and rules enclosed in braces and parenthesis is used for please?
Thanks.
-
I would strongly suggest using an existing mailing class, simply to make life easier. I always use this, it's free and easy-to-use and also allows SMTP. It will send the message in HTML or Plain Text depending on whether the client supports HTML or not.
http://phpmailer.codeworxtech.com/
-
header() will only work providing that you haven't displayed ANY data at all on the page before. Including HTML.
Check if headers have been sent, if they have use either javascript or HTML to do the redirect.
if (!headers_sent()) { header("Location: page.php"); } else { $redirect = '<script type="text/javascript">window.location = "page.php";</script>'; $redirect .= '<noscript><meta type="refresh" content="0;url=page.php" /></noscript>'; echo $redirect; }
-
Hi,
I'm totally new to regular expressions. So I'm looking for a bit of guidance and descriptions. My problem is that I'm trying to validate a name and description of a category for example, the name and description should only contain upper and lower case letters from A-Z and numbers from 0-9 with no special characters, not even an underscore. I also want to be able to limit the length of the string using regular expressions.
Here is what I have
if (!preg_match('[A-Za-z][A-Za-z0-9]{0,70}+', $str) { // Error... }
Could anybody provide any guidance and/or examples and a description of the operators used in regular expressions? e.g., + / *
Much appreciated, thanks.
Hanging AJAX
in Javascript Help
Posted
No, but couldn't you use sleep in PHP to 'hang' the connection intentionally?