Professional Web Applications Themes

How to redirect after (header) after sending an alert message - PHP Development

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

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

  3. #3

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

    "iceking" <iceking_e <nospam>> 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

  4. #4

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

    "iceking" <iceking_e<nospam>> wrote in
    news:41494a1f$0$48933$e4fe514cnews.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;
    cht=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

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

  6. #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" <Rainmaker526NOSPAMhotmail.com> wrote in message
    news:7Jy3d.104657$C7.79323amsnews05.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

  7. #7

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

    "iceking" <iceking_e<nospam>> wrote in
    news:41494a1f$0$48933$e4fe514cnews.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;
    cht=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

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

Similar Threads

  1. How To Supress Acrobat Error Message And Alert Message
    By ckpang@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 10
    Last Post: January 15th, 11:33 AM
  2. Replies: 4
    Last Post: March 23rd, 12:56 AM
  3. warning message (alert)
    By kt03 in forum Coldfusion - Getting Started
    Replies: 2
    Last Post: April 14th, 08:32 PM
  4. Regarding to alert message
    By satishsrs in forum Macromedia Flex General Discussion
    Replies: 1
    Last Post: March 2nd, 09:42 PM
  5. alert or message box?
    By monika in forum ASP
    Replies: 2
    Last Post: September 25th, 08:48 AM

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
  •  

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