SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Dec 2002
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help needed with chat script (newbie)

    I have trying to build a chat script and have made some progress, but in trying to extend the features, I find that I do not understand some basic things about php and frames.

    I have uploaded the script that I started with (much changed now) to the web along with a screenshot of the output. http://www.nonlimited.net/chat.htm

    I have tried to syntax highlight it to make it easier for any helpers to follow it.

    It works well, but I need to understand how it actually tells what parts go in what frames.

    Normally with frames, each frame is a separate file, but not so in this php script. For the life of me, I cannot figure out WHY the submit button and tex bar etc are in the bottom frame and the posts are in the top frame.

    What part of the code dictates that??

    I need to know this so that I can add a third frame showing a list of all users logged in.

    If you can explain it, please remember that I have only been doing web scripts for about 4 weeks.

    Thanks
    Dave

  2. #2
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Look at these two lines:
    PHP Code:
    <frame name="posts" src="chat.php?action=posts&nick=<?php echo $nick?>;&chat=<?php echo $chat?>">
    <frame name="form" src="chat.php?action=form&nick=<?php echo $nick?>;">
    Do you see how the src of the frames are pointing to the script itself? When the browser reads that part, it retrieves those pages along with the arguements, in this case the variable passed is $action. So, in each frame, the script is executed again. If you'll look at the top, there's a small series of if conditional statements checking the value of $action:
    PHP Code:
    if (empty($action))
    ShowLoginForm();
    elseif (
    $action == "posts")
    ShowAddPosts();
    elseif (
    $action == "form")
    GetInput();
    elseif (
    $action == "enter")
    Login(); 
    If $action is empty, it executes the HTML/frames portion of the script (the ShowLoginForm() function). If $action is posts, forms, or enter, the script will instead execute the other functions. Make sense?

    Consequently, there are a few minor errors with the script also -- namely some misplaced ;'s.

    -Colin
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  3. #3
    SitePoint Member
    Join Date
    Dec 2002
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks very much Colin

    Actually I had an epiphany lasts night just as I laid down to sleep (Australian time).

    The answer just jumped into my head and I had to race over and write it down in case I forgot it. (I didnt, I even woke up dreaming of the script )

    Nonetheless your help is greatly appreciated.

    BTW, that is not my script, it is one on the web for a tutorial which I used as a starting point. But to show that would have been overly confusing for the question needed.

    Thanks
    Dave

  4. #4
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool Dave! Glad to hear you figured it out.

    -Colin
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.


Bookmarks

Posting Permissions

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