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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • iceking

    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


  • Alvaro G Vicario

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

    *** iceking wrote/escribió (Thu, 16 Sep 2004 10:07:37 +0200):[color=blue]
    > 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?[/color]

    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="<?=htmlsp ecialchars($pre vious_page)?>"> Return</a></p>



    (Is is necessary to crosspost?)

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

    Comment

    • Daniel Tryba

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

      "iceking" <iceking_e <nospam>@yahoo. com> wrote:[color=blue]
      > 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.[/color]

      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

      Comment

      • iceking

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

        Excellent answer tot my problem!
        Of course it is server side <-> clientside
        Now I use the location.href for redirection after clicking away the
        message....

        I should have known this..... ;-o

        Thanks
        "Daniel Tryba" <news_comp.lang .php@canopus.nl > wrote in message
        news:cibjgf$oo$ 2@news.tue.nl.. .[color=blue]
        > "iceking" <iceking_e <nospam>@yahoo. com> wrote:[color=green]
        > > I have a php script that checks whether the user is allowed to perform[/color][/color]
        an[color=blue][color=green]
        > > action. If he is not allowed; I display a warning; using the alert[/color][/color]
        function.[color=blue][color=green]
        > > After clicking away this function, I want to redirect the user to the
        > > original page using the header function.[/color]
        >
        > 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
        >[/color]


        Comment

        • Good Man

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

          "iceking" <iceking_e<nosp am>@yahoo.com> wrote in
          news:41494a1f$0 $48933$e4fe514c @news.xs4all.nl :
          [color=blue]
          > 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?[/color]

          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,$vD estination) {
          echo("<html>\n" );
          echo("<head>\n" );
          echo("<title>Sy stem Message</title>\n");
          echo("<meta http-equiv=\"Content-Type\" content=\"text/html;
          charset=iso-8859-1\">\n");

          echo("<script language=\"Java Script\" type=\"text/JavaScript\">\n ");
          echo("alert('$v Msg');\n");
          echo("window.lo cation = ('$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.','retr y.php');

          ?>

          Comment

          • Rainmaker

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

            iceking <iceking_e wrote:[color=blue]
            > 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
            >
            >[/color]

            Although it has no real use to send headers after your output, as
            mentioned in the other posts, you can use
            http://nl2.php.net/manual/en/function.ob-start.php ob_start if you
            really want to. Dirty solution btw. Better not use it.

            Comment

            • Charles Pelkey

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

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

              -Charles


              "Rainmaker" <Rainmaker526NO @SPAMhotmail.co m> wrote in message
              news:7Jy3d.1046 57$C7.79323@ams news05.chello.c om...[color=blue]
              > iceking <iceking_e wrote:[color=green]
              > > Hi,
              > > I have a php script that checks whether the user is allowed to perform[/color][/color]
              an[color=blue][color=green]
              > > action. If he is not allowed; I display a warning; using the alert[/color][/color]
              function.[color=blue][color=green]
              > > 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[/color][/color]
              what[color=blue][color=green]
              > > 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
              > >
              > >[/color]
              >
              > Although it has no real use to send headers after your output, as
              > mentioned in the other posts, you can use
              > http://nl2.php.net/manual/en/function.ob-start.php ob_start if you
              > really want to. Dirty solution btw. Better not use it.
              >[/color]


              Comment

              Working...