www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: Redirect log in page

  1. #1
    Join Date
    Jun 2013
    Posts
    8

    Redirect log in page

    To whom is this concern i have problem with log in page i am trying to redirect page on my index.php page but i couldn't ,this code i copied from your website.Right here when i going from log in page to success page i getting blank page.

    I think is problem here echo "<form action=\"?op=login\" method=\"POST\">"; because when i am trying to preview in browser on the end of the domain i have this \"?op=login\"










    <?php
    session_start();
    // dBase file
    include "dbConfig.php";
    if ($_GET["op"] == "login")
    {
    if (!$_POST["username"] || !$_POST["password"])
    {
    die("You need to provide a username and password.");
    }
    // Create query
    $q = "SELECT * FROM `dbUsers` "
    ."WHERE `username`='".$_POST["username"]."' "
    ."AND `password`=PASSWORD('".$_POST["password"]."') "
    ."LIMIT 1";
    // Run query
    $r = mysql_query($q);
    if ( $obj = @mysql_fetch_object($r) )
    {
    // Login good, create session variables
    $_SESSION["valid_id"] = $obj->id;
    $_SESSION["valid_user"] = $_POST["username"];
    $_SESSION["valid_time"] = time();
    // Redirect to member page
    Header("Location: members.php");
    }
    else
    {
    // Login not successful
    die("Sorry, could not log you in. Wrong login information.");
    }
    }
    else
    {
    //If all went right the Web form appears and users can log in
    echo "<form action=\"?op=login\" method=\"POST\">";
    echo "Username: <input name=\"username\" size=\"15\">";
    echo "Password: <input type=\"password\" name=\"password\" size=\"8\">";
    echo "<input type=\"submit\" value=\"Login\">";
    echo "</form>";
    }
    ?>




  2. #2
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    Ya i really wish you would of typed your problem a little better your text is a little confusing. but im gonna try to help. first of all i would not of set this up the way you have it set up.

    1. you can use get and post you need to pick one of the other when gathering the information. so if someone is trying to log in with a for and the action is post but then in your authentication process you are using GET its not gonna work right.

    2. the reason you see OP=login in the URL is because when you use the GET method it post the information to the URL.

    So to start with... cause I am not to clear on where the page is directing you when you login. you did not specify that to clearly. it sounds like it is just posing the GET value to the URL. Change the GET to POST and see if that fixes your problem. If not I think we might have to rewrite your script. Ill post one to give you an example.

    I really advise against having forms in pages posting to them selves. for some reason I have noticed a lot of people posting questions where their forms dont show up or behave correctly and when you make the action method in the form point to another page and put the php in that page everything seems to work fine. I am not sure why that is maybe someone with more experience then me would not mind explaining it.

    Please retype your question and be more clear about what your seeing before you execute anything. and then what your seeing after. such as if the page redirects what does the URL say?

  3. #3
    Join Date
    Jun 2013
    Posts
    8

    Redirect page

    Quote Originally Posted by Nicholas Diaz View Post
    Ya i really wish you would of typed your problem a little better your text is a little confusing. but im gonna try to help. first of all i would not of set this up the way you have it set up.

    1. you can use get and post you need to pick one of the other when gathering the information. so if someone is trying to log in with a for and the action is post but then in your authentication process you are using GET its not gonna work right.

    2. the reason you see OP=login in the URL is because when you use the GET method it post the information to the URL.

    So to start with... cause I am not to clear on where the page is directing you when you login. you did not specify that to clearly. it sounds like it is just posing the GET value to the URL. Change the GET to POST and see if that fixes your problem. If not I think we might have to rewrite your script. Ill post one to give you an example.

    I really advise against having forms in pages posting to them selves. for some reason I have noticed a lot of people posting questions where their forms dont show up or behave correctly and when you make the action method in the form point to another page and put the php in that page everything seems to work fine. I am not sure why that is maybe someone with more experience then me would not mind explaining it.

    Please retype your question and be more clear about what your seeing before you execute anything. and then what your seeing after. such as if the page redirects what does the URL say?
















    This is where is orginal code //www.webdeveloper.com/forum/showthread.php?265799-Login-amp-Registration-form-with-profile





    http://www.webdesigngroup1999.com/my...n/register.php this is my register page after i pass register page, i am getting blank page



    www.webdesigngroup1999.com/mysqladmin/login.php after i pass log in page i am getting blank page






    My problem is i made index.page with text and i can redirect to that page.(index.page)

  4. #4
    Join Date
    Jun 2013
    Posts
    8
    Quote Originally Posted by Ado View Post
    This is where is orginal code //www.webdeveloper.com/forum/showthread.php?265799-Login-amp-Registration-form-with-profile





    http://www.webdesigngroup1999.com/my...n/register.php this is my register page after i pass register page, i am getting blank page



    www.webdesigngroup1999.com/mysqladmin/login.php after i pass log in page i am getting blank page






    My problem is i made index.page with text and i can not redirect to that page.(index.page)
    [/QUOTE]

  5. #5
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    ok so when someone logs in you want to send them back to the index page but if there is a session start you want them to have access to hidden information?

  6. #6
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    ok do this...

    I need you to post your index page. your login script. and do it with code tags so its easy for me to read. so type [code ] with out the space and close it with [/code ] two seperate scripts one is the full index page and one is the login script.

    unless they are on the same page if so just post what you have the way you have it in the code tags

  7. #7
    Join Date
    Jun 2013
    Posts
    8

    Redirect page

    Quote Originally Posted by Nicholas Diaz View Post
    ok do this...

    I need you to post your index page. your login script. and do it with code tags so its easy for me to read. so type [code ] with out the space and close it with [/code ] two seperate scripts one is the full index page and one is the login script.

    unless they are on the same page if so just post what you have the way you have it in the code tags






    This my code log in page
    [code ]

    <?php
    session_start();
    // dBase file
    include "dbConfig.php";
    if ($_GET["op"] == "login")
    {
    if (!$_POST["username"] || !$_POST["password"])
    {
    die("You need to provide a username and password.");
    }
    // Create query
    $q = "SELECT * FROM `dbUsers` "
    ."WHERE `username`='".$_POST["username"]."' "
    ."AND `password`=PASSWORD('".$_POST["password"]."') "
    ."LIMIT 1";
    // Run query
    $r = mysql_query($q);
    if ( $obj = @mysql_fetch_object($r) )
    {
    // Login good, create session variables
    $_SESSION["valid_id"] = $obj->id;
    $_SESSION["valid_user"] = $_POST["username"];
    $_SESSION["valid_time"] = time();
    // Redirect to member page
    Header("Location: members.php");
    }
    else
    {
    // Login not successful
    die("Sorry, could not log you in. Wrong login information.");
    }
    }
    else
    {
    //If all went right the Web form appears and users can log in
    echo "<form action=\"?op=login\" method=\"POST\">";
    echo "Username: <input name=\"username\" size=\"15\">";
    echo "Password: <input type=\"password\" name=\"password\" size=\"8\">";
    echo "<input type=\"submit\" value=\"Login\">";
    echo "</form>";
    }
    ?>

    [/code ]




    This is my index.php page
    [code ]

    <?php ?>


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    testtttttttttttttt
    <body>
    </body>
    </html>



    [/code ]

  8. #8
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    dont put spaces in the code brackets... is this all the code?
    is this your index page?

  9. #9
    Join Date
    Jun 2013
    Posts
    8

    Redirect page

    Quote Originally Posted by Nicholas Diaz View Post
    dont put spaces in the code brackets... is this all the code?
    is this your index page?


    Yes that is it.

  10. #10
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    i need you to answer my question... so when someone goes to your webpage you want them to immediatly be prompted to login? right? and once they login then they can see the information on the index page? so as of now it would be i go to your site. i log in then it shows me test on the page? is this correct?

  11. #11
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    or do youw ant them to go to members.php? cause you have them going to members.php right now which u have not showed me that file yet

  12. #12
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    did you set up the page members.php?

  13. #13
    Join Date
    Jun 2013
    Posts
    8
    Yes

  14. #14
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    log in and copy your url and paste it in to here for me to see

  15. #15
    Join Date
    Jun 2013
    Posts
    8

    Redirect page

    Quote Originally Posted by Nicholas Diaz View Post
    log in and copy your url and paste it in to here for me to see
    http://www.webdesigngroup1999.com/my...n.php?op=login

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles