Jump to content

Wolphie

Members
  • Posts

    682
  • Joined

  • Last visited

    Never

Posts posted by Wolphie

  1. 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..

  2. 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.

  3. 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.

  4. 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.

  5. 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...
    }
    

  6. 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.

  7. 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..
    

  8. 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...
    }
    

     

  9. 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.

  10. 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;
    }
    

  11. 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.

     

×
×
  • 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.