Page 1 of 1
Problem in Passing PHP variables over multiple php pages
Posted: Fri Jul 13, 2007 2:59 am
by maani786
hi all.
dear programmers and developers i am begineer to php progrmming.
i am working on php 5.2.3.3 with IIS on windows XP 2006 version.
i want to get information from user to a form named "form.htm"and then i pass values to php page named "info.php" by using $_POST method. upto this state nothing is wrong there but the problem starts when i want to use that $_POST[]
values to second php page named "access.php". i cannot get those values to second php page.
i have no idea of php sessions if any body guides me that how i can do all that with phpsession or with some other approach. i would be very thankful.
Regards..
maani janjua
Posted: Fri Jul 13, 2007 4:16 am
by Gente
Posted: Fri Jul 13, 2007 5:05 am
by aceconcepts
Basically you need to initialise the "start" of session usage:
Put this at the very top of your page
Whenever you want to pass variables to multiple pages when you can't use "POST" simply setup some "SESSION" variables:
Code: Select all
$_SESSION["first_name"] = $_POST["first_name"];
Remember you must have a value that the "SESSION" can be set to i.e. you must "submit" form data ("POST" values must exist).
thanks for ur reply
Posted: Fri Jul 13, 2007 5:25 am
by maani786
respected sir
i have did all that in the same way u told.
i send information from a form' s textfield and that values is diplayed at ist page of php which is called by form's action method.
and after that i displayed that value at php page by using session variable.
the value is displayed accurately but a message along with value is also displayed.
"PHP Warning: session_start() [function.session-start]: open(C:\DOCUME~1\maani\LOCALS~1\Temp\php\session\sess_h4peelbc3vhgimb0p8putkbbk2, O_RDWR) failed: Permission denied (13) in C:\Inetpub\wwwroot\phpsessions\1.php on line 2 PHP Warning: Unknown: open(C:\DOCUME~1\maani\LOCALS~1\Temp\php\session\sess_h4peelbc3vhgimb0p8putkbbk2, O_RDWR) failed: Permission denied (13) in Unknown on line 0 PHP Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (C:\DOCUME~1\maani\LOCALS~1\Temp\php\session) in Unknown on line 0 "
what i am looking for is to use that value( which was passed by form to php page )
to another php page i am using the same session variable which was created in previous php page but nothing is displayed there and i got only this message
"PHP Warning: session_start() [function.session-start]: open(C:\DOCUME~1\maani\LOCALS~1\Temp\php\session\sess_h4peelbc3vhgimb0p8putkbbk2, O_RDWR) failed: Permission denied (13) in C:\Inetpub\wwwroot\phpsessions\2.php on line 2 PHP Notice: Undefined index: text in C:\Inetpub\wwwroot\phpsessions\2.php on line 14 PHP Warning: Unknown: open(C:\DOCUME~1\maani\LOCALS~1\Temp\php\session\sess_h4peelbc3vhgimb0p8putkbbk2, O_RDWR) failed: Permission denied (13) in Unknown on line 0 PHP Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (C:\DOCUME~1\maani\LOCALS~1\Temp\php\session) in Unknown on line 0"
what could be the solution
regards
-----------
maani janjua
Posted: Fri Jul 13, 2007 5:33 am
by volka
run
Code: Select all
<?php echo 'ini: ', get_cfg_var('cfg_file_path'); ?>
to find the php.ini you have to edit.
Open this file in a text editor and search for
session.save_path.
Set the value to a valid directory where php can save the session data and save the file.
Restart the webserver.
Posted: Fri Jul 13, 2007 5:38 am
by aceconcepts
I think this has something to do with the dir "\Temp\".
Its basically saying the "session.save_path" could not be found, so focus on the directory path.
Open php.ini and check if the directory for "session.save_path" is correct. On Windows systems the dir is "/temp/".
hi
Posted: Fri Jul 13, 2007 5:41 am
by maani786
dear volka
the value in php.ini is
session.save_path="C:\DOCUME~1\maani\LOCALS~1\Temp\php\session"
if i change it to another path like
session.save_path="d:\php\session"
will it work for me?
Posted: Fri Jul 13, 2007 5:43 am
by volka
Just try it. Worst thing that can happen is that it doesn't work...
thanks
Posted: Fri Jul 13, 2007 6:32 am
by maani786
thats good idea .
i changed path and all error messages vanished.
but still i cannot get value at second page of php
i have to reintialize the session variable in second page?
because there is no value.
"my code for page 1.php is"
Code: Select all
<?php
session_start();
$_session['text']=$_POST["textfield"];
?>
<?php
echo "Php Page # 1 session: ".$_session['text'];
?>
<form method="post" action="2.php">
<input type="submit" name="submit" id="submit" value="Next Page" class="button" />
</form>
"Code for page 2.php is"
Code: Select all
<?php
session_start();
?>
<?php
echo "Php page # 2 session: ".$_SESSION['text'];
?>
output
Posted: Fri Jul 13, 2007 6:49 am
by maani786
respected all
output of 1.php is ok.
Php Page # 1 session: maani
output of 2.php is
Php page # 2 session:
whats wrong with coding..
kindly guide me ... i would be very thankful to all who give a positive responce..
regards
---------------
maani janjua
Posted: Fri Jul 13, 2007 7:31 am
by ocpamit
hi as you said in the start, you are new to php.
i think problem might be when you post variable (say abc) to info.php, there you submit some form to move to access.php e.g.
$abc = $_POST['abc'];
<form action="access.php" method="post">
<input type="submit" value="Move to Access File">
</form>
....something like this.
Nothing is wrong with this but the posted variable will be not posted to access.php. What you need to do is pass this variable as hidden field from within the form as...
<form action="access.php" method="post">
<input type="hidden" name="abc" value="<?php echo $abc;?>">
<input type="submit" value="Move to Access File">
</form>
Now it will be available at next page i.e. access.php
If this is the case, above example may solve your problem. If something else just ignore it.
Posted: Fri Jul 13, 2007 7:34 am
by volka
While function and method names are not case sensitive variable names are.
Use $_SESSION, not $_session.
Posted: Fri Jul 13, 2007 8:33 am
by aceconcepts
If you are passing values from one form to another page i.e. page1(form) to page2 simply set the "SESSION" variable to the "POST" variable in the second page.
Think of it like this:
if you live at 100 London Road England and post a letter to 17 China Town Street Paris where will the letter be received???
Thats right, 17 China Town (providing no delivery hicups occur).
I hope the example helps.
You can set the "ACTION" part of the "FORM" to the same file it was sent from (just like ocpamit suggested) but as you are particulalry new to PHP its probably more straightforward to use additional pages so that the results/methods are clearer.
thanks 2 all
Posted: Fri Jul 13, 2007 8:59 am
by maani786
Thank you so very much dear mr. ocpamit and mr. Volka
and every body which reply me..
due to hidden variable i have got the solution which i was looking for..
perhaps i will be back soon with new query and i am hopeful that u all will reply me again also...
Take a very good care of urselves.
Thanks once again
Regards
---------------------
maani janjua