Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
drops a $_SESSION[] variable
Old 11-05-2008, 05:36 PM drops a $_SESSION[] variable
matt w's Avatar
Super Talker

Posts: 136
Location: kalamazoo
Trades: 0
I have a bug. everything works fine, but on the last page the script omits the $_SESSION['file'] variable (I don't know why, all the other variables--login, reason, example-- come through.) Can somebody spot the bug? Pages follow:

initial form page:

HTML Code:
<?php
session_start();
/*Title: "radio form.php"
collects a document name and passes it to a series of download pages
*/
?>
<html>
<body>
<form name="first_form" action="first_form_action.php" method="post">
first file:<a href="file.pdf"> click to view sample</a>
<input type="hidden" name="file" value="first file" >
<br>
<input type ="submit" value ="proceed to download">
<br>
</form>
<form name="second_form" action="first_form_action.php" method="post">
second file:<a href="file.pdf"> click to view sample</a>
<input type="hidden" name="file" value="second file" >
<br>
<input type ="submit" value ="proceed to download">
</form>
<p>
If you click the "Submit" button, you will send your input
to a new page that will start processing your download.
</p>
</body>
</html>
first form processing page:

HTML Code:
<?php
/*Title: "first form action.php"
collects reason why client is downloading a material
and proceeds to download page
*/
require_once('auth.php');
session_start();
 
//processes the entered "reason" for downloading the form
if ($_POST["submit"]) {
$_SESSION['reason']=$_POST['reason'];
header("location: member_page.php");
}
 
$_SESSION['file']=$_POST['file'];
//dummy session variable just to test sessions functionality
$example="example";
$_SESSION['example']=$example;
 
$break = "\r";
echo "hello,";
echo $break;
echo $_SESSION['login'];
echo $break;
echo "Please give a brief reason why you are downoading ";
echo $_SESSION['file'];
echo '<pre>' . htmlentities(print_r($_SESSION, 1)) . '</pre>';
 
?>
<html>
<form action="first_form_action.php" method="post">
<table border="0" cellspacing="0" >
<tr>
<td>Reason:</td>
</tr>
<tr>
<td>
<textarea name="reason" rows="6" cols="29"></textarea></td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Send Reason" />
</td>
</tr>
</table>
</form>
</html>
last page:

HTML Code:
<?php
/*Title: "member page.php"
lets the client download a certain material
and sends an e-mail regarding the identity of the
client and the reason they wanted the material
*/
require_once('auth.php');
session_start();
?>
<!DOCTYPE html
PUBLIC "-/WWW.W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.wc3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head><title>member page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 
</head>
<body>
<?php
echo "Thanks, ";
echo $_SESSION['login'];
 
/*
//executes operations on $_SESSION variables
//e.g. sends email containing information on client
//and why they wanted the materials in the ddownloaded file
$myFile = "downloadlog.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $_SESSION['reason'];
fwrite($fh, $stringData);
*/
?>
 
<a href="presentation1.html">right click here and select "Save Target As"
</a>
to download <?php print $_SESSION['file']?>
<?php
echo '<pre>' . htmlentities(print_r($_SESSION, 1)) . '</pre>';
?>
</body>
</html>
Thanks,
Matt
matt w is offline
Reply With Quote
View Public Profile Visit matt w's homepage!
 
 
Register now for full access!
Old 11-06-2008, 12:20 AM Re: drops a $_SESSION[] variable
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
What do you mean 'omits'?

var_dump($_POST['file']) right before you try to put it into the session, I'm quite sure it will be empty. This is because you redirect after receiving $_POST['submit'].
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 11-06-2008, 12:43 AM Re: drops a $_SESSION[] variable
matt w's Avatar
Super Talker

Posts: 136
Location: kalamazoo
Trades: 0
Uh, umm, omits? All the other session variables are carried into the last page except the darn SESSION['file'] variable. The SESSION['reason'] variable comes through, (is recognized on the last page), the SESSIONS['login'] comes through (that is, is available, is printed by the <pre>...</pre> code), but never the SESSION['file'] variable never shows up on the last page. It is always ...not there. mtishetsky, in all honesty I do not understand the rest of you post. I am the definition of "newbie".

Thanks for the help.
mw
matt w is offline
Reply With Quote
View Public Profile Visit matt w's homepage!
 
Old 11-06-2008, 03:11 AM Re: drops a $_SESSION[] variable
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Right now you have:
PHP Code:
if ($_POST["submit"]) {
$_SESSION['reason']=$_POST['reason'];
header("location: member_page.php");
}
 
$_SESSION['file']=$_POST['file']; 
Should be:
PHP Code:
if ($_POST["submit"]) {
$_SESSION['reason']=$_POST['reason'];
$_SESSION['file']=$_POST['file'];
header("location: member_page.php");

And your home tas will be: explain what your mistake was.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 11-06-2008, 05:53 PM Re: drops a $_SESSION[] variable
matt w's Avatar
Super Talker

Posts: 136
Location: kalamazoo
Trades: 0
Mtishetsky:
I can't get it! I made the alteration in the code on the "first_form_action.php" page:

PHP Code:
if ($_POST["submit"]) {
$_SESSION['reason']=$_POST['reason'];
$_SESSION["html"]=$_POST["html"];
header("location: member_page.php");

But the SESSION['html'] (I changed the variable name to "html") still gets wiped before it gets to the "member.php" page. Do you know that there is very little php on the form page? That it justs submits the form data to a new page called "first_form_action.php"? And that that page then submits to "member.php"? (Three pages?)

I've been working on this. But I just don't see it!


Thanks for the sagacious advice,
mw
matt w is offline
Reply With Quote
View Public Profile Visit matt w's homepage!
 
Old 11-06-2008, 06:08 PM Re: drops a $_SESSION[] variable
Extreme Talker

Posts: 182
Trades: 0
You changed the var name to 'html'? Did you also change the form field name?

Do some simple debugging to narrow down the cause.

On first_form_action.php, try only doing this:

PHP Code:
session_start();
echo 
"<pre>";
print_r $_POST );
echo 
"</pre>"
This will allow you to confirm that the correct data is being transferred from the form.

Then, on member_page.php:

PHP Code:
session_start();
echo 
"<pre>";
print_r $_SESSION );
echo 
"</pre>"
This will allow you to see what is in the session array.
bhgchris is offline
Reply With Quote
View Public Profile
 
Old 11-06-2008, 11:06 PM Re: drops a $_SESSION[] variable
matt w's Avatar
Super Talker

Posts: 136
Location: kalamazoo
Trades: 0
I'm already doing:
HTML Code:
echo '<pre>' . htmlentities(print_r($_SESSION, 1)) . '</pre>';
which gives me on "first form action.php" the following:

Array
(
[SESS_MEMBER_ID] => 1
[login] => sifaka
[html] => second file
[example] => example
)

and on "members.php" the following:

Array
(
[SESS_MEMBER_ID] => 1
[login] => sifaka
[html] =>
[example] => example
[reason] => I am trying to save the world and I thought this would help.
)


I have changed the form field name to "html" match the change of the session variable to SESSION['html']
"second file" is the name of one of the form field values, but it never makes it to the member.php page.
Thanks bhgchris!
matt w is offline
Reply With Quote
View Public Profile Visit matt w's homepage!
 
Old 11-07-2008, 02:33 AM Re: drops a $_SESSION[] variable
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Most probably you overwrite $_SESSION['html'] somewhere in your script
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 11-07-2008, 05:49 AM Re: drops a $_SESSION[] variable
muqti's Avatar
Average Talker

Posts: 23
Trades: 0
yes write and will work
muqti is offline
Reply With Quote
View Public Profile
 
Old 11-07-2008, 09:55 AM Re: drops a $_SESSION[] variable
Extreme Talker

Posts: 182
Trades: 0
Perhaps you are leaving something out in your shortened code example?

Is the above code the exact code you are using?
bhgchris is offline
Reply With Quote
View Public Profile
 
Old 11-07-2008, 04:00 PM Re: drops a $_SESSION[] variable
matt w's Avatar
Super Talker

Posts: 136
Location: kalamazoo
Trades: 0
bhgchris,
I think I am wiping the session variables 'html' and 'sample' when I submit the self submitting form in "first form action.php" on the second page. But only these variables --created on the first page "radio form.php"-- are being wiped! I know this because a session variable I create on the second page (named 'example') is hanging out for the duration.
I submit to "first form action" twice, once from the first page and once from itself. Is that a problem?
I have added code so that all three pages are valid xhtml transitional.
Below is the whole three page mess itself:
HTML Code:
<?php
session_start();
/*Title: "radio form.php"
collects a document name and passes it to a series of download pages
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>radio form</title>
</head>
<body>
<form name="radio_form" action="first_form_action.php" method="post">
second file:<a href="file.pdf"> click to view sample</a>
<input type="hidden" name="html" value="second file" />
<br />
<input type="hidden" name="sample" value="sample formfield" />
<br />
<input type ="submit" value ="proceed to download" />
</form>
<?php
echo '<pre>' . htmlentities(print_r($_SESSION, 1)) . '</pre>';
?>
<p>
If you click the "proceed to download" button, you will send your input
to a new page that will start processing your download.
</p>
</body>
</html>
second page:
HTML Code:
<?php
session_start();
require_once('auth.php');
 
/*Title: "first form action.php"
collects reason why client is downloading a material
and proceeds to download page
*/
 
//handle form about the reason the member is downloading material
//form located below on this page
if ($_POST["submit"]) {
$_SESSION['reason']=$_POST['reason'];
header("location: member_page.php");
}
//print_r array showing session variables
echo '<pre>' . htmlentities(print_r($_SESSION, 1)) . '</pre>';
//examples of session variables received from
//the original form on "radio form.php"
//--they are wiped when I submit this pages form
$_SESSION['html']=$_POST['html'];
$_SESSION['sample']=$_POST['sample'];
 
//example of a session variable created on this page
//session variables created here last through the whole session!
$example="example";
$_SESSION['example']=$example;
//generate prompt for member attempting download
$break = "\r";
echo "hello,";
echo $break;
echo $_SESSION['login'];
echo $break;
echo "Please give a brief reason why you are downloading ";
echo $_SESSION['html'];
//print_r array showing session variables
echo '<pre>' . htmlentities(print_r($_SESSION, 1)) . '</pre>';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>first form action</title>
</head>
<body>
<form action="first_form_action.php" method="post">
<table border="0" cellspacing="0" >
   <tr>
   <td>Reason:</td>
   </tr>
   <tr>
   <td>
   <textarea name="reason" rows="6" cols="29"></textarea></td>
  </tr>
     <tr>
  <td>
     <input type="submit" name="submit" value="Send Reason" />
     </td>
  </tr>
    </table>
</form>
</body>
</html>
third page:
HTML Code:
<?php
session_start();
require_once('auth.php');
 
/*Title: "member page.php"
lets the client download a certain material
and sends an e-mail regarding the identity of the
client and the reason they wanted the material
*/
 
//greats the member
echo "Thanks, ";
echo $_SESSION['login'];
 
//executes operations on $_SESSION variables
//e.g. sends email containing information on client
//and why they wanted the materials in the ddownloaded file
$myFile = "downloadlog.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $_SESSION['reason'];
fwrite($fh, $stringData);
fclose($fh);
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>member page</title>
</head>
<body>
<a href="presentation1.html">
right click here and select "Save Target As"</a> to download <?php print $_SESSION["html"]?>
</body>
</html>
<?php
echo '<pre>' . htmlentities(print_r($_SESSION, 1)) . '</pre>';
?>
Thank you!
matt w is offline
Reply With Quote
View Public Profile Visit matt w's homepage!
 
Old 11-10-2008, 04:17 PM Re: drops a $_SESSION[] variable
matt w's Avatar
Super Talker

Posts: 136
Location: kalamazoo
Trades: 0
Two pages are submitting to the same script. It was necessary create two parts in the processing done on the second page, one executed when the first page submits to the second page, one executing when the second page submits to itself.
Thanks to:
mtishetsky and bhgchris
You've got positive talkupation!
matt w is offline
Reply With Quote
View Public Profile Visit matt w's homepage!
 
Reply     « Reply to drops a $_SESSION[] variable
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.34437 seconds with 12 queries