Jump to content

Recommended Posts

Hello everyone sorry before hand if this because a long post but i really do need so help as i have only been working with PHP for a few weeks now. my university project this year is to create a forum and include all features such as a moderator , being able to post, view and delete topics.

 

so here is my problem so far i have created a logging script which works fine as i have been following a tutorial on how to get this working what i'm trying to do is get the usersid and send it to the next page (login_success.php) to tell if this user is a moderator.

 

checklogin.php:-

 


<<?php

ini_set( 'display_errors', '1' );
error_reporting( E_ALL | E_STRICT );  

ob_start();
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // 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=mysql_escape_string($_POST['myusername']); //edited 12/27/07
$mypassword=mysql_escape_string($_POST['mypassword']); 


$sql="SELECT * FROM $tbl_name WHERE username = '$myusername' and password = '$mypassword'";  
$result=mysql_query($sql);

$id_result ="SELECT id FROM $tbl_name WHERE username = '$myusername'and password = '$mypassword'"; 
$id=mysql_query($id_result);


// 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)
{
    session_register("myusername");
    session_register("mypassword");

    
    
    header("location:login_success.php?id=$id");

}
    else 
    {
        
    echo "Wrong Username or Password";

    }

ob_end_flush();

?>

 

login_success.php

 


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

<html>
<body>


</body>
</html>

<?

echo "you are logged in as: ",$_SESSION[myusername];
$id = intval( $_GET['id'] );
echo $id; //echo for testing 

?>

 

Thanks James

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/83626-php-forum-need-help/
Share on other sites

I hope they are teaching you to code with Register Globals Off.

 

The User ID shouldn't tell the script if they are a Moderator, there should be some sort of access level in the user table instead.

 

Also, no need to do two sql queries when your first query gets the ID as well, since you are doing a SELECT *.

 

Make sure you put session_start(); at the top of your login_success.php page, and use

 

$_SESSION['myusername'] = $myusername;

$_SESSION['mypassword'] = $mypassword;

 

instead of

 

session_register("myusername");

session_register("mypassword");

 

Not really sure why you need the PW in a session though.  You should add one more session from the user table for their access level, and then you can check that on each page or action that requires a certain access.

 

Link to comment
https://forums.phpfreaks.com/topic/83626-php-forum-need-help/#findComment-425418
Share on other sites

Thank you for the fast reply

 

"The User ID shouldn't tell the script if they are a Moderator, there should be some sort of access level in the user table instead".

 

how to i go about doing this? sorry to ask so much but i'm on a major learning curve i have changed my code to what you recommended

 

Thanks

James

Link to comment
https://forums.phpfreaks.com/topic/83626-php-forum-need-help/#findComment-425422
Share on other sites

You are already getting all the info here

 

$sql="SELECT * FROM $tbl_name WHERE username = '$myusername' and password = '$mypassword'"; 

 

You'll want to do a mysql_fetch command on this and turn the resource into either an array or object.

Link to comment
https://forums.phpfreaks.com/topic/83626-php-forum-need-help/#findComment-425462
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.