Jump to content

Recommended Posts

Hey, I have got the inbox, the send message working. However on the reading messages I am having problems.

 

read_message.php?messageid=23

This is the URL to the page.

 

<?php

include("include/session.php");

$userfinal=$_SESSION['username'];

$user=$userfinal;

$messageid = $_GET['messageid'];

 

$res=mysql_query("SELECT * FROM messages WHERE message_id = '$message_id' AND to_user = '$user'");

 

while($row=mysql_fetch_assoc($res)){

 

$fromuser=$row['from_user'];

$title=$row['message_title'];

$contents=$row['message_contents'];

?>

<table>

<tr><td><?echo "$fromuser\n";?></td></tr>

<tr><td><?echo "$title\n";?></td></tr>

<tr><td><?echo "$contents\n";?></td></tr>

<tr><td><?echo "<br />\n";?></td></tr>

</table>

 

<?

echo '<form name="backfrm" method="post" action="inbox.php">';

echo '<input type="submit" value="Back to Inbox">';

echo '</form>';

?>

 

That is the code for the reading of the messages.

Can anyone see a problem? Thankyou

Link to comment
https://forums.phpfreaks.com/topic/165169-solved-msg-system/
Share on other sites

Do you get any error messages? What is the output you get? Are you sure there are any records at all?

 

what do you mean you can see more problems?

 

try:

 

read_message.php?messageid=1' OR 1=1--

 

Which gives:

 

SELECT * FROM messages WHERE message_id = '1' OR 1=1--' AND to_user = 'someusername'

 

Oh! look at that: Each and every message in the database ;)

Link to comment
https://forums.phpfreaks.com/topic/165169-solved-msg-system/#findComment-870953
Share on other sites

I know this topic says solved, but I just had to jump in and mention that, as ignace was trying to point out, there is zero security in this script. :-\

 

Also, in your first post the variables don't match the query statment.

 

Changing this...

$userfinal=$_SESSION['username'];
$user=$userfinal;
$messageid = $_GET['messageid'];

 

to the following would be much safer/better.

 

$user=$_SESSION['username'];
$message_id = trim($_GET['messageid']);
if(!is_numeric($message_id)){
die("Sorry, but that's not a proper message id!");
}

 

This way, your database is better protected and the rest of your code works as written. :D

Link to comment
https://forums.phpfreaks.com/topic/165169-solved-msg-system/#findComment-871015
Share on other sites

Yeah that's true ignace. ;D But I figured using the if statement would make it easier for them to adapt code to other security issues.

 

And trim just makes it so there's no whitespace around the variable, complusive habit of mine to add it in. :P

 

Good luck with your site onthespot. :)

Link to comment
https://forums.phpfreaks.com/topic/165169-solved-msg-system/#findComment-871033
Share on other sites

And trim just makes it so there's no whitespace around the variable, complusive habit of mine to add it in. :P

 

It trims more then just whitespace (if the second parameter is left out):

*    " " (ASCII 32 (0x20)), an ordinary space.
* "\t" (ASCII 9 (0x09)), a tab.
* "\n" (ASCII 10 (0x0A)), a new line (line feed).
* "\r" (ASCII 13 (0x0D)), a carriage return.
* "\0" (ASCII 0 (0x00)), the NUL-byte.
* "\x0B" (ASCII 11 (0x0B)), a vertical tab.

 

It's worth noting that you can also add your own characters:

print trim('adbecfa', 'cab'); // dbecf

Link to comment
https://forums.phpfreaks.com/topic/165169-solved-msg-system/#findComment-871081
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.