Forwarding to next php script on correct input?

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

    Forwarding to next php script on correct input?

    Hi!
    I need the best way to solve a problem, I'm a newbie.

    I have "login.php" , a login script. That page first displays a login
    form with itself as target of a post-request to validate data when
    user presses the login-button (I can't change that setup).

    If the login is not correct I want to display the login form again and
    show an additional line displaying the error, that is easy and already
    working.

    But if the login was correct I want to display another page to the
    user that is constructed in "main.php".

    Now what is the best way (easiest and most compatible) when I'm in
    "login.php" to switch to the next page "main.php"?

    Thank you very much for your answers!
  • Kevin Thorpe

    #2
    Re: Forwarding to next php script on correct input?

    Joe Randstein wrote:
    [color=blue]
    > Hi!
    > I need the best way to solve a problem, I'm a newbie.
    >
    > I have "login.php" , a login script. That page first displays a login
    > form with itself as target of a post-request to validate data when
    > user presses the login-button (I can't change that setup).
    >
    > If the login is not correct I want to display the login form again and
    > show an additional line displaying the error, that is easy and already
    > working.
    >
    > But if the login was correct I want to display another page to the
    > user that is constructed in "main.php".
    >
    > Now what is the best way (easiest and most compatible) when I'm in
    > "login.php" to switch to the next page "main.php"?
    >
    > Thank you very much for your answers![/color]

    This must come before any output at all:
    header('Locatio n: main.php');

    Comment

    • Matthias Esken

      #3
      Re: Forwarding to next php script on correct input?

      Kevin Thorpe wrote:
      [color=blue]
      > This must come before any output at all:
      > header('Locatio n: main.php');[/color]

      Of course, according to the RFCs, you have to add the domain name:

      header('Locatio n: http://www.example.com/main.php');
      exit;

      Matthias

      Comment

      • Garp

        #4
        Re: Forwarding to next php script on correct input?


        "Matthias Esken" <muelleimer2004 nospam@usenetve rwaltung.org> wrote in
        message news:c6mnif.260 .1@usenet.esken .de...[color=blue]
        > Kevin Thorpe wrote:
        >[color=green]
        > > This must come before any output at all:
        > > header('Locatio n: main.php');[/color]
        >
        > Of course, according to the RFCs, you have to add the domain name:
        >
        > header('Locatio n: http://www.example.com/main.php');
        > exit;
        >
        > Matthias[/color]

        He's right! RFC 2616 section 14 (Head Field Definitions):

        14.30 Location
        The Location response-header field is used to redirect the recipient to a
        location other than the Request-URI for completion of the request or
        identification of a new resource. For 201 (Created) responses, the Location
        is that of the new resource which was created by the request. For 3xx
        responses, the location SHOULD indicate the server's preferred URI for
        automatic redirection to the resource. The field value consists of a single
        absolute URI.

        Location = "Location" ":" absoluteURI
        <snip>

        Prepend $_SERVER['host'] (and /) to your relativeURI:

        <?php

        header("Locatio n: ".$_SERVER['host']."/index.php");

        ?>


        Garp




        Comment

        • Joe Randstein

          #5
          Re: Forwarding to next php script on correct input?

          Matthias Esken <muelleimer2004 nospam@usenetve rwaltung.org> wrote in message news:<c6mnif.26 0.1@usenet.eske n.de>...[color=blue]
          > Kevin Thorpe wrote:
          >[color=green]
          > > This must come before any output at all:
          > > header('Locatio n: main.php');[/color]
          >
          > Of course, according to the RFCs, you have to add the domain name:
          >
          > header('Locatio n: http://www.example.com/main.php');
          > exit;
          >
          > Matthias[/color]

          Thanks to both of you!

          More questions:

          -so far I have programmed so that I can use relative URLs in my
          scripts, so I can move the scripts to a subdirectory or other domain
          and do not have to care. But if you say I should add domain name and
          directory to the Location-header, then what is the easiest way to get
          that without hardcoding it?

          -Would this be an alternative to the location-header? Last night
          (before I read your replies) I thought about turning on buffering at
          start of my login.php. When I would find out that the given data by
          user was correct, then I would empty the buffer and include() my
          main.php and then don't give any more output by login.php.
          Shouldn't the user then see only output from main.php? What could be
          difficulties with this solution?

          But I will now try first the Location-header. It seems easier ;-)

          Comment

          • Juha Suni

            #6
            Re: Forwarding to next php script on correct input?

            Joe Randstein wrote:[color=blue]
            > More questions:
            >
            > -so far I have programmed so that I can use relative URLs in my
            > scripts, so I can move the scripts to a subdirectory or other domain
            > and do not have to care. But if you say I should add domain name and
            > directory to the Location-header, then what is the easiest way to get
            > that without hardcoding it?[/color]

            Usually I tackle this by using a global settings.php.in c-file (located
            below the www-root directory), which sets the common configuration
            settings for the scripts (paths, database settings and so on). This way
            you can easily change the path-specific settings if necessary.

            So in settings.php.in c you could have:
            $config["domain"] = 'http://www.example.com/';
            $config["path_root"] = 'scripts/';

            and in the program files you could use:
            include('/home/www/mydir/settings.php.in c');
            header('locatio n: ' . $config["domain"] . $config["path_root"] .
            'myscript.php') ;

            HTH

            --
            Suni

            Comment

            • Tim Van Wassenhove

              #7
              Re: Forwarding to next php script on correct input?

              In article <4091080e$0$247 34$39db0f71@new s.song.fi>, Juha Suni wrote:[color=blue]
              > Joe Randstein wrote:[color=green]
              >> More questions:
              >>
              >> -so far I have programmed so that I can use relative URLs in my
              >> scripts, so I can move the scripts to a subdirectory or other domain
              >> and do not have to care. But if you say I should add domain name and
              >> directory to the Location-header, then what is the easiest way to get
              >> that without hardcoding it?[/color]
              >
              > Usually I tackle this by using a global settings.php.in c-file (located
              > below the www-root directory), which sets the common configuration
              > settings for the scripts (paths, database settings and so on). This way
              > you can easily change the path-specific settings if necessary.
              >
              > So in settings.php.in c you could have:
              > $config["domain"] = 'http://www.example.com/';
              > $config["path_root"] = 'scripts/';
              >
              > and in the program files you could use:
              > include('/home/www/mydir/settings.php.in c');
              > header('locatio n: ' . $config["domain"] . $config["path_root"] .
              > 'myscript.php') ;[/color]

              If the location of that settings file changes, you still have to update
              all those files. In this case auto_prepend can be handy ;)


              --

              Comment

              • Jan Pieter Kunst

                #8
                Re: Forwarding to next php script on correct input?

                In article <c6rb3t$f3i2c$2 @ID-188825.news.uni-berlin.de>,
                Tim Van Wassenhove <euki@pi.be> wrote:
                [color=blue][color=green]
                > > So in settings.php.in c you could have:
                > > $config["domain"] = 'http://www.example.com/';
                > > $config["path_root"] = 'scripts/';
                > >
                > > and in the program files you could use:
                > > include('/home/www/mydir/settings.php.in c');
                > > header('locatio n: ' . $config["domain"] . $config["path_root"] .
                > > 'myscript.php') ;[/color]
                >
                > If the location of that settings file changes, you still have to update
                > all those files. In this case auto_prepend can be handy ;)[/color]

                What I do is use one config file which sets all the paths and is located
                in . (i.e. in the same directory as the rest of the scripts), so that it
                is always findable in a default PHP configuration. I include that file
                in every script. So if the location of settings files etc. changes, I
                only have to update my path_config.inc .php file.

                JP

                --
                Sorry, <devnull@cauce. org> is een "spam trap".
                E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.

                Comment

                • Tim Van Wassenhove

                  #9
                  Re: Forwarding to next php script on correct input?

                  In article <devnull-A7BB3E.18462129 042004@news1.ne ws.xs4all.nl>, Jan Pieter Kunst wrote:[color=blue]
                  > In article <c6rb3t$f3i2c$2 @ID-188825.news.uni-berlin.de>,
                  > Tim Van Wassenhove <euki@pi.be> wrote:
                  >[color=green][color=darkred]
                  >> > So in settings.php.in c you could have:
                  >> > $config["domain"] = 'http://www.example.com/';
                  >> > $config["path_root"] = 'scripts/';
                  >> >
                  >> > and in the program files you could use:
                  >> > include('/home/www/mydir/settings.php.in c');
                  >> > header('locatio n: ' . $config["domain"] . $config["path_root"] .
                  >> > 'myscript.php') ;[/color]
                  >>
                  >> If the location of that settings file changes, you still have to update
                  >> all those files. In this case auto_prepend can be handy ;)[/color]
                  >
                  > What I do is use one config file which sets all the paths and is located
                  > in . (i.e. in the same directory as the rest of the scripts), so that it
                  > is always findable in a default PHP configuration. I include that file
                  > in every script. So if the location of settings files etc. changes, I
                  > only have to update my path_config.inc .php file.[/color]

                  This is what i used to do before.

                  But the difference with .htaccess is that .htaccess also works for
                  subdirectories. And with a init.php you end up including
                  .../../../init.php in the scripts that are in subdirectories.

                  Comment

                  Working...