Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem $_POST, $_SESSION

Status
Not open for further replies.

metamorphy

Programmer
Dec 16, 2001
34
US
Hi,

For some reason $_POST doesn't seem to be working. For example, when I do this:


<?php
$variable = $_POST['foo'];

?>

When I echo $variable; , the variable is empty. For some reason $_POST['foo'] is not getting the form data sent from the previous page??. I am using method=&quot;post&quot; on the submission form. Do I need to configure my php.ini or something? This is ultimately screwing up my ability to use $_SESSION also.


This code works:

<?php

$_SESSION['variable'] = $foo;

?>

but when I try to pass the session variable to a new page, its gone.

This obviously does not work ...

<?php

$_SESSION['variable'] = $_POST['foo'];

?>

I can only guess it something to do with the php.ini configuration. Any tips or help would be greatly appreciated. Thanks!!
 
Did you do session_start() before all the $_SESSION manipulation?
 
Here's page1.php
*******************************************

<?php

session_start();

?>

<HTML>
<HEAD></HEAD>
<BODY>
<FORM METHOD=&quot;post&quot; ACTION=&quot;page2.php&quot;>
username: <INPUT TYPE=&quot;text&quot; NAME=&quot;username&quot;><BR>
<INPUT TYPE=&quot;submit&quot; VALUE=&quot;submit&quot; >
</FORM>
</BODY>
</HTML>

HEre's page2.php
*************************************************
<?php
session_start();
?>

<HTML>
<HEAD></HEAD>
<BODY>

<?php

/* here's where I've tried several things:
THis doesn't work....

$username=$_POST['username'];
echo $username; //Nothing prints...

And this doesn't work....
$_SESSION['username'] = $_POST['username'];

echo $_SESSION['username']; //Nothing....

This works .... but I cannot carry the $_SESSION variable to the page3.php:

$_SESSION['username'] = $username;
echo $_SESSION['username'];

*/
?>


</BODY>
</HTML>


I can echo the session_id(); and it is the same on all three pages. I just dont get it????
 
Ah, there's the problem.

The superglobal arrays $_POST, $_GET, $_SESSION, $_COOKIE, $_SERVER, etc., were introduced to PHP 4.1.0. Use $HTTP_POST_VARS, $HTTP_GET_VARS, $HTTP_SESSION_VARS, $HTTP_COOKIE_VARS, $HTTP_SERVER_VARS, etc., respectively. (
Keep in mind that the $HTTP_*_VARS arrays are not superglobal. You will have to use the global operator to make them available in user-defined functions.

Can you upgrade? There are a lot of bug fixed between 4.0.6 and 4.3.3.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top