RE: [PHP] redirecting after login
| From: | César Aracena | Date: | Tue, 23 Jul 2002 04:52:11 +0000 |
| Subject: | RE: [PHP] redirecting after login | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-109029@lists.php.net to get a copy of this message | ||
I forgot to tell you: This snippet is supposed to go at the very top of
the login page (right after the <? Tag). Like this, you can easily
modify whatever login method you are using... just remember to add that
extra "LEVEL" field to your user's database and/or modify the snippet
accordingly.
Cheers, C.
> -----Original Message-----
> From: César Aracena [mailto:icaam@icaam.com.ar]
> Sent: Tuesday, July 23, 2002 1:45 AM
> To: 'Tim Thorburn'; php-general@lists.php.net
> Subject: RE: [PHP] redirecting after login
>
> Hi. Since I haven't used meta tags for years now (don't like them:) I
> can't help you there, but instead, here's a typical login/redirect PHP
> page of mine. As you can see, it doesn't matter if the login form is
at
> the bottom of the page, or even if it's after an included header file
as
> long the form points to $PHP_SELF:
>
> session_start();
>
> if ($username && $pass)
> {
> $db_conn = mysql_connect("localhost", "admin", "password");
>
> mysql_select_db("db_name", $db_conn);
>
> $query = "SELECT * FROM table_name WHERE username = '$username'
> AND password = password('$pass')";
>
> $result = mysql_query($query, $db_conn);
>
> if (mysql_num_rows($result) > 0)
> {
> $row = mysql_fetch_array($result);
> if ($row['devlevel'] == '2')
> {
> $valid_admin = $row['devfirst'];
> session_register("valid_admin");
> header("Location: ../admin/index.php");
> exit;
> }
> else if ($row['devlevel'] == '1')
> {
> $valid_user = $row['devid'];
> session_register("valid_user");
> header("Location: index.php");
> exit;
> }
> else
> {
> header("Location: ../jumpto.php?fetch=devent");
> exit;
> }
> }
> else
> {
> header("Location: ../jumpto.php?fetch=devent");
> exit;
> }
> }
> else
> {
> header("Location: ../jumpto.php?fetch=devent");
> exit;
> }
>
> Like this, I can diferenciate the users by fetching the "devlevel"
> number from the same DB that the user was authenticated from.
>
> HTH, C.
>
>
> > -----Original Message-----
> > From: Tim Thorburn [mailto:immortal@nwconx.net]
> > Sent: Tuesday, July 23, 2002 1:00 AM
> > To: php-general@lists.php.net
> > Subject: [PHP] redirecting after login
> >
> > Hi,
> >
> > A site I'm working on requires a login screen where various
> individuals
> > will log into the site and add information for their various
> > departments. Rather than setup a different script for each
> department, I
> > was hoping to create one script that would either accept or deny a
> login
> > based on the username/password stored in a database, then based on
the
> > username/password - redirect the individuals browser to a URL.
> >
> > I've got the login part working perfectly, and I can turn the URL
into
> a
> > link on the page, but I'd rather have the script just automatically
> > forward
> > the person to the page they're login gives them access to.
> >
> > I've tried using header(), but since the redirection takes place
about
> > mid-script, it doesn't work. I've also tried using <meta> tag
> redirects,
> > but those don't seem to accept the PHP/MySQL combo.
> >
> > Any ideas?
> >
> > Thanks
> > -Tim
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php