Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.