Jump to content

[SOLVED] SESSION HELP


bhavin12300

Recommended Posts

HI

I AM LITTLE NEW TO PHP

I AM HAVING SOME PROBLEM REGARDING THE SESSION IN PHP.

HERE IS MY PROBLEM.

 

AS LIKE ALL WEBSITE MY AIM IS TO ASK FOR ID AND PASSWORD FROM USER AND AFTER CHECKING THE ID AND PASSWORD I CREATE ONE SESSION AND STORE USER ID IN ONE VARIABLE TO REFER TO OTHER PAGE.

AND I AM REDIRECTING TO HOME PAGE AFTER SETTING SESSION AND AT THAT  HOME PAGE I AM UNABLE TO RETRIEVE THAT SESSION VARIABLE DATA.

MEANS MY SESSION IS NOT PERSISTENCE.

 

CAN  ANYONE HELP ME

 

WAITING FOR REPLY.

IF CODE REQUIRE ASK ME

 

 

I AM DOING THIS ON SERVER LOT LOCAL SERVER

 

Link to comment
https://forums.phpfreaks.com/topic/59058-solved-session-help/
Share on other sites

yes you can c code.i did start my session

first code is where i am setting my session.

and second is where i am retrieving.

 

1)

<?php

    $mydb=mysql_connect('mysql3.freehostia.com:3306','bhapit_database','canuseeme2');


	if(mysql_select_db('bhapit_database',$mydb))

            {

      	    }
        else
    {
	echo("databse not connected");
    }

  
   $userid = $_POST['userid'];
   $password = $_POST['password'];
   $submit="select * from user where userid like '$userid' and password like '$password'";
   $result=mysql_query($submit);
       $num=1;
     while($row=mysql_fetch_array($result))
	{
		  session_start();
	  $SESSION['username'] =$userid;
	  mysql_close($mydb);
	   header("Location: index.php");


		}
   

   
?>
<html>
<head>
</head>
<body>
<table  >
<tr><td  > <?php include("header.php"); ?></td></tr>
<tr><td  > <?php include("nevigator.php"); ?></td></tr>
<tr>
<td>Registration Done Sucessfully.<br>Login Here<?php include("login_user.php"); ?> </td>

</tr>
<tr><td> <?php include("footer.php"); ?></td></tr>
<table>

</body>
</html>

 

here is the code for session retrival

<?php
session_start(); 


$MYNAME=$_SESSION['USERNAME']; //retrieve data
echo $MYNAME;
?>

<html>
<head>
</head>
<body>
<table  >
<tr><td  > <?php include("header.php"); ?></td></tr>
<?php
  if($MYNAME=="")
     {
     }
  else
   {
    echo("<font size=3><b>WELCOME!!");
    echo $MYNAME;
    echo("     <a href=>Sign Out</a></b></font>");
   }
?>

<tr><td  > <?php include("nevigator.php"); ?></td></tr>
<tr>

<td> <?php include("center.php"); ?> </td>

</tr>
<tr><td> <?php include("footer.php"); ?></td></tr>
<table>

</body>
</html>

 

ANY INFORMATION?

Link to comment
https://forums.phpfreaks.com/topic/59058-solved-session-help/#findComment-293179
Share on other sites

no sir

its still same i am not getting answer here is the update code

<?php
session_start(); 


$MYNAME=$_SESSION['username']; //retrieve data
echo $MYNAME;
?>

<html>
<head>
</head>
<body>
<table  >
<tr><td  > <?php include("header.php"); ?></td></tr>
<?php
  if($MYNAME=="")
     {
     }
  else
   {
    echo("<font size=3><b>WELCOME!!");
    echo $MYNAME;
    echo("     <a href=>Sign Out</a></b></font>");
   }
?>

<tr><td  > <?php include("nevigator.php"); ?></td></tr>
<tr>

<td> <?php include("center.php"); ?> </td>

</tr>
<tr><td> <?php include("counter_footer.php"); ?></td></tr>
<table>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/59058-solved-session-help/#findComment-293201
Share on other sites

yes you can c code.i did start my session

first code is where i am setting my session.

and second is where i am retrieving.

 

1)

<?php

    $mydb=mysql_connect('mysql3.freehostia.com:3306','bhapit_database',' ');


	if(mysql_select_db('bhapit_database',$mydb))

            {

      	    }
        else
    {
	echo("databse not connected");
    }

  
   $userid = $_POST['userid'];
   $password = $_POST['password'];
   $submit="select * from user where userid like '$userid' and password like '$password'";
   $result=mysql_query($submit);
       $num=1;
     while($row=mysql_fetch_array($result))
	{
		  session_start();
	  $SESSION['username'] =$userid;
	  mysql_close($mydb);
	   header("Location: index.php");


		}
   

   
?>
<html>
<head>
</head>
<body>
<table  >
<tr><td  > <?php include("header.php"); ?></td></tr>
<tr><td  > <?php include("nevigator.php"); ?></td></tr>
<tr>
<td>Registration Done Sucessfully.<br>Login Here<?php include("login_user.php"); ?> </td>

</tr>
<tr><td> <?php include("footer.php"); ?></td></tr>
<table>

</body>
</html>

 

here is the code for session retrival

<?php
session_start(); 


$MYNAME=$_SESSION['USERNAME']; //retrieve data
echo $MYNAME;
?>

<html>
<head>
</head>
<body>
<table  >
<tr><td  > <?php include("header.php"); ?></td></tr>
<?php
  if($MYNAME=="")
     {
     }
  else
   {
    echo("<font size=3><b>WELCOME!!");
    echo $MYNAME;
    echo("     <a href=>Sign Out</a></b></font>");
   }
?>

<tr><td  > <?php include("nevigator.php"); ?></td></tr>
<tr>

<td> <?php include("center.php"); ?> </td>

</tr>
<tr><td> <?php include("footer.php"); ?></td></tr>
<table>

</body>
</html>

 

ANY INFORMATION?

Link to comment
https://forums.phpfreaks.com/topic/59058-solved-session-help/#findComment-293246
Share on other sites

yes you can c code.i did start my session

first code is where i am setting my session.

and second is where i am retrieving.

 

1)

<?php

    $mydb=mysql_connect('mysql3.freehostia.com:3306','bhapit_database',' ');


	if(mysql_select_db('bhapit_database',$mydb))

            {

      	    }
        else
    {
	echo("databse not connected");
    }

  
   $userid = $_POST['userid'];
   $password = $_POST['password'];
   $submit="select * from user where userid like '$userid' and password like '$password'";
   $result=mysql_query($submit);
       $num=1;
     while($row=mysql_fetch_array($result))
	{
		  session_start();
	  $SESSION['username'] =$userid;
	  mysql_close($mydb);
	   header("Location: index.php");


		}
   

   
?>
<html>
<head>
</head>
<body>
<table  >
<tr><td  > <?php include("header.php"); ?></td></tr>
<tr><td  > <?php include("nevigator.php"); ?></td></tr>
<tr>
<td>Registration Done Sucessfully.<br>Login Here<?php include("login_user.php"); ?> </td>

</tr>
<tr><td> <?php include("footer.php"); ?></td></tr>
<table>

</body>
</html>

 

here is the code for session retrival

<?php
session_start(); 


$MYNAME=$_SESSION['USERNAME']; //retrieve data
echo $MYNAME;
?>

<html>
<head>
</head>
<body>
<table  >
<tr><td  > <?php include("header.php"); ?></td></tr>
<?php
  if($MYNAME=="")
     {
     }
  else
   {
    echo("<font size=3><b>WELCOME!!");
    echo $MYNAME;
    echo("     <a href=>Sign Out</a></b></font>");
   }
?>

<tr><td  > <?php include("nevigator.php"); ?></td></tr>
<tr>

<td> <?php include("center.php"); ?> </td>

</tr>
<tr><td> <?php include("footer.php"); ?></td></tr>
<table>

</body>
</html>

 

ANY INFORMATION?

Link to comment
https://forums.phpfreaks.com/topic/59058-solved-session-help/#findComment-293247
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.