Jump to content

[SOLVED] 1 More Problem (Last One ;) )


imdead

Recommended Posts

Hey Guys, 1 Last Problem :)

 

I made this code (Practicly a re-write since i last showed you guys it)

 

Anyway this is the Takelogin

<?php
ob_start();
session_start();
$conn = mysql_connect("localhost","root","");
$db = mysql_select_db("pete");
if(isset($_POST['submit'])) {
$username = htmlspecialchars($_POST['username'], ENT_QUOTES);
$password = htmlspecialchars($_POST['password'], ENT_QUOTES);
$password = ($password);
$username = addslashes($username); 
$password = addslashes($password); 
$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'");
if(mysql_num_rows($sql)>0) {
session_register("username");
session_register("password");
$sessionid = session_name();
mysql_query("UPDATE users SET sessionid='$sessionid' WHERE username='$username' and password='$password' LIMIT 1");
ob_start();
   exit();
   ob_flush();
}
if (mysql_num_rows($sql)>1){
	$row = mysql_fetch_assoc($sql);
	$userlevel = $row['userlevel'];
}

else {
header("Location:login.php");
}
}
ob_flush();
?> 

 

The problem is..

The code logs me in and everything although i get this error

 

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

 

Also i dont think it is getting the row $userlevel becuase in the script where i want that displayed i have this

 

if ($userlevel == '2'){
echo"<a style='color:#666; font-weight: normal;' href='/admin.php'>Admin Control Panel</a>";
}

 

Although Nothing appears :(

Link to comment
https://forums.phpfreaks.com/topic/102947-solved-1-more-problem-last-one/
Share on other sites

You can't use session_register() if you don't have register globals turned on. ( which you shouldn't do ).

 

Rather then session_register, use the global $_SESSION variable. Example

 

<?php
$_SESSION['password'] = $password;
$_SESSION['username'] = $username;
?>

 

 

http://us3.php.net/session_register

 

 

 

ok thanks, i've done this

 

<?php
ob_start();
session_start();
$conn = mysql_connect("localhost","root","");
$db = mysql_select_db("pete");
if(isset($_POST['submit'])) {
$username = htmlspecialchars($_POST['username'], ENT_QUOTES);
$password = htmlspecialchars($_POST['password'], ENT_QUOTES);
$password = ($password);
$username = addslashes($username); 
$password = addslashes($password); 
$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'");
if(mysql_num_rows($sql)>0) {
$_SESSION['password'] = $password;
$_SESSION['username'] = $username;
$sessionid = session_name();
mysql_query("UPDATE users SET sessionid='$sessionid' WHERE username='$username' and password='$password' LIMIT 1");
ob_start();
   exit();
   ob_flush();
header("Location:index.php");   
}

if (mysql_num_rows($sql)>1){
	$row = mysql_fetch_assoc($sql);
	$userlevel = $row['userlevel'];
}
else{
header("Location:login.php");
}
}
ob_flush();
?> 

 

Which still seems to log me in fine :) and with no error :D although its not redirecting me to the index page anymore :S

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.