User Login to Redirect using PHP

Ask a Question related to Macromedia Dreamweaver, Design and Development.

  1. #1

    Default User Login to Redirect using PHP

    I've read many posts about redirecting a user by specifying the directin url in the database, but have had very little luck. I'm using Dreamweaver's user authentication login extensions, and telling the "if successful login, go to page:" to point to the redirect field in the database by clicking browse..data sources...redirect(recordset value). This seems to work only for the first user in the database, ie. any other user is verified, but still directed to the first users redirect page. I have included the code to view(nothing fancy). Please be detailed in explaination, being I'm not that handy with coding and general "do this and do that" talk.

    Thank you to anyone who might be able to help me.


    <?php require_once('Connections/PasswordDB.php'); ?>
    <?php

    mysql_select_db($database_PasswordDB, $PasswordDB);

    $query_Recordset1 = "SELECT * FROM Trial";
    $Recordset1 = mysql_query($query_Recordset1, $PasswordDB) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    ?>

    <?php

    // *** Validate request to log in to this site.

    session_start();

    $loginFormAction = $HTTP_SERVER_VARS['PHP_SELF'];

    if (isset($accesscheck)) {$GLOBALS['PrevUrl'] = $accesscheck;
    session_register('PrevUrl');}

    if (isset($HTTP_POST_VARS['textfield'])) {$loginUsername=$HTTP_POST_VARS['textfield'];
    $password=$HTTP_POST_VARS['textfield2'];

    $MM_fldUserAuthorization = "";
    $MM_redirectLoginSuccess = $row_Recordset1['redirect'];
    $MM_redirectLoginFailed = "/index.html";
    $MM_redirecttoReferrer = false;

    mysql_select_db($database_PasswordDB, $PasswordDB);

    $LoginRS__query=sprintf("SELECT username, password FROM Trial WHERE username='%s' AND password='%s'", get_magic_quotes_gpc()
    ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password
    : addslashes($password));

    $LoginRS = mysql_query($LoginRS__query, $PasswordDB) or die(mysql_error());

    $loginFoundUser = mysql_num_rows($LoginRS);

    if ($loginFoundUser) { $loginStrGroup = "";

    //declare two session variables and assign them

    $GLOBALS['MM_Username'] = $loginUsername;
    $GLOBALS['MM_UserGroup'] = $loginStrGroup;

    //register the session variables

    session_register("MM_Username");
    session_register("MM_UserGroup");
    if (isset($HTTP_SESSION_VARS['PrevUrl']) && false) { $MM_redirectLoginSuccess = $HTTP_SESSION_VARS['PrevUrl'];
    } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } ?>



    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <table width="585" border="0" cellpadding="0" cellspacing="0">

    <!--DWLayoutTable-->
    <tr>
    <td width="585" height="178" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    </tr>
    <tr>
    <td height="261" valign="top"><form ACTION="<?php echo $loginFormAction; ?>" name="form1" method="POST">

    <p>
    <input type="text" name="textfield">
    </p>
    <p>
    <input type="text" name="textfield2">
    </p>
    <p>
    <input type="submit" name="Submit" value="Submit">
    </p>
    </form></td>
    </tr>
    </table>
    </body>
    </html>
    <?php
    mysql_free_result($Recordset1);
    ?>



    SpeedRacer21 webforumsuser@macromedia.com Guest

  2. Similar Questions and Discussions

    1. Login Redirect
      Hi, all I have this login script that calls on itself to authenticate the username and the password. It redisplays the login page if there is an...
    2. redirect to guest if first redirect is doesnt work for a user
      Hi all, I was wondering if anyone could help me solve a problem Once a user hits a certain webpage ..I try to redirect them to another using...
    3. Cookie not set after login and redirect
      Hello I have setup a forms authentication login page and use custom principal and identity. When authenticate everything goes well. But when I set...
    4. How to set redirect default on login?
      Sorry, FormsAuthentication is hard set to "default.aspx" when doing the RedirectFromLoginPage and/or GetRedirectUrl Just execute SetAuthCookie...
    5. Login User and Redirect to a specific page - help required
      I'm using ASP/Access 2000. This is what I would like to do. A site has a limited number of users - User Bert logs in and assuming gets thru...
  3. #2

    Default Re: User Login to Redirect using PHP

    Hi SoeedRacer21,

    Try doing this:

    Go back to the original code inserted by the login server behavior. You
    don't need to create another recordset to get the page that you should
    redirect to. That information can be pulled from the recordset that checks
    the username/password. Add 'redirect' to the list of fields being retrieved
    "username,password,redirect".

    add this code below "$GLOBALS['MM_UserGroup'] = $loginStrGroup;"

    $MM_redirectLoginSuccess = mysql_result($LoginRS,0,'redirect');

    Hope this helps
    Jaybee Reyes
    Macromedia Technical Support


    JREYES-MMTS Guest

  4. #3

    Default Re: User Login to Redirect using PHP

    Thank you so much for your help. This worked perfectly! Do I need to add a behavior to the individual user pages to keep unautherized people from viewing this page by directly typing it in to the title bar?

    I am very grateful to you. You don't know how much headache this has caused me. Thank you.


    SpeedRacer21 webforumsuser@macromedia.com Guest

  5. #4

    Default Re: User Login to Redirect using PHP

    Hi SpeedRacer21,

    Glad that worked for you. As for the page restrictions, I would recommend
    adding that. But from what you are describing, this is not something that
    can be handled by the restrict access behavior. The only way I can see this
    working with the behavior is if you use user level permissions. You will
    have to create a user level for each user. A bit tedious but it should work.

    Regards,
    Jaybee


    JREYES-MMTS Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139