Page 1 of 3 123 LastLast
Results 1 to 10 of 30

Thread: Please Help Me With This Code!!! :( (ALERT CODE)

  1. #1
    Join Date
    Jun 2006
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Please Help Me With This Code!!! :( (ALERT CODE)

    Hello guys.

    I was wondering if anyone knows of a code that allows admins to send pop up alert messages to the users that are currently viewing a web page. Sourta like a Java script pop up alert, but one that admins can send them when ever they want. I'm not even sure if there is a such script but its worth a try.

    Thanks in advance,
    Joe

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    There isn't, and it's not possible.
    Well -- using AJAX and some server-side scripting, it probably is. But it isn't with pure Javascript.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jun 2006
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok,

    Do you know of any tutorials that can teach me how to do that with AJAX and serverside scripting???

    Thanks,
    Joe

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I have no idea about your skill level, so please don't be insulted when I say this.... AJAX is pretty complex. It involves knowing both javascript and php well, and then getting them to work together. It isn't a thing you could find a quick little tutorial on, for example, but rather something you could write many books about.
    Just google for some examples/tutorials and see if it starts making sense.
    Just ask yourself... is this really worth it? If so, then dive right in.

    An easier way would be to use just server side coding.
    You could store a message somewhere, and only display the alert (using php to control the html/javascript output... this is easy) if you wanted to display the alert.
    It wouldn't be live, but it would display upon refreshing.
    Kinda like the PM system here.


    Anyway, there are a lot of ways of doing it... depends how much work/learning you want to do.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Jun 2006
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I know PHP and I know a LITTLE bit of Javascript... I reallly need help. If you can maby work this out for me I will give you Major Credit on my website...

  6. #6
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33
    I have no idea about your skill level, so please don't be insulted when I say this.... AJAX is pretty complex. It involves knowing both javascript and php well, and then getting them to work together.
    You forgot to mention HTTP. If someone plans on writing code using an XMLHTTP request object, they should thoroughly understand client and server behaviour as you're essentially writing part of the former.

    Then again, anyone attempting to control server behaviour should also have a very good understanding of the HTTP protocol (and it's amazing just how many people don't).


    Quote Originally Posted by jad9321
    I know PHP and I know a LITTLE bit of Javascript... I reallly need help.
    Even if you followed Twey's suggestion, it would require polling the server, and that's not a nice thing to do either to the server, or the user.

    The server cannot send anything of its own accord; the client must initiate a request. The solution you want is simply not practical over HTTP.

    Mike

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Yeah, HTTP too, Mike.


    We talked on AIM last night, and here's the code I suggested. This will happen on refreshing, based off a text file... upload with content if you want it displayed, leave the file blank or don't upload if you don't want it displayed. Quite simple, and I suggested adding in cookies. Anyway, here's a start:
    PHP Code:
    PUT THIS AT THE TOP OF YOUR PAGE, EVERY PAGE YOU WANT TO HAVE THE ALERT ON:
    <?php
    $alert 
    = @file_get_contents('alert.txt');
    if (
    $alert != "") {$alert " alert('".$alert."');";}
    ?>
    AND THIS FOR YOUR BODY TAG:
    <body<?php echo $alert?>>
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Uuuhhh...

    Example output would be:
    Code:
    <body alert('You've got mail!');>
    That's not valid HTML, and the quotes would break the script even if it were. Not only that, what if s/he wanted to move the file? That's a lot of pages to edit. I'd suggest putting this in a seperate file:
    Code:
    <?php
    $alert = addslashes(file_get_contents('alert.txt'));
    if ($alert !== '') $alert = " onload=\"window.alert('$alert');\"";
    ?>
    ... then including it:
    Code:
    <?php require_once('alert.inc.php'); ?>
    <body<?php echo($alert); ?>>
    @ should never be used. It makes debugging a lot harder -- you have to go through the code removing all those @s to get to the bottom of a problem. If you want to suppress error reporting, do it globally with
    Code:
    error_reporting(E_NONE);
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Ok, wow, I was tired.

    The alert thing needs to be replaced with:
    onLoad="alert(....

    My bad.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #10
    Join Date
    Jun 2006
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Okkk,

    That code dosen't work. http://smilealert.ueuo.com/alert.php I need that fixed than I need the knowledge of the cookie. I want to to block Only a message but once the message is displayed it shouldn't show up again. But if I change the alert.txt it should show the new message.
    Last edited by jad9321; 06-21-2006 at 01:35 PM.

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
  •