This is a discussion on Forwarding to next php script on correct input? within the PHP Language forums, part of the PHP Programming Forums category; Hi! I need the best way to solve a problem, I'm a newbie. I have "login.php", ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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! |
|
|||
|
Joe Randstein wrote:
> 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! This must come before any output at all: header('Location: main.php'); |
|
|||
|
Kevin Thorpe wrote:
> This must come before any output at all: > header('Location: main.php'); Of course, according to the RFCs, you have to add the domain name: header('Location: http://www.example.com/main.php'); exit; Matthias |
|
|||
|
"Matthias Esken" <muelleimer2004nospam@usenetverwaltung.org> wrote in message news:c6mnif.260.1@usenet.esken.de... > Kevin Thorpe wrote: > > > This must come before any output at all: > > header('Location: main.php'); > > Of course, according to the RFCs, you have to add the domain name: > > header('Location: http://www.example.com/main.php'); > exit; > > Matthias 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("Location: ".$_SERVER['host']."/index.php"); ?> Garp |
|
|||
|
Matthias Esken <muelleimer2004nospam@usenetverwaltung.org> wrote in message news:<c6mnif.260.1@usenet.esken.de>...
> Kevin Thorpe wrote: > > > This must come before any output at all: > > header('Location: main.php'); > > Of course, according to the RFCs, you have to add the domain name: > > header('Location: http://www.example.com/main.php'); > exit; > > Matthias 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 ;-) |
|
|||
|
Joe Randstein wrote:
> 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? Usually I tackle this by using a global settings.php.inc-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.inc 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.inc'); header('location: ' . $config["domain"] . $config["path_root"] . 'myscript.php'); HTH -- Suni |
|
|||
|
In article <4091080e$0$24734$39db0f71@news.song.fi>, Juha Suni wrote:
> Joe Randstein wrote: >> 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? > > Usually I tackle this by using a global settings.php.inc-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.inc 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.inc'); > header('location: ' . $config["domain"] . $config["path_root"] . > 'myscript.php'); If the location of that settings file changes, you still have to update all those files. In this case auto_prepend can be handy ;) -- http://home.mysth.be/~timvw |
|
|||
|
In article <c6rb3t$f3i2c$2@ID-188825.news.uni-berlin.de>,
Tim Van Wassenhove <euki@pi.be> wrote: > > So in settings.php.inc 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.inc'); > > header('location: ' . $config["domain"] . $config["path_root"] . > > 'myscript.php'); > > If the location of that settings file changes, you still have to update > all those files. In this case auto_prepend can be handy ;) 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" = @. |
|
|||
|
In article <devnull-A7BB3E.18462129042004@news1.news.xs4all.nl>, Jan Pieter Kunst wrote:
> In article <c6rb3t$f3i2c$2@ID-188825.news.uni-berlin.de>, > Tim Van Wassenhove <euki@pi.be> wrote: > >> > So in settings.php.inc 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.inc'); >> > header('location: ' . $config["domain"] . $config["path_root"] . >> > 'myscript.php'); >> >> If the location of that settings file changes, you still have to update >> all those files. In this case auto_prepend can be handy ;) > > 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. 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. |