ignace
Moderators-
Posts
6,457 -
Joined
-
Last visited
-
Days Won
26
Everything posted by ignace
-
Add an extra column to your users table of type timestamp and upon registration: INSERT INTO users SET registration_date = NOW(), expiration_date = DATE_ADD(NOW(), INTERVAL 1 MONTH), ..registration data Then when a user logs in: <?php if (date('U', $row['expiration_date']) > time()) { // expired // expiration logic } ?>
-
login_form.php <?php require_once('csrf.php'); ?> <?php if (!empty($_GET['errors'])): ?> <ul> <li><?php print implode("</li>\n\t<li>", explode(';', $_GET['errors'])); ?></li> </ul> <?php endif; ?> <form action="login_process.php" method="post"> <input type="hidden" name="csrf" value="<?php print $_SESSION['csrf']; ?>"> <label>Username: <input type="text" name="username"></label> <label>Password: <input type="password" name="password"></label> <input type="submit" value="Login"> </form> login_process.php <?php error_reporting(0); // set to E_ALL if under development ini_set('display_errors', FALSE); // set to TRUE if under development if (!empty($_POST)) { if (empty($_POST['csrf'])) { session_destroy(); header('Location: login_form.php'); } $csrf = $_POST['csrf']; if (!strcmp($csrf, $_SESSION['csrf']) || $_SESSION['csrf_ttl'] < time()) { session_destroy(); header('Location: login_form.php'); // re-creates the session and the csrf } $username = htmlentities($_POST['username']); $password = htmlentities($_POST['password']); $errors = array(); if (!ctype_alnum($username)) { $errors[] = 'Username should only contain alphanumeric characters'; } if (sizeof($errors)) { $errors = implode(';', $errors); header("Location: login_form.php?errors=$errors"); } require_once('connect2db.php'); $query = 'SELECT * FROM users WHERE username=\'%s\' AND password=sha1(\'%s\')'; $fquery = sprintf($query, $username, $password); $result = mysql_query($fquery, $db); $total_result_rows = mysql_num_rows($result); if ($total_result_rows === 1) { require_once('getip.php'); require_once('sessions.php'); $_SESSION['username'] = $username; $_SESSION['userip'] = sha1(getip()); $_SESSION['useragent'] = sha1($_SERVER['HTTP_USER_AGENT']); } else {// 0: username, password match not found; 1+: multiple matches found, ambiguous $errors = 'Username and/or password are incorrect'; header("Location: login_form.php?errors=$errors"); } } else { header('Location: login_form.php'); } ?> verify_login.php <?php require_once('getip.php'); require_once('sessions.php'); if (!empty($_SESSION['useragent']) && (!strcmp($_SESSION['useragent'], sha1($_SERVER['HTTP_USER_AGENT'])) || !strcmp($_SESSION['userip'], sha1(getip()))) { // 1: same session, different browser? 2: ip changed? session_destroy(); header('Location: login_form.php'); } ?> Then on your login protected pages: <?php require_once('verify_login.php'); //protected page content ?>
-
Right and then he will be coming back asking why he gets: Notice: Undefined index: user Notice: Undefined index: rank Or why after he logs in he is being redirected to the login after going to a login protected page.
-
$PHPSESSID = session_id(); after session_start();
-
<?php $i = 0; $cities_per_column = 500; print '<table><tr>'; while ($row = @mysql_fetch_assoc($result)){ print '<td><a href="page.html">', strtr($row['city'],$arr) ,'</a></td>'; ++$i; if (!($i % $cities_per_column)) { print '</tr><tr>'; } } print '</tr></table>'; ?> Creates columns of each 500 cities.
-
1) resize the image using a resizing script 2) use the width and height attributes of the img element Technically we can't help you on this one as this is html/css related and we are talking php here It's not padding but margin. Add a style attribute with the margin defined (like so: <img style="margin: .." ..>) If this doesn't work you may need to modify the display setting (<img style="margin: ..; display: block" ..>.
-
[SOLVED] difference btw insert record and inserting fields
ignace replied to ilikephp's topic in PHP Coding Help
Depends on what you want to do. If you need an input field on your website you need the text field. If you on the other hand want to expand your current stored data (for example add a new user directly to your database) you insert a new record. -
Depends on what you want in the first column and what you want in the second column. You may need to create a separate query for this to work.
-
[SOLVED] upload file, rename, and restrict size.
ignace replied to adamlacombe's topic in PHP Coding Help
$ttarget2 = $ttarget1 . $_SESSION['id'] . '.jpg'; Note the . before jpg -
SELECT * FROM crackz WHERE (name = '$name' OR name LIKE '%$name%') AND (type = 'Games' OR type = 'Movies')
-
[SOLVED] difference btw insert record and inserting fields
ignace replied to ilikephp's topic in PHP Coding Help
A text field is a piece (single-line text entry) of a form. A record is one row of a (db) table. -
Sorry I made a mistake. My suggested solution was a second row instead of a second column. This code now creates a second column. <table style="width: 630px"> <tbody> <tr> <td style="height: 500px"> <div style="width: 50%; height: 100%; overflow: auto;"> <ul> <?php foreach ($datacol1 as $value) { print "<li>$value</li>"; } ?> </ul> </div> </td> <td> <div style="width: 50%; height: 100%; overflow: auto;"> <ul> <?php foreach ($datacol2 as $value) { print "<li>$value</li>"; } ?> </ul> </div> </td> </tr> </table>
-
I mean your tables (name + columns)
-
connect to database first? Edit: Nevermind, got it. I thought mysql_real_escape_string() could operate independently of a db connection.
-
<table style="width: 630px"> <tbody> <tr> <td style="height: 500px"> <div style="width: 50%; height: 100%; overflow: auto;"> <ul> <li><a href="/VT/Adamant.html">Adamant, VT</a></li> <li><a href="/VT/Albany.html">Albany, VT</a></li> <li><a href="/VT/Alburg.html">Alburg, VT</a></li> <li><a href="/VT/Arlington.html">Arlington, VT</a></li> <li><a href="/VT/Ascutney.html">Ascutney, VT</a></li> </ul> </div> </td> </tr> <!-- second column --> <tr> <td style="height: 500px"> <div style="width: 50%; height: 100%; overflow: auto;"> <ul> <li><a href="/VT/Adamant.html">Adamant, VT</a></li> <li><a href="/VT/Albany.html">Albany, VT</a></li> <li><a href="/VT/Alburg.html">Alburg, VT</a></li> <li><a href="/VT/Arlington.html">Arlington, VT</a></li> <li><a href="/VT/Ascutney.html">Ascutney, VT</a></li> </ul> </div> </td> </tr> </tbody> </table>
-
Use a table if it's tabular data.
-
$id = empty($_POST['id']) ? 'NULL' : $_POST['id'];
-
You are using the wrong html element. If you want to work with columns you need a table.
-
Wrong section. Here's a cheat sheet: http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/