Current location: Hot Scripts Forums » Programming Languages » PHP » Security Issue!


Security Issue!

Reply
  #1 (permalink)  
Old 04-12-04, 02:27 PM
D_tunisia D_tunisia is offline
Newbie Coder
 
Join Date: Apr 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Security Issue!

I've written this code:

PHP Code:

<html>


<body>

<?php

include ("dbConfig.php");

mysql_select_db("ittechni_main");

// display individual record

if ($id) {

   
$result mysql_query("SELECT * FROM posts WHERE id=$id");

   
$myrow mysql_fetch_array($result);

   
printf("Title: %s\n<br>"$myrow["title"]);

   
printf("Text: %s\n<br>"$myrow["text"]);

} else {

    
// show employee list

   
$result mysql_query("SELECT * FROM posts");

    if (
$myrow mysql_fetch_array($result)) {

      
// display list if there are records to display

      
do {

        
printf("<a href=\"%s?id=%s\">%s %s</a><br>\n"$PHP_SELF$myrow["id"], 

$myrow["title"], $myrow["text"]);

      } while (
$myrow mysql_fetch_array($result));

    } else {

      
// no records to display

      
echo "Sorry, no records were found!";    

    }

}



?>



</html>
The code displays a posted message from a news script which is linked from a members area. The issue I have though is that, with the code in its present form, it means that someone could type in the URL with the ?=$postid and modify someone elses post.

Do you guys know of a way to ensure that only the user who posted the message can modify it?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 04-12-04, 03:13 PM
Frank Frank is offline
Newbie Coder
 
Join Date: Apr 2004
Location: Montreal, Canada
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
You can check if the username and password saved in the session or cookie matches the ones saved in the database and then print the data.


You can add this after "if ($id) {" and then modify your code to make it work with my code.

PHP Code:

$query_user mysql_query("SELECT * FROM users"); // choose your user table

$check_user mysql_fetch_array($query_user);

if ((
$check_user['username'] == $_SESSION['username']) && ($check_user['password'] == $_SESSION['password'])) {

echo 
'you\'re in members\' section, smile!';

} else {
    echo 
'You are not yet a member!';
    } 

Frank
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
php or apache issue? lokey PHP 7 03-08-04 11:55 PM
How to supress security prompt in Mozilla browser rameshreddy74 JavaScript 0 01-13-04 11:53 PM
popping up the security box when accessing a php script andreas66 PHP 2 11-19-03 10:34 AM
PHP scripts security khibinite PHP 2 10-23-03 06:13 AM
image identification security system for home PC? LuNa The Lounge 0 10-21-03 11:03 PM


All times are GMT -5. The time now is 10:26 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.