Staredit Network > Forums > Technology & Computers > Topic: Me again with PHP problem :D
Me again with PHP problem :D
Nov 30 2008, 9:08 pm
By: Devourer  

Nov 30 2008, 9:08 pm Devourer Post #1

Hello

Hi there... first of all: thanks for the support and help
second: I've got 2 small problems again:


#1: In the Input-text is my server address enterd... why? (it's automatly enterd! when i'm opening that page)
#2: Why is there always standing "You are logged in now"? it just should stay there when the password and username is true...
(im talking about my login page)

here is it: login.php

<?php

session_start();

echo "<form action='?act=login' method='post'>"
."Username: <input type='text' name='user' size='30'><br>"
."Password: <input type='password' name='pass' size='30'><br>"
."<input type='submit' value='Login'>"
."</form>"
."</br> <a href=index.php> Index </a>";


$pass = md5($_POST[pass]);
$user = $_POST[user];

//Connecting to database
$connect = mysql_connect("localhost", "browsergamesc", "------------------------------------------------------");
if(!$connect){
die(mysql_error());
}

mysql_select_db("browsergamesc",$connect);

$search = "SELECT * FROM users WHERE username='$user'";
$res = mysql_query($search) OR die(mysql_error());

$check = mysql_fetch_array($res);

if($check[username] == $user && md5($check[password]) == $pass)
{
$_SESSION[login] = TRUE;
$_SESSION['user'] = $user;
$_SESSION['pass'] = $pass;
$_SESSION['geld'] = $check['geld'];
echo "</br>You are now Logged in! <a href=index.php> </br>Back to Index </a>";
}
else
{
echo "</br>";
echo "</br> Wrong username or password";
session_destroy(); }

?>


Help me pls, thanks



Please report errors in the Staredit.Network forum.

Dec 1 2008, 3:21 am Matt Burch Post #2



Code
if($check[username] == $user && md5($check[password]) == $pass)

You store unencrypted passwords in your database? Very insecure.

Code
$pass = md5($_POST[pass]);
$user = $_POST[user];

need to change that to this:
Code
$pass = md5($_POST['pass']);
$user = $_POST['user'];


And...

Code
if($check[username] == $user && md5($check[password]) == $pass)

Need to change that to this:
Code
if($check['username'] == $user && md5($check['password']) == $pass)


It is thinking that those values are variables, which have null in them. Which will result in showing it every time.

Edit:
And in response to your first problem. That is your cache or something. Which browser are you using? (Auto-fill is on?)

Post has been edited 1 time(s), last time on Dec 1 2008, 3:54 am by Matt Burch.



None.

Dec 1 2008, 2:10 pm Devourer Post #3

Hello

Quote from Matt Burch
Code
if($check[username] == $user && md5($check[password]) == $pass)

You store unencrypted passwords in your database? Very insecure.

Code
$pass = md5($_POST[pass]);
$user = $_POST[user];

need to change that to this:
Code
$pass = md5($_POST['pass']);
$user = $_POST['user'];


And...

Code
if($check[username] == $user && md5($check[password]) == $pass)

Need to change that to this:
Code
if($check['username'] == $user && md5($check['password']) == $pass)


It is thinking that those values are variables, which have null in them. Which will result in showing it every time.

Edit:
And in response to your first problem. That is your cache or something. Which browser are you using? (Auto-fill is on?)

The first part I don't understand, sorry
to your help to question2....
it didn't really helped... any other idea?

to your help to question1... Firefox, and if autofill, I don't know, I didn't find anythign about Auto-fill.

and something else, I made a shoutbox with a color-selection... how to color a word INSIDE a selection-option? I tried it and it didn't worked... here is my shoutbox.php

Shoutbox.php
<?php



//This will start a session
session_start();

$username = $_SESSION['user'];
$password = $_SESSION['pass'];
$geld = $_SESSION['geld'];





echo "Welcome ".$_SESSION['user']." (<a href=logout.php>Logout</a> | <a href=members.php> Members</a> | <a href=index.php> Index</a>)";
echo "</br>";
echo "<br>";



$con = mysql_connect("localhost","browsergamesc","----------------------");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("browsergamesc", $con);

$result = mysql_query("SELECT * FROM shoutbox ORDER BY `id2` DESC LIMIT 0 , 5");


while($row = mysql_fetch_array($result))
{
echo "<font color='0000FF'> " . $row['time'] . " </font>- ";
echo "<font color='66FF00'> " . $row['username'] . " </font>- ";
echo "<font color=' " . $row['color'] . " '> ";
echo " " . $row['message'] . " </font> </br>";
}


echo '<form action="insertshout.php" method="post"></br>';
echo '<select name="color" size="">';
echo '<option value="000000"> <font color="000000"> Black </font></option>';
echo '<option value="FF0000"> <font color="FF0000"> Red </font></option>';
echo '<option value="00CC00"> <font color="00CC00"> Green </font></option>';
echo '<option value="0000FF"> <font color="0000FF"> Blue </font></option>';
echo '</select>';
echo ' - ';
echo 'Message: <input type="text" name="message" /> </br>';
echo '<input type="submit" />';
echo '</form>';

?>

Help please :)



Please report errors in the Staredit.Network forum.

Dec 1 2008, 8:52 pm Matt Burch Post #4



Like i said your variables are null:
$check[user] = null;
$pass = null;
$check[pass] = null;
$user = null;

An easier way to fix this is to add some more if statements.

Code
if (count($_POST) > 0)
{
   $pass = md5($_POST[pass]);
   $user = $_POST[user];
}

...
...

$search = "SELECT * FROM users WHERE username='$user'";
$res = mysql_query($search) OR die(mysql_error());

if ($res)
{

   $check = mysql_fetch_array($res);

   if($check[username] == $user && md5($check[password]) == $pass)
   {
       ...
       ...
   }
}




None.

Dec 1 2008, 8:59 pm Devourer Post #5

Hello

Thanks, I'll try it tomorrow, I will edit the post if when I've got results...



Please report errors in the Staredit.Network forum.

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[04:15 am]
DarkenedFantasies -- you eat lots of beans
[03:46 am]
IskatuMesk -- how do i get gas
[11:43 pm]
Moose -- you don't
[10:06 pm]
Zoan -- how do i get minerals
[2026-4-14. : 11:45 pm]
ClansAreForGays -- Anyone wanna played Skewed StarCraft?
[2026-4-14. : 12:07 am]
Vrael -- NudeRaider
NudeRaider shouted: Vrael ranting still is though
you're a gentleman and a scholar, thank you
[2026-4-13. : 10:07 pm]
NudeRaider -- ya why phone people when you can just write letters
[2026-4-13. : 9:37 pm]
IskatuMesk -- I have never and will never own a phone
[2026-4-13. : 9:15 pm]
NudeRaider -- Vrael ranting still is though
[2026-4-13. : 9:14 pm]
ClansAreForGays -- anticapitalism isnt edgy anymore
Please log in to shout.


Members Online: DarkenedFantasies