Page 1 of 3

question about session

Posted: Thu Oct 27, 2005 3:12 pm
by rajan
is is possible that session value will have to be null without making it null in many post of same form. i did not understand why my session value is null in previos post.

Posted: Thu Oct 27, 2005 3:44 pm
by Burrito
huh?

d11wtq | Rgr that :?

Posted: Thu Oct 27, 2005 4:03 pm
by rajan
i want to ask is it possible that session variable will null without making it null.

Posted: Thu Oct 27, 2005 4:06 pm
by Burrito
not that I know of.

try echoing out the value that you're trying to set it to and see if there's something there. I've never heard of any auto nulling session value voodoo.

Posted: Thu Oct 27, 2005 4:30 pm
by rajan
but when i used this program in my local server, it is running good but when i run it on website, it has problem with session variable lost. the progrme is my last post in this forum.

Posted: Thu Oct 27, 2005 4:32 pm
by Burrito
it's likely that the session settings on the web server are different than they are on your local machine.

do sessions work at all?

Posted: Thu Oct 27, 2005 4:47 pm
by rajan
sessions is working well in my all progrm except one i had asked u

Posted: Thu Oct 27, 2005 4:49 pm
by Burrito
well post some code then...I really can't help much w/o seeing the problem.

Posted: Thu Oct 27, 2005 4:59 pm
by rajan

Code: Select all

<?php //for only showing on forum
<? session_start(); ?>
<? include_once('../include/mysql_connect.php'); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
a:link {
	color: #FFFFFF;
}
a:visited {
	color: #FFFFFF;
}
a:hover {
	color: #FFFFFF;
}
a:active {
	color: #FFFFFF;
}
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12;
	font-weight: bold;
}
-->
</style></head>
<body>
<?
if(isset($_GET['finaltime']))
{
/* echo "\n accountype".$_GET['accountype'];
echo "<br>Time Left".$_GET['minute'];
echo "<br>Start Time".$_GET['starttime']; */
$quantity1=$_GET['quantity1'];
$acc1=$_GET['accountype']; 
$finalt=$_GET['minute']; //final time after account is used 
$startt=$_GET['starttime']; //final time after account is start
$usedt=$finalt-$startt;
	if($usedt<=10) //if time used is less the 10 minute
		{
		$updatet=$finalt-10; //final time left
		}
		else
		{
		$updatet=$finalt;
		}
			if($updatet==0)
			{
				if($quantity1>1)
				{
				$sql="update acinfo set quantity=quantity-1 where accounttype='$acc1' and username='$_SESSION[email]'";
				}
				else
				{
				$sql="delete from acinfo where accounttype='$acc1' and username='$_SESSION[email]'";
				}
			}
			else
			{
			$sql="update acinfo set minute='$updatet' where accounttype='$acc1' and username='$_SESSION[email]'";
			}
			$result=mysql_query($sql) or die(mysql_error());
}

	if(isset($_POST['prosel']))
	{
	$acctype=$_POST['radiobutton'];
	$sql="select minute,quantity from acinfo where accounttype='$acctype' and username='$_SESSION[email]'";
	$result=mysql_query($sql)or die(mysql_error());
	$row=mysql_fetch_row($result)or die(mysql_error());
	$minute=$row[0];
	$quantity=$row[1];
  		if($minute==0)
  		{
			if($quantity==1)
			{
			$query="delete from acinfo where accounttype='$acctype' and username='$_SESSION[email]'";
			}
			else
			{
			$query="update acinfo set quantity=quantity-1 where accounttype='$acctype' and username='$_SESSION[email]'";
			}
			$result=mysql_query($query)or die(mysql_error());
	?>
 Account is modified </p>
      </div>
        <span class="style1">
<?
   		}
   		else
  		{
?>
        <SCRIPT LANGUAGE = "JavaScript">
		<!--
		var secs
		var timerID = null
		var timerRunning = false
		var delay = 1000


		function InitializeTimer()
		{
    // Set the length of the timer, in seconds
    secs = '<? echo $minute ?>'*60
    StartTheTimer()
		}

		function StopTheClock()
		{
    if(timerRunning)
    clearTimeout(timerID)
    timerRunning = false
var finaltime=true
alert('<? echo $acctype ?>');
var acctype='<? echo $acctype; ?>'
var starttime='<? echo $minute; ?>' 
var quantity1='<? echo $quantity ?>'
 var minute= Math.round(secs/60);
	alert(minute)
	<? echo "  location.href=\"${_SERVER['SCRIPT_NAME']}?${_SERVER['QUERY_STRING']}"
           . "&minute=\" + minute + \"&finaltime=\"+finaltime+\"&accountype=\" + acctype + \"&starttime=\"+starttime + \"&quantity1=\"+quantity1;\n"; ?>

	   
		}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
        // Here's where you put something useful that's
        // supposed to happen after the allotted time.
        // For example, you could display a message:
        alert("You have just wasted 10 seconds of your life.")
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}
InitializeTimer()
//-->
        </SCRIPT>
        <?

   }
}   
?>
        
        <table border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td class="style1">&nbsp;</td>
          </tr>
          <tr>
            <td class="style1">&nbsp;</td>
          </tr>
          <tr>
            <td class="style1">Please Enter the Email Address of Customer </td>
          </tr>
          <tr>
            <td class="style1"> </td>
          </tr>
          <tr>
            <td class="style1"></td>
          </tr>
          <tr>
            <td class="style1"><table border="0" align="center" cellpadding="0" cellspacing="0">
                <tr>
                  <td>Email Address </td>
                  <td><form name="form1" method="post" action="<? echo $_SERVER['PHP_SELF'] ?>">
                      <input type="textfield" name="txtEmail">
                  </form></td>
                </tr>
                <tr>
                  <td colspan="2" align="center">
                    <input name="hid" type="hidden" value="TRUE">
                    <input type="submit" name="emailsubmit" value="Submit">
                  </td>
                </tr>
            </table></td>
          </tr>
        </table>
        <p class="style1">&nbsp;</p>
        <span class="style1">
        <?
  	 if(isset($_POST['hid']) or isset($_SESSION['email']))
	{	
	$email=$_POST['txtEmail'];
	if(!is_null($email))
	{
	$_SESSION['email']=$email; 
	}
	
?>
       <? $_SESSION[email]="ashuraj2163@rediffmail.com"; ?>
	           <table border="1" align="center" cellpadding="1" cellspacing="1">
          <form action="<? echo $_SERVER['PHP_SELF'] ?>" method="post" class="style1">
            <tr align="center">
              <td>Account holder Id </td>
              <td><? echo $_SESSION['email'] ?>&nbsp;</td>
              <td>&nbsp;</td>
              <td><input name="stoptimer" type="button" id="stoptimer" value="stop timer" onClick="StopTheClock()"></td>
            </tr>
            <tr align="center">
              <td>Account Type </td>
              <td>Minute</td>
              <td>Quantity</td>
              <td>Select Account</td>
            </tr>
            <?  
			
	  $sql="select * from acinfo where username='$_SESSION[email]'";
	  $result=mysql_query($sql)or die("database fetch error".mysql_error());  
	  while($row=mysql_fetch_assoc($result))
	  {
	  ?>
            <tr align="center">
              <td><? echo $row['accounttype'] ?></td>
              <td><? echo $row['minute'] ?>&nbsp;of current account</td>
              <td><? echo $row['quantity'] ?>&nbsp;</td>
              <td><input name="radiobutton" type="radio" value="<? echo $row['accounttype'] ?>" checked></td>
            </tr>
            <?

   } ?>
            <tr align="center">
              <td colspan="4"><input type="submit" name="Submit" value="Submit">
              </td>
            </tr>
            <input name="prosel" type="hidden" value="TRUE">
          </form>
        </table>
        <p class="style1">&nbsp;</p>
        <?
}
?><p>&nbsp;</p>
      </TD>
    </TR>
    <TR>
      <TD height="1" width="12">&nbsp; </TD>
      <TD height="1" width="10">&nbsp; </TD>
      <TD height="1" width="5">&nbsp; </TD>
      <TD height="1" width="84">&nbsp; </TD>
      <TD height="1" width="5">&nbsp; </TD>
      <TD height="1" width="27">&nbsp; </TD>
      <TD height="1" width="15">&nbsp; </TD>
      <TD height="1" width="9">&nbsp; </TD>
      <TD height="1" width="18">&nbsp; </TD>
      <TD height="1" width="11">&nbsp; </TD>
      <TD height="1" width="9">&nbsp; </TD>
      <TD height="1" width="5">&nbsp; </TD>
      <TD height="1" width="89">&nbsp; </TD>
      <TD height="1" width="7">&nbsp; </TD>
      <TD height="1" width="88">&nbsp; </TD>
      <TD height="1" width="5">&nbsp; </TD>
      <TD height="1" width="89">&nbsp; </TD>
      <TD height="1" width="6">&nbsp; </TD>
      <TD height="1" width="88">&nbsp; </TD>
      <TD height="1" width="6">&nbsp; </TD>
      <TD height="1" width="46">&nbsp; </TD>
      <TD height="1" width="10">&nbsp; </TD>
      <TD height="1" width="33">&nbsp; </TD>
      <TD height="1" width="5">&nbsp; </TD>
      <TD height="1" width="93">&nbsp; </TD>
      <TD height="1" width="3">&nbsp; </TD>
      <TD height="1" width="11">&nbsp; </TD>
      <TD height="1" width="11">&nbsp; </TD>
      <TD height="1" width="4">&nbsp;</TD>
    </TR>
  </TABLE>
  <p align="center"><b><font face="Verdana" color="#000000" size="1">Copyright: All Right Reserved-2005. LivePCdoctor.com, Website designed & maintained by: <a href="../../wintech%20webdesign.html" target="_blank" style="text-decoration: none; color: #FFFFFF"><font color="#000000">WinTech Webdesign.</font></a></font></b></p>
</div>
</body>
</html>
// for only showing on forum ?>
Burrito: Please use

Code: Select all

tags when [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting PHP Code In The Forums[/url][/size]

Posted: Thu Oct 27, 2005 5:04 pm
by dallasx
This isn't related to the topic but if I were you, I'd put my PHP db connection file in the server's root, your account's root or somewhere behind the path of your website to hide it from the world.

Posted: Thu Oct 27, 2005 5:08 pm
by Burrito
the only session var I see being set is for 'email'.

have you tried echoing out the $email var (per my suggestion above) to see if it's populated?

if it is, where are you having the session var not being set prob? On this page, or on another page that contains your session info?

Posted: Thu Oct 27, 2005 5:34 pm
by rajan
yes it only needs for email .all other things is fetched by query.

Posted: Thu Oct 27, 2005 5:37 pm
by Burrito
ok, so did you try echoing out the $email page var?

Posted: Thu Oct 27, 2005 5:42 pm
by rajan
when i echo $email on webserver(main website ) it will not show but on my local compueter it is properly working
using phpdev as

Posted: Thu Oct 27, 2005 5:45 pm
by Burrito
ahh, so the problem is not your sessions.

how about echoing the $_POST['txtEmail'] var?

try a print_r() of your $_POST array...