Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   PHP (https://www.askmehelpdesk.com/forumdisplay.php?f=454)
-   -   Authentication in PHP (https://www.askmehelpdesk.com/showthread.php?t=295729)

  • Dec 25, 2008, 09:01 PM
    leenakrishna
    Authentication in PHP
    Hai,

    I'am ne wto PHP and I am doing a project.I want a login,in such a way that each one entered should be identified (i.e,whether the entered person is a client or admin )and they should be directed to their respective pages.What is the code I have to use.anybody there to help me...
  • May 4, 2009, 05:04 AM
    shihan

    I write this script and I also create the database.But it show an error.why

    <?php
    $con=mysql_connect("localhost","root");
    if(!$con){
    die('could not connect:'.mysql_error());
    }

    mysql_select_db("project",$con);

    $sql="INSERT INTO customer(firstname)
    VALUES ('$_POST[firstname]'';')";

    if(!mysql_query($sql,$con));
    {
    die('Error.'.mysql_error());
    }

    echo"1 record added";
    mysql_close($con)

    ?>
  • May 8, 2009, 10:22 PM
    leenakrishna
    Try this:

    First one is the html form:
    <form action="newphp.php" method="post">
    Firstname: <input type="text" name="firstname" />
    Lastname: <input type="text" name="lastname" />
    Age: <input type="text" name="age" />
    <input type="submit" />
    </form>

    Following is the php code:"newphp.php".Here I have used my own database and table.Just change it.

    <?php

    $con = mysql_connect("localhost","root","");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }mysql_select_db("hai", $con);
    $sql="INSERT INTO persons (FirstName)
    VALUES('$_POST[firstname]')";
    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    echo "1 record added";mysql_close($con)




    ?>
  • Jul 21, 2009, 07:49 PM
    slapshot_oi
    Quote:

    Originally Posted by leenakrishna View Post
    hai,

    I'am ne wto PHP and iam doing a project.I want a login,in such a way that each one entered should be identified (i.e,whether the entered person is a client or admin )and they should be directed to their respective pages.What is the code i have to use.anybody there to help me.....

    I realize this is an old thread and you may have already found the answer, but the most general answer I can give--because I'm not going to code it for you--is you have to use sessions with the $_SESSION array. To identify the group ID of the user, you have to use a database.

    You'll first have to check if a session is already started, and if not, prompt the user to login and check their input against the corresponding record in the database. If it chechks out, start a session with session_start()

    The easiset way to do all of this is use RAD tool. This code is so commonly used, you'd just be reinventing the wheel if you were to write it on your own. I use CodeCharge Studio, they have templates that do all of the generic stuff for you, you just add the special code where need be. And if you can't do that, search Google Code for snippets, I guarantee you'll find what you're looking for.

  • All times are GMT -7. The time now is 09:32 AM.