/    Sign up×
Community /Pin to ProfileBookmark

Unknown: Your script possibly relies on a session side-effect which

Hello,

I am using PHP 5 and i am getting following warning:

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.

Why this ?
How to avoid this without changing
PHP.INI…

Thanks in advance,
MAngesh

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@chazzyDec 04.2006 — can you show us the code that was being executed when this error showed?
Copy linkTweet thisAlerts:
@joshi_mangeshauthorDec 04.2006 — Thx buddy,

Here is the code

<code>

if (isset($_SESSION["maincat1"])) $maincat = $_SESSION["maincat1"]; else $maincat=0;

//echo $maincat;

$catList = $category->CategoryDropDownList(0,$maincat,"maincat");
echo $catList."<br>";

if (isset($_SESSION["productid"])) $productid = $_SESSION["productid"]; else $productid=0;
if (isset($_SESSION["subcat1"])) $subcat1 = $_SESSION["subcat1"]; else $subcat1=0;
//echo "subcat1-". $subcat1;

if ($subcat1 != 0)
{
$subcat1List = $category->CategoryDropDownList($maincat,$subcat1,"subcat1");
$productList = $product->ProductDropDownList($subcat1,$productid,"productid");
}
else
{
$subcat1List = "";
}
//echo $subcat2;
if (isset($_SESSION["subcat2"])) $subcat2 = $_SESSION["subcat2"]; else $subcat2=0;
if ($subcat2 != 0)
{
$subcat2List = $category->CategoryDropDownList($subcat1,$subcat2,"subcat2");
$productList = $product->ProductDropDownList($subcat2,$productid,"productid");
}
else
{
$subcat2List = "";
}


</code>
Copy linkTweet thisAlerts:
@herderFeb 23.2008 — I've been having the same warning since my provider upgraded the server and PHP version. Since suppressing warnings may lead to more problems I tried to find the root cause (and solution). I found many postings on the issue, but no clear answer anywhere. So here it comes.

My basic rule:


AVOID USING THE SAME NAMES FOR SESSION VARIABLES AND NORMAL ONES.

In your code this rule is broken by (one example)

[I]$productid = $_SESSION["productid"];[/I]

The warning is there because in older PHP environments, any changes to $productid would also be made to $_SESSION["productid"]. If your code relies on this behavior, it will not work correctly in the newer environments.

This in fact has its roots in the old way of registering session variables like

[I]$productid="whatever"; session_register("productid"); [/I]

making the global and the session variable virtually one and the same.

So,

* work on the session variable directly

*
if you do need a working copy, use a different variable name.

I hope this helps.
Copy linkTweet thisAlerts:
@joshi_mangeshauthorFeb 25.2008 — Thank you Sir,

Mangesh
Copy linkTweet thisAlerts:
@ccommon26Jun 14.2008 — Hi All,

I'm having the same issue above mentioned...

Here is the code:
<i>
</i>&lt;?
session_start();
session_register("ADMIN");
include'../config.php';
$title="$CONFIG-&gt;sitename ADMIN Login ";
include("$CONFIG-&gt;templatedir/header.php");
if(isset($ADMIN["admin"]["username"])){redirect("adminarea.php","",0);}
$frm=$HTTP_POST_VARS;;
if(!$frm){
$page_content="
&lt;table width=100% border="0" align="center" cellpadding="0" cellspacing="0"
bgcolor=white&gt;
&lt;tr&gt;
&lt;td &gt;&lt;br&gt;&lt;br&gt;&lt;table width="30%" border="0" cellspacing="2" cellpadding="0" align=center&gt;
&lt;tr valign="top"&gt;
&lt;td&gt;
&lt;form name="form1" method="post" action="$CONFIG-&gt;siteurl/radmin/index.php"&gt;
&lt;table width="100%" border="1" cellspacing="0" cellpadding="0" &gt;
&lt;tr&gt;
&lt;td&gt;
&lt;table width="100%" border="0" cellspacing="0" cellpadding="3" class="text" bgcolor="$CONFIG-&gt;lightcolor"&gt;
&lt;tr id=heading&gt;
&lt;td colspan="2" align=center class=text&gt;&lt;strong&gt;ADMIN Login!&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align="right" class="text_mic"&gt;
&lt;div align="right" class=text&gt;Username:&lt;/div&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;input type="text" name="username" size="10" maxlength="30" class="input"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align="right" class="text_mic"&gt;
&lt;div align="right" class=text&gt;Password:&lt;/div&gt;
&lt;/td&gt;
&lt;td class="barreclair"&gt;&lt;span class="barreclair"&gt;
&lt;input type="password" name="password" size="10" maxlength="30" class="input"&gt;
&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td align="center"&gt;
&lt;input type="submit" name="Submit" value="Login" class="button"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/form&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;div align=center&gt;&lt;a class=link1 href=forgot_password.php&gt;Forgot your password?&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;";}
if (match_referer() &amp;&amp; isset($frm["username"])) {
$err=0;
$msg = "&lt;p class=text align=center&gt;The following error(s) occured:&lt;br&gt;&lt;ul class=text&gt;";

<i> </i> if(!$frm["username"])
<i> </i> {$err=1;
<i> </i> $msg.="&lt;li&gt;Please enter the username&lt;/li&gt;";
<i> </i> }
<i> </i> if(!$frm["password"])
<i> </i> {$err=1;
<i> </i> $msg.="&lt;li&gt;Please enter the password&lt;/li&gt;";
<i> </i> }

<i> </i> $msg.="&lt;/ul&gt;&lt;br&gt;&lt;p class=text align=center&gt;
Please go &lt;a href="javascript:history.back();" class=link1&gt;Back &lt;/a&gt; and correct this.&lt;/p&gt;";
if($err==1)$page_content=$msg;

}

function verify_login($username, $password) {
$q= db_query("
SELECT username, firstname, lastname, email, lastlogin,last_ip
FROM users
WHERE username = '$username' AND password = '$password' and id='1'
");

<i> </i>return db_fetch_array($q);}

IF($frm["username"]&amp;&amp;$frm["password"]){
$user = verify_login($frm["username"], $frm["password"]);
if ($user) {
$ADMIN["admin"] = $user;
$ADMIN["ip"] = $REMOTE_ADDR;

<i> </i> db_query("update users set lastlogin=now(),last_ip='$REMOTE_ADDR' where username='$frm[username]'");
<i> </i> $goto = $CONFIG-&gt;siteurl."/radmin/adminarea.php" ;
<i> </i> redirect( $goto,"",0);
<i> </i> die;

<i> </i>} else {
<i> </i> $page_content = "&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;p align=center class=text&gt;Invalid login, please try &lt;a href="javascript:history.back();"

class=link1&gt;again&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/p&gt;";
$frm["username"] =$HTTP_POST_VARS["username"];
}
}
include("$CONFIG-&gt;templatedir/admin.content.php");
include("$CONFIG-&gt;templatedir/footer.php");?&gt;


hosting is using PHP 5

Does anyone know how to fix this incompatibility ?

Thanks!

<CG>
Copy linkTweet thisAlerts:
@herderJun 14.2008 — Hi,

Like I mentioned in my previous post:

DO NOT USE THE SAME VARIABLE NAMES FOR NORMAL AND SESSION VARIABLES.

By using [I]session_register[/I] you are violating this rule.

For example $ADMIN: drop the session_register, and replace all references to $ADMIN by $_SESSION["ADMIN"]. Do the same with all other registered variables and you should be fine.

Have fun!
Copy linkTweet thisAlerts:
@ccommon26Jun 14.2008 — This is what I did..... but, same issue, as you can see I'm a foolish newbie, can you reply with the right coding


***********************************************
<? session_start();

/*session_register("ADMIN");*/

include'../config.php';

$title="$CONFIG->sitename ADMIN Login ";

include("$CONFIG->templatedir/header.php");

if(isset($_SESSION["ADMIN"]["admin"]["username"])){redirect("adminarea.php","",0);}

$frm=$HTTP_POST_VARS;;

if(!$frm){

$page_content="

<table width=100% border="0" align="center" cellpadding="0" cellspacing="0"

bgcolor=white>

<tr>

<td ><br><br><table width="30%" border="0" cellspacing="2" cellpadding="0" align=center>

<tr valign="top">

<td>

<form name="form1" method="post" action="$CONFIG->siteurl/radmin/index.php">

<table width="100%" border="1" cellspacing="0" cellpadding="0" >

<tr>

<td>

<table width="100%" border="0" cellspacing="0" cellpadding="3" class="text" bgcolor="$CONFIG->lightcolor">

<tr id=heading>

<td colspan="2" align=center class=text><strong>ADMIN Login</strong></td>

</tr>

<tr>

<td align="right" class="text_mic">

<div align="right" class=text>Username:</div>

</td>

<td>

<input type="text" name="username" size="10" maxlength="30" class="input">

</td>

</tr>

<tr>

<td align="right" class="text_mic">

<div align="right" class=text>Password:</div>

</td>

<td class="barreclair"><span class="barreclair">

<input type="password" name="password" size="10" maxlength="30" class="input">

</span></td>

</tr>

<tr>

<td></td>

<td align="center">

<input type="submit" name="Submit" value="Login" class="button">

</td>

</tr>

</table>

</td>

</tr>

</table>

</form>

</td>

</tr>

</table><div align=center><a class=link1 href=forgot_password.php>Forgot your password?</a><br><br></div></td>

</tr>

</table>";}

if (match_referer() && isset($frm["username"])) {

$err=0;

$msg = "<p class=text align=center>The following error(s) occured:<br><ul class=text>";

if(!$frm["username"])
{$err=1;
$msg.="<li>Please enter the username</li>";
}
if(!$frm["password"])
{$err=1;
$msg.="<li>Please enter the password</li>";
}

$msg.="</ul><br><p class=text align=center>

Please go <a href="javascript:history.back();" class=link1>Back </a> and correct this.</p>";

if($err==1)$page_content=$msg;

}

function verify_login($username, $password) {

$q= db_query("

SELECT username, firstname, lastname, email, lastlogin,last_ip

FROM users

WHERE username = '$username' AND password = '$password' and id='1'

");

return db_fetch_array($q);}

IF($frm["username"]&&$frm["password"]){

$user = verify_login($frm["username"], $frm["password"]);

if ($user) {

$_SESSION["ADMIN"]["admin"] = $user;

$_
SESSION["ADMIN"]["ip"] = $REMOTE_ADDR;

echo "foo is $user";

db_query("update users set lastlogin=now(),last_ip='$REMOTE_ADDR' where username='$frm[username]'");

$goto = $CONFIG->siteurl."/radmin/adminarea.php" ;

redirect( $goto,"",0);

die;

} else {
$page_content = "<br><br><br><p align=center class=text>Invalid login, please try <a href="javascript:history.back();"


class=link1>again</a><br><br><br><br><br><br><br></p>";

$frm["username"] =$HTTP_POST_VARS["username"];

}

}

include("$CONFIG->templatedir/admin.content.php");

include("$CONFIG->templatedir/footer.php");?>

***********************************************

Thanks for your help!

<CG>
×

Success!

Help @joshi_mangesh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...