How to redirect after (header) after sending an alert message

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default How to redirect after (header) after sending an alert message

    Hi,
    I have a php script that checks whether the user is allowed to perform an
    action. If he is not allowed; I display a warning; using the alert function.
    After clicking away this function, I want to redirect the user to the
    original page using the header function.
    However, I get the normal message " headers already sent"... I know what
    the problem is.
    But how do you normally deal with this situation? use a html/php for the
    warning instead of alert message? or is there another way?


    Thanks


    iceking Guest

  2. Similar Questions and Discussions

    1. How To Supress Acrobat Error Message And Alert Message
      Is there any way to supress those pop up message? If can't, is there any way to catch it?
    2. Error Message When Sending Message In Windows Mail
      Am I the only one getting an error message when replying to a posted message using Windows Mail. Every time I send a message I get a popup error...
    3. warning message (alert)
      Hi, I want to create the alert message ' You are about to over writte the acct, do you wish to continue?'). I need two buttons here, YES/ NO. If...
    4. Regarding to alert message
      Hi If our text contains only characters but wrongly we add the number so alert message will come. In that we want only to remove the number not...
    5. alert or message box?
      I am not clear ... whether to use alert of JavaScript or messagebox of VBScript in ASP. But what I want is that when a user has some error I want...
  3. #2

    Default Re: How to redirect after (header) after sending an alert message

    *** iceking wrote/escribió (Thu, 16 Sep 2004 10:07:37 +0200):
    > I have a php script that checks whether the user is allowed to perform an
    > action. If he is not allowed; I display a warning; using the alert function.
    > After clicking away this function, I want to redirect the user to the
    > original page using the header function.
    > However, I get the normal message " headers already sent"... I know what
    > the problem is.
    > But how do you normally deal with this situation? use a html/php for the
    > warning instead of alert message? or is there another way?
    There's no point in displaying info for the user at the same time you're
    redirecting the user out of the page where that info is.

    Unless you have very specific needs I can't see a reason to avoid Really
    Simple Solutions:

    <p>Action not allowed</p>
    <p><a href="<?=htmlspecialchars($previous_page)?>">Retur n</a></p>



    (Is is necessary to crosspost?)

    --
    -- Álvaro G. Vicario - Burgos, Spain
    -- Thank you for not e-mailing me your questions
    --
    Alvaro G Vicario Guest

  4. #3

    Default Re: How to redirect after (header) after sending an alert message

    "iceking" <iceking_e <nospam>@yahoo.com> wrote:
    > I have a php script that checks whether the user is allowed to perform an
    > action. If he is not allowed; I display a warning; using the alert function.
    > After clicking away this function, I want to redirect the user to the
    > original page using the header function.
    You are confused:

    -the alert function is clientside javascript
    -header is serverside php

    These can't work together in the way you describe above since by the
    time the alert gets to the client, the php script is long gone.

    The solution you might be looking for is the javascript location.href
    property...

    --

    Daniel Tryba

    Daniel Tryba Guest

  5. #4

    Default Re: How to redirect after (header) after sending an alert message

    "iceking" <iceking_e<nospam>@yahoo.com> wrote in
    news:41494a1f$0$48933$e4fe514c@news.xs4all.nl:
    > Hi,
    > I have a php script that checks whether the user is allowed to perform
    > an action. If he is not allowed; I display a warning; using the alert
    > function. After clicking away this function, I want to redirect the
    > user to the original page using the header function.
    > However, I get the normal message " headers already sent"... I know
    > what the problem is.
    > But how do you normally deal with this situation? use a html/php for
    > the warning instead of alert message? or is there another way?
    i have built this php function which does exactly what you want - create
    a javascript warning, and direct them to a new page when they click 'ok':

    <?php
    function popup($vMsg,$vDestination) {
    echo("<html>\n");
    echo("<head>\n");
    echo("<title>System Message</title>\n");
    echo("<meta http-equiv=\"Content-Type\" content=\"text/html;
    charset=iso-8859-1\">\n");

    echo("<script language=\"JavaScript\" type=\"text/JavaScript\">\n");
    echo("alert('$vMsg');\n");
    echo("window.location = ('$vDestination');\n");
    echo("</script>\n");
    echo("</head>\n");
    echo("<body>\n");
    echo("</body>\n");
    echo("</html>\n");
    exit;
    }
    ?>


    So, you call it like this:
    <?php
    //they made an error
    popup('Hey, you made a mistake, jackass.','retry.php');

    ?>
    Good Man Guest

  6. #5

    Default Re: How to redirect after (header) after sending an alert message

    iceking <iceking_e wrote:
    > Hi,
    > I have a php script that checks whether the user is allowed to perform an
    > action. If he is not allowed; I display a warning; using the alert function.
    > After clicking away this function, I want to redirect the user to the
    > original page using the header function.
    > However, I get the normal message " headers already sent"... I know what
    > the problem is.
    > But how do you normally deal with this situation? use a html/php for the
    > warning instead of alert message? or is there another way?
    >
    >
    > Thanks
    >
    >
    Although it has no real use to send headers after your output, as
    mentioned in the other posts, you can use
    [url]http://nl2.php.net/manual/en/function.ob-start.php[/url] ob_start if you
    really want to. Dirty solution btw. Better not use it.
    Rainmaker Guest

  7. #6

    Default Re: How to redirect after (header) after sending an alert message

    If using a javascript ALERT, try using a javascript redirection... ie:
    top.location.href= "url";

    -Charles


    "Rainmaker" <Rainmaker526NO@SPAMhotmail.com> wrote in message
    news:7Jy3d.104657$C7.79323@amsnews05.chello.com...
    > iceking <iceking_e wrote:
    > > Hi,
    > > I have a php script that checks whether the user is allowed to perform
    an
    > > action. If he is not allowed; I display a warning; using the alert
    function.
    > > After clicking away this function, I want to redirect the user to the
    > > original page using the header function.
    > > However, I get the normal message " headers already sent"... I know
    what
    > > the problem is.
    > > But how do you normally deal with this situation? use a html/php for the
    > > warning instead of alert message? or is there another way?
    > >
    > >
    > > Thanks
    > >
    > >
    >
    > Although it has no real use to send headers after your output, as
    > mentioned in the other posts, you can use
    > [url]http://nl2.php.net/manual/en/function.ob-start.php[/url] ob_start if you
    > really want to. Dirty solution btw. Better not use it.
    >

    Charles Pelkey Guest

  8. #7

    Default How to redirect after (header) after sending an alert message

    "iceking" <iceking_e<nospam>@yahoo.com> wrote in
    news:41494a1f$0$48933$e4fe514c@news.xs4all.nl:

    I have built this php function which does exactly what you want - create
    a javascript warning, and direct them to a new page when they click 'ok':

    <?php
    function popup($vMsg,$vDestination) {
    echo("<html>\n");
    echo("<head>\n");
    echo("<title>System Message</title>\n");
    echo("<meta http-equiv=\"Content-Type\" content=\"text/html;
    charset=iso-8859-1\">\n");

    echo("<script language=\"JavaScript\" type=\"text/JavaScript\">\n");
    echo("alert('$vMsg');\n");
    echo("window.location = ('$vDestination');\n");
    echo("</script>\n");
    echo("</head>\n");
    echo("<body>\n");
    echo("</body>\n");
    echo("</html>\n");
    exit;
    }
    ?>


    So, you call it like this:
    <?php
    //they made an error
    popup('Hey, you made a mistake, jackass.','retry.php');

    ?>[/QUOTE]

    Thanks,exactly what I also needed :)
    Unregistered Guest

  9. #8

    Thumbs up Re: How to redirect after (header) after sending an alert message

    Thanks a lot your script helped me a lot!!!
    Unregistered Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139