/    Sign up×
Community /Pin to ProfileBookmark

weird error message

I’ve been learning sessions for a log in area of a web site. I’ve got it working fine, but when the user clicks on the link to fire a mysql retrieval script (for the members content), i get this error message:

WARNING: Unknown(): Your script possibly relies on a session side-effect which existed until PHP4.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

Does anyone know what this means? I’m running php 4.3.1 and i know they’ve changed some things in it. I’d rather code it properly then simply turn off an error message and use buggy scripts. Yet its weird that this is only a problem when theres a mysql retrieve in the script as well. ?

any help is greatly appreciated

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@pyroAug 04.2003 — Can we see the code that is displaying this error message?
Copy linkTweet thisAlerts:
@moondanceauthorAug 04.2003 — I have a few scripts. The first is a log in script:

login.php:

<?

session_start();

$_SESSION['Name'] = $_POST['Name'];

$_SESSION['Password'] = $_POST['Password'];

$Name = stripslashes($Name);

$Password = stripslashes($Password);

if((!$Name) ||(!$Password))

{

echo "You did not submit the following information: <br>";

if (!$Name){

echo "You need to enter a User ID <br>";

}

if (!$Password){

echo"You need to enter a password <br>";

}

//show the login form again

include "login.html";

exit();

}

//connect to database server

@ $dbcnx = mysql_connect("localhost", "root");

if (!$dbcnx)

{

echo ("Error: Could not connect to server");

}

//select database

$db = mysql_select_db("userdb", $dbcnx);

if (!$db)

{

echo ("Could not connect to database");

exit;

}

//login

$query = mysql_query("select * from user where name= '$Name'and password='$Password'");

if (mysql_num_rows($query) > 0)

{

//log in and register variables

$_SESSION['Name'] = $_POST['Name'];

$_SESSION['Password'] = $_POST['Password'];

$_SESSION['row'] = $_POST['row'];

$_SESSION['result'] = $_POST['result'];

$_SESSION['db'] = $_POST['db'];

$_SESSION['sql'] = $_POST['sql'];

$_SESSION['valid_user'] = $valid_user;

header("Location: login_success.php");

}

else

{

echo ("User ID not recognised. Please try again");

include "login.html";

exit();

}

if (!$query)

{

echo("incorrect user name");

include "login.html";

exit();

}

?>

login _success.php looks like this:

login_success.php:

<?

session_start();

echo ("Welcome " . $_SESSION['Name'] . ". You can now view your <a href = info.php>account</a>

echo ("<BR><BR> <a href = logout.php>Logout</a>");

?>


And the following page is where i get the error message, when the user clicks on the above link to their own account, info.php:

info.php:

<?

session_start();

//not sure if these are supposed to go here

$dbcnx = $_POST['dbcnx'];

$db = $_
POST['db'];

$result = $_POST['result'];

$row = $_
POST['row'];


echo ( $_SESSION['Name'] . ", these are your complaints arranged in order by most recent displayed first");

//display all session variables and values

echo ("<BR><BR>");

print_R($_SESSION);

//connect to database server

@ $dbcnx = mysql_connect("localhost", "root");

if (!$dbcnx)

{

echo ("Error: Could not connect to server");

}

//select database

$db = mysql_select_db("accounts", $dbcnx);

if (!$db)

{

echo ("Could not connect to database");

}

$result = mysql_query("select * from user_account where from = '$Name' order by daterecieved desc") or die ("Couldn't Connect");

echo "<BR><BR><BR>";

while ($row = mysql_fetch_array($result))

{

echo "<table width = 80% align = center border = 1>";

echo "<tr width>";

echo "<td width = 10% align = center>";

echo "<b>ID</b>";

echo "</td>";

echo "<td width = 50%>";

echo "<b>Summary</b>";

echo "</td>";

echo "<td width = 20%>";

echo "<b>Current Status</b>";

echo "</td>";

echo "<td width = 20%>";

echo "<b>Date Recieved</b>";

echo "</td>";

echo "</tr>";

echo "<BR>";

//populate table from db

echo "<tr>";

echo "<td align = center>";

echo $row["ID"];

echo "</td>";

echo "<td>";

echo $row["Description"];

echo "</td>";

echo "<td>";

echo $row["Status"];

echo "</td>";

echo "<td>";

//echo $row["daterecieved"];

echo $timestr;

echo "</td>";

echo "</tr>";

echo "</table>";

}

?>

The reason i included the first two parts is because i'm sure if i need to declare the session variables for the mysql query somewhere, and i'm not sure if i've put them in the right place.

Now i know that info.php works fine, because when i run it alone without using sessions, it retrieves the info fine and puts it in the tables.

Therefore i'm assuming the problem is with the variables such as $db, $dbcnx, $sql, $result etc. I'm not sure if i even need to store these as session variables, but if you try to run the third page, it writes the first few lines, then the page is blank apart from that error message - so the session is working, but there is no mysql retrieval, and no mysql error messages either.


*seriously stumped*
Copy linkTweet thisAlerts:
@Bootsman123Aug 04.2003 — I don't know if it's really necessary, but I always register the session variables.

session_register ('variable');

$_SESSION['variable'] = "Value";
Copy linkTweet thisAlerts:
@moondanceauthorAug 04.2003 — That would work with previous versions of PHP - but ..." with $_SESSION, there is no need to use the session_register(), session_unregister(), session_is_registered() functions. Session variables are accessible like any other variables. " (from http://uk.php.net/session)

I just can't figure out why the info.php script works on its own, but not when used in a session....and what that damn error message means


?
Copy linkTweet thisAlerts:
@moondanceauthorAug 04.2003 — i think i've narrowed down the problem to this:

the reason the mysql query is not showing anything is because the name (needed for the search) is not being accessed.

On the info.php, you can check that the session information is still there by typing

echo session_id();

print_R($_SESSION);

and this will show the user id ('Name') and password ('Password').

Now the mysql statement for some reason isn't picking up the name from the session:

$result = mysql_query("Select * from user_account where from = '$_SESSION['Name']' order by daterecieved desc") or die("Couldn't Connect");

Like i said, the session information is there, but the statement isn't just picking it up, not even if i try :

$_SESSION['Name'] = $var;

and then put the $var in the mysql statement.

Anyone got any ideas?

?
Copy linkTweet thisAlerts:
@Bootsman123Aug 04.2003 — If it can't pick the value of a session variable, then the session variable isn't set or it has no value.

Try this:

echo $_SESSION['Name'];

echo $_
SESSION['Password'];

It it doens't print out anything, then they hold no value.
×

Success!

Help @moondance 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.5,
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,
)...