Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Page error due to form
Old 05-13-2005, 03:55 PM Page error due to form
Novice Talker

Posts: 9
Trades: 0
Okay, I've got a weird problem!
I've noticed some members have problems logging in when I edit this page:
PHP Code:
<?php
if(isset($_SESSION['gebruiker'])) {
    
header("Location: ingelogged.php");
}
?>
<form name="form1" method="post" action="">
  <table  border="0">
    <tr>
      <td>Gebruikersnaam:</td>
      <td><input name="gebruikersnaam" type="text" id="gebruikersnaam" size="35" <?php if(isset($_GET['gebruikersnaam'])) { ?>value="<?=$_GET['gebruikersnaam']?>"<?php ?> /></td>
    </tr>
    <tr>
      <td>Wachtwoord:</td>
      <td><input name="wachtwoord" type="password" id="wachtwoord" size="35" /></td>
    </tr>
    <tr>
      <td>Tijd:</td>
      <td><select name="tijd" id="tijd">
        <option value="3600" selected="selected">Een uur</option>
        <option value="86400">Een dag</option>
        <option value="604800">Een week</option>
        <option value="2678400">Een maand</option>
        <option value="32140800">Een jaar</option>
        <option value="32140767859200">Altijd</option>
      </select>
      (cookies vereist) </td>
    </tr>
    <tr>
      <td colspan="2"><input type="submit" name="Submit" value="Inloggen" /></td>
    </tr>
  </table>
  </form>
<?php if(isset($_POST['Submit'])) {
    
$checkg mysql_result(mysql_query("SELECT COUNT(*) FROM leden WHERE gebruikersnaam='".$_POST['gebruikersnaam']."'"),0);
    
$checkp mysql_result(mysql_query("SELECT COUNT(*) FROM leden WHERE gebruikersnaam='".$_POST['gebruikersnaam']."' AND wachtwoord='".$_POST['wachtwoord']."'"),0);
        if(
$_POST['gebruikersnaam'] == "" || $_POST['wachtwoord'] == "") {
            
$error[] = 'Vul alle velden in!';
        }
        if(
$checkg == && $_POST['gebruikersnaam'] != "") {
            
$error[] = 'De ingevoerde gebruikersnaam is niet geregistreerd.';
        }
        if(
$_POST['wachtwoord'] != "" && $_POST['gebruikersnaam'] != "" && $checkp == 0) {
            
$error[] = 'Het ingevoerde wachtwoord is niet correct.';
        }
        
$fouten sizeof($error); // aantal errors tellen
        
if($fouten != 0) { // Er is minstens 1 error
            
echo 'Kan niet inloggen omwille van de volgende reden(en):';
            echo 
'<ul>';
                for(
$i 0$i $fouten$i++) {
                    echo 
'<li>'.$error[$i].'</li>';
                }
            echo 
'</ul>';
        } else {
            
session_start();
            
$res mysql_query("SELECT * FROM leden WHERE gebruikersnaam='".$_POST['gebruikersnaam']."'");
            
$row mysql_fetch_assoc($res);
            
setcookie("gebruikersnaam",$row['gebruikersnaam'],time()+$_POST['tijd']);
            
setcookie("wachtwoord",$row['wachtwoord'],time()+$_POST['tijd']);
            
$_SESSION['gebruiker'] = $row['gebruikersnaam'];
            
$_SESSION['gid']        = $row['id'];
            
header("Location:  index.php");
        }
 } 
?>
This page is working perfectly (everyboddy can log in and a cookie will be set). Now, when I edit the 'tijd' part in the form to this (I've replaced the selected):

Code:
<select name="tijd" id="tijd">
        <option value="3600">Een uur</option>
        <option value="86400" selected="selected">Een dag</option>
        <option value="604800">Een week</option>
        <option value="2678400">Een maand</option>
        <option value="32140800">Een jaar</option>
        <option value="32140767859200">Altijd</option>
      </select>
Now, when I've only edited this part of the page (yes I'm sure only this part), there will be no cookie setted, and so nobody can log in! I think this is extremely weird!
Frederic is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-14-2005, 05:56 AM
OmuCuSucu's Avatar
Vi Veri Veniversum Vivus

Posts: 1,168
Name: Dragos-Valentin
Location: Cluj-Napoca, RO
Trades: 0
if that is all you did than probably there is no value sent for tijd. i think the $_POST['tijd'] that you use in setcookie is 0 or null ...

test first and check the value of $_POST['tijd'] and see what it is ... i may be completely off here...
__________________
.
» Please remember to add to my Talkupation if you enjoyed my post. Thank you :)
.
OmuCuSucu is offline
Reply With Quote
View Public Profile
 
Old 05-14-2005, 09:23 AM
Novice Talker

Posts: 9
Trades: 0
I've now edited the page like this:
PHP Code:
<?php
if(isset($_SESSION['gebruiker'])) {
    
header("Location: ingelogged.php");
}
?>
<form name="form1" method="post" action="">
  <table  border="0">
    <tr>
      <td>Gebruikersnaam:</td>
      <td><input name="gebruikersnaam" type="text" id="gebruikersnaam" size="35" <?php if(isset($_GET['gebruikersnaam'])) { ?>value="<?=$_GET['gebruikersnaam']?>"<?php ?> /></td>
    </tr>
    <tr>
      <td>Wachtwoord:</td>
      <td><input name="wachtwoord" type="password" id="wachtwoord" size="35" /></td>
    </tr>
    <tr>
      <td>Tijd:</td>
      <td><input type="hidden" value="32140767859200" name="tijd" id="tijd"/>
      (cookies vereist) </td>
    </tr>
    <tr>
      <td colspan="2"><input type="submit" name="Submit" value="Inloggen" /></td>
    </tr>
  </table>
  </form>
<?php if(isset($_POST['Submit'])) {
echo 
$_POST['gebruikersnaam']."<br />";
echo 
$_POST['wachtwoord']."<br />";
echo 
$_POST['tijd'];
 } 
?>
And all 3 the values are being echo'd like they should, with the correct values!
Frederic is offline
Reply With Quote
View Public Profile
 
Old 05-14-2005, 12:22 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
I'm assuming it's still not working??

Isn't the second parameter of the setcookie() supposed to be enclosed in "" ? Also, try changing the $_POST['tijd'] into a normal variable, so just before you use setcookie() put it into $expire or something, like this:

PHP Code:
$usersname $_POST['gebruikersnaam'];
$expire $_POST['tijd'];
setcookie("gebruikersnaam""$usersname"time()+$expire); 
I'm not 100% this will work, but give it a try anyway, it won't hurt!
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 05-14-2005, 01:40 PM
Novice Talker

Posts: 9
Trades: 0
Hmm, if I use the code like this everythings works correct:
PHP Code:
<?php
if(isset($_POST['Submit']) && (preg_match("/^[-_0-9a-z]{2,}$/i"$_POST['gebruikersnaam'])) && (preg_match("/^[-_0-9a-z]{2,}$/i"$_POST['wachtwoord']))) {

            
$res mysql_query("SELECT * FROM leden WHERE gebruikersnaam='".$_POST['gebruikersnaam']."' && wachtwoord='".$_POST['wachtwoord']."'");
            if (
$row mysql_fetch_assoc($res)){
            
session_start();
            
setcookie("gebruikersnaam","".$row['gebruikersnaam']."",time()+32140760);
            
setcookie("wachtwoord","".$row['wachtwoord']."",time()+32140760);
            
$_SESSION['gebruiker'] = $row['gebruikersnaam'];
            
$_SESSION['gid'] = $row['id'];
            
header("Location: index.php?Pagina=berichten");
            }
            else{
            echo 
"Error, please check your data!";
            }
 } 
?>
Does this looks safe, the way I'm doing it now?
Frederic is offline
Reply With Quote
View Public Profile
 
Old 05-14-2005, 02:29 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
Yeah that'll work fine, there is no real security in cookies. What i would suggest is storing the users password in the SQL as an MD5 hash, and storing it in the cookie as an MD5 hash also, this means its a little more secure.

You can then match both the hash numbers up (they will be identical if the same password is used) everytime u wish to check the password is correct.
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 05-14-2005, 06:31 PM
Novice Talker

Posts: 9
Trades: 0
OK, I've edited everything to a MD5 hash! Thanks a lot guys!
Frederic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Page error due to form
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.83780 seconds with 12 queries