Default login naam value form
En ik zou graag willen dat de gebruikersnaam automatisch word ingevuld door hun sessie.
Het enigste wat ik geprobeer heb is op dit moment:
Dit werkte naar mijn verwachtingen al niet, ik zou niet weten wat ik moet proberen.
Dit is trouwens de session:
Ik weet niet of ik jullie voldoende informatie geef op dit moment, zoniet post maar een reactie voor wat je nodig hebt!
Alvast bedankt!
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
<?php
// Start a session
session_start();
echo $_SESSION['name'];
require_once ('db_connect.inc.php');
require_once ("functions.inc.php");
?>
// Start a session
session_start();
echo $_SESSION['name'];
require_once ('db_connect.inc.php');
require_once ("functions.inc.php");
?>
Toevoeging op 07/12/2010 17:44:41:
Ik kan er niet uit komen wat ik moet doen.
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
<?php
// Start a session
session_start();
require_once ('db_connect.inc.php');
require_once ("functions.inc.php");
$_SESSION['username'] = $u;
?>
// Start a session
session_start();
require_once ('db_connect.inc.php');
require_once ("functions.inc.php");
$_SESSION['username'] = $u;
?>
Toevoeging op 07/12/2010 18:05:42:
niemand?
Gewijzigd op 07/12/2010 17:45:08 door Chris Broekz
Je wilt hem overnemen:
Maar waarom niet direct?
Code (php)
1
2
3
2
3
<?php
echo '<td><input type="hidden" name="name" id="name" value="' . $_SESSION['username'] . '"></td>';
?>
echo '<td><input type="hidden" name="name" id="name" value="' . $_SESSION['username'] . '"></td>';
?>
Gewijzigd op 07/12/2010 18:48:29 door - SanThe -
SanThe als ik dat doe krijg ik gewoon "Posted By: . $_SESSION['username'] ."
Laat eens de code zien van die regel die jij nu hebt.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<div align="center">
<table border="0" width="370" cellspacing="0" cellpadding="0">
<tr>
<td width="60"> </td>
<?php
echo '<td><input type="hidden" name="name" id="name" value="' . $_SESSION['username'] . '"></td>';
?>
</tr>
<tr>
<td>Smile:</td>
<td>{smilies}</td>
</tr>
<tr>
<td colspan="2">
<textarea cols="40" rows="6" id=commentsbox name="comments"></textarea><br />
<input type="submit" name="submit" value="Add My Comment">
<input type=checkbox name=CNremember id=CNremember value=1><label for=CNremember> Remember Me</label> |
<a href="javascript:CNforget();">Forget Me</a>
</td>
</tr>
</table></div>
<table border="0" width="370" cellspacing="0" cellpadding="0">
<tr>
<td width="60"> </td>
<?php
echo '<td><input type="hidden" name="name" id="name" value="' . $_SESSION['username'] . '"></td>';
?>
</tr>
<tr>
<td>Smile:</td>
<td>{smilies}</td>
</tr>
<tr>
<td colspan="2">
<textarea cols="40" rows="6" id=commentsbox name="comments"></textarea><br />
<input type="submit" name="submit" value="Add My Comment">
<input type=checkbox name=CNremember id=CNremember value=1><label for=CNremember> Remember Me</label> |
<a href="javascript:CNforget();">Forget Me</a>
</td>
</tr>
</table></div>
En in de header heb ik staan.
Code (php)
1
2
3
4
5
6
2
3
4
5
6
<?php
// Start a session
session_start();
require_once ('db_connect.inc.php');
require_once ("functions.inc.php");
?>
// Start a session
session_start();
require_once ('db_connect.inc.php');
require_once ("functions.inc.php");
?>
functions.inc.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
function show_userbox()
{
// retrieve the session information
$u = $_SESSION['username'];
$uid = $_SESSION['loginid'];
// display the user box
echo "<div id='userbox'><br>
<center>Welcome back $u!</center></div>
<div id='container'><br><br><br>
<center> <a href='./logout.php'>Logout </center>
</div>";
}
?>
function show_userbox()
{
// retrieve the session information
$u = $_SESSION['username'];
$uid = $_SESSION['loginid'];
// display the user box
echo "<div id='userbox'><br>
<center>Welcome back $u!</center></div>
<div id='container'><br><br><br>
<center> <a href='./logout.php'>Logout </center>
</div>";
}
?>
en db.connect.inc.php is gewoon mijn DB info.
Toevoeging op 07/12/2010 19:37:19:
$u blijkt alleen te werken bij login.php bij mij.
Als ik bijvoorbeeld
Code (php)
1
2
3
4
5
6
2
3
4
5
6
<?php
// Start a session
session_start();
require_once ('db_connect.inc.php');
require_once ("functions.inc.php");
?>
// Start a session
session_start();
require_once ('db_connect.inc.php');
require_once ("functions.inc.php");
?>
Dit is login.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
if (!session_is_registered('loginid') || !session_is_registered('username'))
{
// user is not logged in.
if (isset($_POST['cmdlogin']))
{
// retrieve the username and password sent from login form
// First we remove all HTML-tags and PHP-tags, then we create a md5-hash
// This step will make sure the script is not vurnable to sql injections.
$u = strip_tags($_POST['username']);
$p = (strip_tags($_POST['password']));
//Now let us look for the user in the database.
$query = sprintf("SELECT acct FROM accounts WHERE login = '%s' AND password = '%s' LIMIT 1;",
mysql_real_escape_string($u), mysql_real_escape_string($p));
$result = mysql_query($query);
// If the database returns a 0 as result we know the login information is incorrect.
// If the database returns a 1 as result we know the login was correct and we proceed.
// If the database returns a result > 1 there are multple users
// with the same username and password, so the login will fail.
if (mysql_num_rows($result) != 1)
{
// invalid login information
echo "Wrong username or password!";
//show the loginform again.
include "loginform.php";
} else {
// Login was successfull
$row = mysql_fetch_array($result);
// Save the user ID for use later
$_SESSION['loginid'] = $row['loginid'];
// Save the username for use later
$_SESSION['username'] = $u;
// Now we show the userbox
show_userbox();
}
} else {
// User is not logged in and has not pressed the login button
// so we show him the loginform
include "loginform.php";
}
} else {
// The user is already loggedin, so we show the userbox.
show_userbox();
}
?>
if (!session_is_registered('loginid') || !session_is_registered('username'))
{
// user is not logged in.
if (isset($_POST['cmdlogin']))
{
// retrieve the username and password sent from login form
// First we remove all HTML-tags and PHP-tags, then we create a md5-hash
// This step will make sure the script is not vurnable to sql injections.
$u = strip_tags($_POST['username']);
$p = (strip_tags($_POST['password']));
//Now let us look for the user in the database.
$query = sprintf("SELECT acct FROM accounts WHERE login = '%s' AND password = '%s' LIMIT 1;",
mysql_real_escape_string($u), mysql_real_escape_string($p));
$result = mysql_query($query);
// If the database returns a 0 as result we know the login information is incorrect.
// If the database returns a 1 as result we know the login was correct and we proceed.
// If the database returns a result > 1 there are multple users
// with the same username and password, so the login will fail.
if (mysql_num_rows($result) != 1)
{
// invalid login information
echo "Wrong username or password!";
//show the loginform again.
include "loginform.php";
} else {
// Login was successfull
$row = mysql_fetch_array($result);
// Save the user ID for use later
$_SESSION['loginid'] = $row['loginid'];
// Save the username for use later
$_SESSION['username'] = $u;
// Now we show the userbox
show_userbox();
}
} else {
// User is not logged in and has not pressed the login button
// so we show him the loginform
include "loginform.php";
}
} else {
// The user is already loggedin, so we show the userbox.
show_userbox();
}
?>
Code (php)
1
<? echo "<td><input type=\"hidden\" name=\"name\" id=\"name\" value=\"".$_SESSION['username']."\"></td>"; ?>
Zo zou je het kunnen doen en zou het moeten lukken.
Mvg Jonathan
Gewijzigd op 07/12/2010 20:35:38 door Jonathan Plas
Posted by: .$_SESSION['username']
Jonathan Plas op 07/12/2010 20:34:28:
Zo zou je het kunnen doen en zou het moeten lukken.
Mvg Jonathan
Code (php)
1
<? echo "<td><input type=\"hidden\" name=\"name\" id=\"name\" value=\"".$_SESSION['username']."\"></td>"; ?>
Zo zou je het kunnen doen en zou het moeten lukken.
Mvg Jonathan
Toevoeging op 08/12/2010 16:52:21:
Niemand die me ff kan helpen?