Jump to content

Help with login system, please


chandler

Recommended Posts

Hi, im getting alot of errors like so Deprecated: Function session_is_registered() is deprecated

 

time to update some files, can you guys pls help im rubbish with PHP guess thats why I waited so long to update.

 

here is the code I need to change

checklogin.php

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:index.php");
}

 

 

index.php

<?
session_start();
/*if(!session_is_registered(myusername)){
header("location:main_login.php");
}*/
?>

 

index.php (display username stuff)

<?php if(session_is_registered(myusername)){ ?>   Welcome: <?= $_SESSION['myusername'] ?><?php } ?>

 

index.php (edit content stuff)

<?php $file = file_get_contents('content/menu_header_a.txt', 'r');  if(session_is_registered(myusername)){ ?><a href="javascript:open4()"><?php echo $file ?></a><?php } else { echo $file; }?>

 

Many thanks for any and all your help with this one.

 

if you could keep it simple please like  ( replace this with this ) :) . thanks

 

Link to comment
https://forums.phpfreaks.com/topic/216576-help-with-login-system-please/
Share on other sites

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['myusername'] = $myusername;
$_SESSION['mypassword'] = $mypassword;
header("location:index.php");
}

 

<?php
session_start();
if(!isset($_SESSION['myusername'])){
header("location:main_login.php");
}
?>

 

<?php 
if(isset($_SESSION['myusername'])) { ?>   Welcome: <?= $_SESSION['myusername'] ?><?php } ?>

 

<?php 
$file = file_get_contents('content/menu_header_a.txt', 'r');  
if(isset($_SESSION['myusername'])){ ?><a href="javascript:open4()"><?php echo $file ?></a><?php } else { echo $file; }?>

I spoke to soon, I am having problems with this part, I only want to have to login to edit content I dont want to have to login just to view the page,

but when I use this it keeps directing me to main_login.php

 

<?php
session_start();
if(!isset($_SESSION['myusername'])){
header("location:main_login.php");
}
?>

 

thanks for your help.

index.php

<?php
session_start();
/*if(!isset($_SESSION['myusername'])){ (I have tried this with and with out /* */ )
header("location:main_login.php");
}*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
<script type="text/javascript" src="js/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="js/content.js"></script>
    <title>Table_Menu</title>
<script type="text/javascript" src="jquery-1.2.3.js"></script>      
<script language="javascript">
function logout()
{
alert("You are now logged out.");
}
</script>	
</head>
<body>
<div class="wrap">
<div class="header"></div>
<div id="navi"></div>
<span id="access">
<a href="main_login.php">Login</a> |
<a href="logout.php" onclick="logout();">Logout</a>
<?php if(isset($_SESSION['myusername'])) { ?>   Welcome: <?= $_SESSION['myusername'] ?><?php } ?></span>
<div class="content">
    <table id="report">
        <tr>
            
		<th>header</th>
		<th></th>
		<th class="menu_header"><?php $file = file_get_contents('content/menu_header_a.txt', 'r');  if(isset($_SESSION['myusername'])){ ?><a href="javascript:open4()"><?php echo $file ?></a><?php } else { echo $file; }?></th>

        </tr>
        
        <tr>
            <td colspan="5">
                <h4>Additional information</h4>
                <ul>
			<li></li>
                 </ul>   
            
            </td>
        </tr>
    </table>
</div><!--  end content -->
</div> <!--  end wrap -->
</body>
</html>

 

logout.php

<?php
session_start();
session_destroy();
header("location:index.php");
?>

 

checklogin.php

<?php
ob_start();
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['myusername'] = $myusername;
$_SESSION['mypassword'] = $mypassword;
header("location:index.php");
}
else {
echo "Wrong Username or Password";
}

ob_end_flush();

?>

 

Thanks!

You should be developing with display_errors = On, and error_reporting = E_ALL in your php.ini file

checklogin.php doesn't have a call to session_start(). Is that a standalone script, or does it get include()d in another script?

Don't use stripslashes() on form data without first checking to see if magic_quotes_gpc = On (although it's better to disable magic_quotes_gpc, IMO)

You don't have any logic in place to make sure the query executed successfully before trying to use mysql_num_rows()

 

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.