Connecting Tech Pros Worldwide Forums | Help | Site Map

how to set session in php

Newbie
 
Join Date: Feb 2008
Posts: 9
#1: Apr 14 '08
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="loginslide.php">
<center>
<table border="0" bgcolor="#CCCCFF" 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"><input 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","root","") or die("could not connect server");
$db = mysql_select_db("thiru",$conn) or die("could not connect database");
$query= "select * from reg";
$res = mysql_query($query) or die("query failed" . mysql_error());
$num_rows=mysql_num_rows($res);
//echo $num_rows;
while($rr=mysql_fetch_array($res))
{
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($conn);
?>

please where i use session function in that program...

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,938
#2: Apr 14 '08

re: how to set session in php


I suggest you take a look at a session tutorial

Regards.
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#3: Apr 14 '08

re: how to set session in php


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)
Newbie
 
Join Date: Mar 2008
Posts: 4
#4: Apr 15 '08

re: how to set session in php


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
Expand|Select|Wrap|Line Numbers
  1.  $_SESSION['userid'] = $_POST['user']; 
When you want to "logout" you would unset the session variable
Expand|Select|Wrap|Line Numbers
  1.  unset($_SESSION['userid']); 
Reply