Forwarding to next php script on correct input?

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


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-27-2004
Joe Randstein
 
Posts: n/a
Default 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!
Reply With Quote
  #2 (permalink)  
Old 04-27-2004
Kevin Thorpe
 
Posts: n/a
Default Re: Forwarding to next php script on correct input?

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');
Reply With Quote
  #3 (permalink)  
Old 04-27-2004
Matthias Esken
 
Posts: n/a
Default Re: Forwarding to next php script on correct input?

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
Reply With Quote
  #4 (permalink)  
Old 04-28-2004
Garp
 
Posts: n/a
Default Re: Forwarding to next php script on correct input?


"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




Reply With Quote
  #5 (permalink)  
Old 04-28-2004
Joe Randstein
 
Posts: n/a
Default Re: Forwarding to next php script on correct input?

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 ;-)
Reply With Quote
  #6 (permalink)  
Old 04-29-2004
Juha Suni
 
Posts: n/a
Default Re: Forwarding to next php script on correct input?

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

Reply With Quote
  #7 (permalink)  
Old 04-29-2004
Tim Van Wassenhove
 
Posts: n/a
Default Re: Forwarding to next php script on correct input?

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
Reply With Quote
  #8 (permalink)  
Old 04-29-2004
Jan Pieter Kunst
 
Posts: n/a
Default 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:

> > 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" = @.
Reply With Quote
  #9 (permalink)  
Old 04-29-2004
Tim Van Wassenhove
 
Posts: n/a
Default Re: Forwarding to next php script on correct input?

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.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:47 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0