how to set session in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thirusvga
    New Member
    • Feb 2008
    • 9

    how to set session in php

    hi sir..
    I write a login program in php....session function where i write in that program and session stop....
    that phph program is successsfull execute....that codings are...in loginslide.html program

    <html>
    <head>
    <title>login</title>
    <body>
    <form method="post" action="loginsl ide.php">
    <center>
    <table border="0" bgcolor="#CCCCF F" cellspacing="1" cellpadding="3" width="287">
    <tr>
    <td align="left" colspan="2" width="275"><b> <font size="5" color="#000080" >Login</font></b></td>
    </tr>
    <tr>
    <td align="right" width="81"><b>< font color="#000080" >User
    Name:</font></b></td>
    <td width="184">
    <input type="text" input name="user">
    </td>
    </tr>
    <tr>
    <td align="right" width="81"><b>< font color="#000080" >Password:</font></b></td>
    <td width="184">
    <input type="password" input name="pass">
    </td>
    </tr>
    <tr>
    <td colspan="2" align="center" width="275"><in put type="submit" input value="Login"></td>
    </tr>
    </table>
    </center>
    </form>
    </body>
    </html>

    login slide.html program codings are...,,
    <?php
    $user=$_POST['user'];
    $pass=$_POST['pass'];
    $conn = mysql_connect(" localhost","roo t","") or die("could not connect server");
    $db = mysql_select_db ("thiru",$co nn) or die("could not connect database");
    $query= "select * from reg";
    $res = mysql_query($qu ery) or die("query failed" . mysql_error());
    $num_rows=mysql _num_rows($res) ;
    //echo $num_rows;
    while($rr=mysql _fetch_array($r es))
    {
    if(ereg($user,$ rr[2]))
    {
    if(ereg($pass,$ rr[3]))
    {
    $flag=true;
    }
    }
    }
    if($flag==true)
    {
    echo"u r in new page";
    }
    else
    {
    echo"userid and password mismatch";
    }
    mysql_close($co nn);
    ?>

    please where i use session function in that program...
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    I suggest you take a look at a session tutorial

    Regards.

    Comment

    • TheServant
      Recognized Expert Top Contributor
      • Feb 2008
      • 1168

      #3
      And use CODE tags in your post to go around code! (have a look in the post bar where you can make text bold, italic etc)

      Comment

      • passion4code
        New Member
        • Mar 2008
        • 4

        #4
        Basic Guide to PHP Sessions:

        Rule 1: Don't forget session_start() ;!!!

        This is very important to use in the beginning every one of your pages that you want to carry the session to, because otherwise none of your $_SESSION superglobals will be accessible.

        That's....about it. All of your variables held within $_SESSION can be most data types. Associative arrays, arrays, objects, strings, integers, etc....so you could have
        Code:
         $_SESSION['userid'] = $_POST['user'];
        When you want to "logout" you would unset the session variable
        Code:
         unset($_SESSION['userid']);

        Comment

        Working...