Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    need help with a complex snippet for chat room

    Hi there,

    I'm fairly new to php but have managed in the past three weeks to go from zero knowledge of php/mysql to building a fully functioning chat room with lots of features.

    One thing I have not been able to figure out though.

    First, I'll describe how my chat works. It's a php script, and once a user is logged in, they are able to chat, etc. It is a post-pull system. Meaning the user must hit "enter" to poll the chat site. In order to help make this system a little faster, I installed Zend Optimizer/Accelerator with my php build so the scripts will be a bit faster with multiple users polling the server for that specific script. I prefer this method at the moment (while learning) over the live update type of chats with java, etc.

    So, user is logged in and can chat via a text input field named "mes" (EX <input type=text name=mes maxlength=600>)

    I want to implement a /command system. I've tried everything I can find snippet wise and code wise on the internet and google and forums, but I haven't been succesful in doing what I want to do, which is this basically

    User types /command [parameter] etc etc , Example /kick USERNAME REASON

    once submitted, I need an if statement that recognizes if the first string (in this case /kick ) begins with a forward slash /
    If it does begin with a forward slash, I then need it to strip the forward slash from that word (ive actually succesfully made a preg_replace that does this part but cant integrate it overall) then, once the forward slash has been stripped and replaced with "nothing", I want to check if (!file_exists(/path/to/command/files/command.php) then display error, else, include command.php

    I'm going to put all of the user commands into their own PHP files in a directory to cut out on the main chat script having an unneccessary extra 5,000 lines of code (there will be upwards of 30-40 commands)

    this way, if a forward slash / exists at the beginning of the first word in the input field, it is stripped, and a check is done to see if the file exists, if it does exist, use the php INCLUDE command so the code for that command is executed in the main chat script execution, if not, return an error saying * Sorry that command is not recognized or does not exist.

    any help would be greatly , greatly appreciated from a junior php learner in progress.

  • #2
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    That sounds like you already put a lot of thought into it. What exactly are you having trouble with?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •