Reply to Re: help needed - passing values between two loads of the same page

Your name:

Reply:


Posted by Joseph S. on 10/09/39 11:28

> littlefire wrote:
> >
> > The two major causes of session failure:
> > 1. The two pages don't reside on the same domain
> > 2. One of the two pages does not call session_start() - this needs to be
> > done on every single page where a session var is used

> Those are two major causes. I wouldn't say they are THE two major causes.
>
> For instance - calling session_start() after some output has been
> written. Not having write access to the temporary directory. Incorrect
> session values in the php.ini file. And several more common errors.
>
> The problem is - which is it?

In my case it was no.2 above, sesion_start() absent.

Also, I discovered that the PHP _interpreter_ goes line by line in
displaying as well as processing. So, if you want to see whether a call
to the file is the first ever call or a subsequent refresh (or form
submittal for that matter), one way to do that is to create a dummy
session variable $_SESSION['a']=1 as the last line of the php file, and
in the lines above, before your actual processing begins, check whether
$_SESSION['a'] is set. If it the first ever call to the page, it will
not be set depending on which you can take some actions(keeping fields
empty etc.). If it is a second call via a refresh or a form submittal,
you will have $_SESSION['a'] set.

Little tricks often are helpful.
(a.php)
<?php
/* Keeping the look of the output HTML the same between
multiple calls to the same page */
session_start();
?>
<html>
<head>
<title>Title</title>
</head>
<body>
<form name="taxform" action="a.php" method="POST" >
<center>
Enter Gross<br/>
<input type="text"
name="gross"
value="<?php if(isset($_SESSION['a'])){echo $_POST['gross'];}?>"

/>
<br/>
<input type="submit"
name="Calcbtn"
value="Calculate Tax"
/>
<br/>

<?php
/* doing the calculation here */
$gross = (float)$_POST["gross"];
$tax = 0;
$rate = 0.3;
$tax = $gross*$rate;
?>
<br />
Tax<br/>
<?php echo $_SESSION['a'] ?><br/>
<input type="text"
name="tax"
value="<?php if(isset($_SESSION['a'])){echo $tax;} ?>"
/>
<br/>
</center>
</form>
</body>
</html>
<?php $_SESSION['a'] = 1; ?>

Regards,
Joseph S.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация