Problem in Passing PHP variables over multiple php pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
maani786
Forum Newbie
Posts: 16
Joined: Fri Jul 13, 2007 2:13 am

Problem in Passing PHP variables over multiple php pages

Post 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
Last edited by maani786 on Fri Jul 13, 2007 5:33 am, edited 1 time in total.
User avatar
Gente
Forum Contributor
Posts: 252
Joined: Wed Jun 13, 2007 9:43 am
Location: Ukraine, Kharkov
Contact:

Post by Gente »

User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

Basically you need to initialise the "start" of session usage:

Put this at the very top of your page

Code: Select all

session_start();
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).
maani786
Forum Newbie
Posts: 16
Joined: Fri Jul 13, 2007 2:13 am

thanks for ur reply

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post 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/".
maani786
Forum Newbie
Posts: 16
Joined: Fri Jul 13, 2007 2:13 am

hi

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Just try it. Worst thing that can happen is that it doesn't work...
maani786
Forum Newbie
Posts: 16
Joined: Fri Jul 13, 2007 2:13 am

thanks

Post 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'];
?>
maani786
Forum Newbie
Posts: 16
Joined: Fri Jul 13, 2007 2:13 am

output

Post 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
ocpamit
Forum Newbie
Posts: 7
Joined: Fri Jul 13, 2007 6:53 am
Location: Punjab, India

Post 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.
Last edited by ocpamit on Fri Jul 13, 2007 7:44 am, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

While function and method names are not case sensitive variable names are.
Use $_SESSION, not $_session.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post 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.
maani786
Forum Newbie
Posts: 16
Joined: Fri Jul 13, 2007 2:13 am

thanks 2 all

Post 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
Post Reply