...

View Full Version : Error: session extension does not consider global variables as a source of data



chump2877
06-09-2005, 08:14 PM
I'm getting the following error message:


Warning: Unknown(): Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0

First of all, what good is an error message if it tells you the problem is on line 0... :)

Anyway, I'm guessing the error is telling me that I'm using some kind of "global session variable" (if there is such a thing -- apparently there is?) in my code, and that that directive is switched off on the server...

I guess I thought that if you started a session and created your session variables on previous pages of code, and placed the following code at the top of each subsequent page that wanted to access these session variables:


session_start();

...then you were golden....I mean, you could call a session variable without re-assigning it a value at the top of a later page of code....

I'm wondering, if maybe that's why I'm getting the error, because (given my server's settings) I NEED to reassign or initialize my session variables on EACH subsequent page...And if I don;t do this, then I'm using "global session variables", and this feature is turned off on the server, and thus the error message....

Does that make any sense? Or does the error indicate something else?

Thanks for any help.....

delinear
06-09-2005, 10:00 PM
What method are you using for setting and accessing the sessions?

chump2877
06-09-2005, 11:27 PM
This is the entire error output I get on the page:


Failed to add user information.
Warning: Unknown(): Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0

This is the code from the page where the error occurs:


<?

// start the session
session_start();
header("Cache-control: private"); //IE 6 Fix


if (isset($_SESSION['product_ID']))
{
$z = $z;
}
else
{
$product_ID = $_POST['product_ID'];

// Register session key with the value
$_SESSION['product_ID'] = $product_ID;




// If this is the second (or greater number) item added to cart, add selected item to shopping cart.


// Add selected item to shopping cart.




$dbcon = mysql_connect("localhost","username","password");

mysql_select_db("MyDatabase",$dbcon);


if (!isset($index_no))
{
$queryU = "SELECT index_no FROM user_information WHERE username LIKE '%".$_SESSION['username']."%'";
$resultU = mysql_query($queryU);
if (mysql_num_rows($resultU) >= '1')
{
while ($rowU = mysql_fetch_assoc($resultU))
{
$index_no = $rowU['index_no'];
settype($index_no, "integer");
$index_no += 1;
}

$queryW = "UPDATE user_information SET index_no=". $index_no. " WHERE username LIKE '%".$_SESSION['username']."%'";
$resultW = mysql_query($queryW);
if (mysql_errno())
{
die("<br>" . mysql_errno() . ": " . mysql_error() . "<br>");
}
if (mysql_affected_rows() != 1)
{
die("<br>Failed to add user information.");
}

}
else
{
die("<br>Failed to add user information.");
}
}




$ref_no = $index_no;




$query3 = "INSERT INTO ". $_SESSION['username']. " (product_ID, quantity, ref_no) VALUES ('".$_SESSION['product_ID']."', '0', '". $ref_no. "')";
$result3 = mysql_query($query3);
if (mysql_errno())
{
die("<br>" . mysql_errno() . ": " . mysql_error() . "<br>");
}
if (mysql_affected_rows() != 1)
{
die("<br>Failed to add user information.");
}


}





?>


<html>
<head>

<title>Shopping Cart</title>

<meta name = "description" content = "Media Moguls is a wholesale, computer retailer featuring over 6,000 computer products, ranging from individual components to highly-configurable systems.">
<meta name = "keywords" content = "computer accessories, computer components, hardware components, hardware accessories, buy computer accessories, buy computer components, buy hardware components, buy hardware accessories, computer accessories, computer components, hardware components, hardware accessories, buy computer accessories, buy computer components, buy hardware components, buy hardware accessories">




<? include('component_header.php') ?>



<?



$referring_URL = $_POST['referring_URL'];

/*
$referring_URL2 = $_SERVER["REQUEST_URI"];


$referring_URL3 = $_POST['referring_URL3'];
*/




// Execute code depending on referral page.


/*
if ($referring_URL == "/create_username.php")
{
include_once('create_username2.php');
}

if ($referring_URL == "/sign_in_component.php")
{
include_once('validate_sign_in.php');
}


if ($referring_URL3 == "/shopping_cart.php")
{
$username = $_POST['username'];
}
*/



?>



<!-- Start of Shopping Cart Form -->



<center><table border="0" cellpadding="0" cellspacing="0" width="610"><tr><td>


<center><table border="0" cellpadding="0" width="610">

<tr>
<td width="5%"></td>

<td width="90%">



<center>
<table border="0" cellpadding="0" cellspacing="0" width="540">
<tr>

<td width="91" bgcolor="#EEEEEE"></td>

<td width="85"><form method="post" action="log_out.php" style="margin:0"><input type="image" src="log_out_link.jpg" alt="Log Out"></form></td>

<td width="104"><form method="post" action="empty_cart2.php" style="margin:0"><input type="image" src="empty_cart_link.jpg" alt="Empty Cart"></form></td>

<td width="168"><form method="post" action="empty_cart1.php" style="margin:0"><input type="image" src="logout_empty_link.jpg" alt="Log Out & Empty Cart"></form></td>

<td width="92" bgcolor="#EEEEEE"></td>

</tr>
</table>
</center>


<a name="head">
<h3><center>Shopping Cart</center></h3>



<?



$dbcon = mysql_connect("localhost","username","password");

mysql_select_db("MyDatabase",$dbcon);


$query5 = "SELECT username FROM user_information WHERE username LIKE '%".$_SESSION['username']."%'";
$result5 = mysql_query($query5);
if (mysql_num_rows($result5) >= '1')
{
while ($row5 = mysql_fetch_assoc($result5))
{
$name = $row5['username'];
}
}

?>



<center><font size=3><i>Welcome, </font><font color="#FF0000"><? echo $name; ?></font><font size=3>! Please confirm that you would like this product added to your<br>shopping cart and specify the desired quantity. To remove this product from<br>your cart, please click on the "Remove This Item" button. To empty your<br>entire cart and start over, click on "Empty Cart" above.</i></font></center>
<br>





<?php

// $product_ID = $_POST['product_ID'];


$queryI = "SELECT index_no FROM user_information WHERE username LIKE '%".$_SESSION['username']."%'";
$resultI = mysql_query($queryI);
if (mysql_num_rows($resultI) >= '1')
{
while ($rowI = mysql_fetch_assoc($resultI))
{
$index_no2 = $rowI['index_no'];
}
}
else
{
echo '<span style="font-style:italic">No records found.</span><br><br>';
}


$query6 = "SELECT product_ID FROM ". $_SESSION['username']. " WHERE ref_no = ". $index_no2. "";
$result6 = mysql_query($query6);
//print_r($result6);
//exit();
if (mysql_num_rows($result6) >= '1')
{
while ($row6 = mysql_fetch_assoc($result6))
{
$product_ID = $row6['product_ID'];
//echo $product_ID;
//exit();
}
}
else
{
echo '<span style="font-style:italic">No records found.</span><br><br>';
}


$query7 = "SELECT description FROM parts WHERE product_code LIKE '%".$_SESSION['product_ID']."%'";
$result7 = mysql_query($query7);
if (mysql_num_rows($result7) >= '1')
{
while ($row7 = mysql_fetch_assoc($result7))
{
$product_description = $row7['description'];
}
}
else
{
echo '<span style="font-style:italic">No records found.</span><br><br>';
}

$query8 = "SELECT price FROM parts WHERE product_code LIKE '%".$_SESSION['product_ID']."%'";
$result8 = mysql_query($query8);
if (mysql_num_rows($result8) >= '1')
{
while ($row8 = mysql_fetch_assoc($result8))
{
$product_price = $row8['price'];
}
}
else
{
echo '<span style="font-style:italic">No records found.</span><br><br>';
}

?>



<br>
<table border="0" cellpadding="0" cellspacing="0" width="610"><tr>
<td align="left">You have requested the following item:</td>
<td align="right">
<form method="post" action="remove_item.php#product_block" style="margin:0">
<input type="submit" value="Remove This Item">
</form>
</td>
</tr>
</table>


<br>



<? echo '<div style="background-color:#DADADA;padding:5px;width:100%"><span style="font-style:italic;color:#000000">', $product_description,'</span></div>';
?>



<br>Cost of this item is:<br><br>


<? echo '<div style="background-color:#DADADA;padding:5px;width:100%"><span style="font-weight:bold;color:#000000">$', $product_price,'</span></div>';
?>


<br>
<form method="post" action="quantity_received.php#product_block">


Please enter the quantity that you desire: <i>(Enter digits only.)</i>

<br><br>
<center>
<font size="2">Click "Submit Quantity", let the page reload, and then continue with the form.</font>
<br><input type="text" name="quantity" size="3">
<input type="submit" value="Submit Quantity">
</center>
</form>











</td>

<td width="5%"></td>
</tr>
</table>




</td></tr></table></center>



<!-- End of Shopping Cart Form -->




<? include('component_footer.php') ?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum