Page 1 of 1
Variables persistent through two pages
Posted: Mon Sep 05, 2005 1:00 am
by Sphenn
Hi,
I'm trying to get a variable across multiple pages, and right now it's not working. I'm trying to build a login feature where the user enters their username and password, then a TOS page appears, and then, if they accept the terms, are logged in. Right now, the problem I have is that going from the TOS page to logging them in is on a different page, and the variables that need to be checked are lost when changing pages. Is there anyone who know how I could move the variables with the page? I've considered cookies, but I've never used them, and it seems like a lot of work for such a (seemingly) simple task.
Thanks for any input
Sphenn
Posted: Mon Sep 05, 2005 1:02 am
by feyd
use session data:
session_start()
Posted: Mon Sep 05, 2005 1:05 am
by Sphenn
Doh...
It's so simple I completely missed it. Just one question...can you think of any other way to do this? Not that sessions won't cut it for me, but I've been thinking about this for so long, I'm kind of intrigued.
Thanks again,
Sphenn
Posted: Mon Sep 05, 2005 1:07 am
by josh
cookies
or if you wanted (NOT RECOMMENDED) track users by their IP
Posted: Mon Sep 05, 2005 1:09 am
by Sphenn
Hi,
Cookies was along the same line as sessions, but even harder. And IP's were definately out. Thanks for the input though. I think I'm going to give sessions a try.
Thanks
Sphenn
Posted: Mon Sep 05, 2005 1:17 am
by feyd
feasible ways:
- cookies (insecure)
- sessions (more secure)
- hidden form (insecure)
Posted: Wed Aug 29, 2007 3:10 am
by shwetha004
hi evryone!!
im kinda new to php,and im developing an online banking system.
i have the same question as Sphenn,and i have tried the solutions suggested in this thread.i am attempting to use the session method to retain a variable value across 2 forms.but somehow im not getting the desired output
i have 3 pages..the 1st page basically allows users to input their particular.the variable which i want to retain is in this page,input thru a field called nric.
the second page has some php which checks the fields.i want to retain the nric value from page 1,and pass it to page3..
in my second page,i have this code
Code: Select all
$ic= $_POST['nric'];
session_register();
session_start();
$_SESSION['ic'] =$_POST['nric'];
and in my 3rd page i have:
Code: Select all
session_start();
echo "ic num is:".$_SESSION['ic'];
so the 3rd page is supposed to display the nric that was input in the 1st page.but somehow the value is lost..im not sure why this is happening.if anyone could point out wer is my mistake,that would b great.maybe there is some error in my code...
thank you..

Posted: Thu Aug 30, 2007 2:22 am
by shwetha004
hi all...
i switched to hidden fields to achieve the same effect..
so now my page1.php has:
Code: Select all
echo '
<input type="hidden" id="icNum" name="icNum" value="<?php echo $ic;?>" > ' ;
the reason im including the form in a php script is,i only want this part of the form to be displayed after certain validation is done.
and my page 2.php has:
Code: Select all
$ic = $_POST['icNum'];
echo "Ic num from hidden field:".$ic;
im trying to just output the hidden file value..to check whether it gets passed..
but apparently it doesnt,[s]coz[/s]
because im getting an empty space..
i have narrowed down the problem to:
my guess is, since that coding is already in an echo statement starting with ', so somehow all the single n double quotes are conflicting.

and i have tried using different combinations of single n double quotes,but none of it is working.and when i attempt to insert the $ic variable into my database,the value that is saved is: <?php echo $ic;?>.maybe only using quotes is not enough..what about slashes?.im really stumped..cant figure out how to get over this..would be very grateful if anyone can point me in the right direction.
thank you so much
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.
Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.
Posted: Sun Sep 02, 2007 11:00 pm
by shwetha004
hello all..
first of all,sorry about the AOL speak..i will avoid it in future..anyway,i managed to solve the problem..
instead of printing the whole form in a php echo statement,i kind of separated the code into different chunks,some html,some php..so,now my code reads:
Code: Select all
//some validation
//if the validation is successfull,the next part of the form will be displayed.
?>
Code: Select all
*i placed all the html code here..to display the form.
then to perform some database functions,i start the php code with <?php again..
maybe this is not the most efficient way,but at least its working..if anyone can show me a better wat to do it,i'll be happy to learn..