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
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; }?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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()

 

Link to comment
Share on other sites

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.