Jump to content

Barand

Moderators
  • Posts

    24,425
  • Joined

  • Last visited

  • Days Won

    806

Posts posted by Barand

  1. A couple of methods spring to mind

    1 ) toggle the value between 0 and 1 ...

    UPDATE tableZ
    SET x = CASE 
                WHEN x = 1 THEN 0 
                ELSE 1
            END;

       or

    UPDATE tableZ
    SET x = (x = 0);

     

    2 ) set it based on the time

    UPDATE tableZ
    SET x = HOUR(NOW()) MOD 2;

    Of course the queries may need a WHERE clause unless you want to apply the change to every record in tableZ.

  2. As @mac_gyver said, when the user registers, create a hash of their password using password_hash() and store that hash value, not the plain-text value.

    You then verify the password hash using password_verify() (See line 36 in the code)

    That being said, my test table for the code below is ...

    CREATE TABLE `sam_user` (
      `user_id` int(11) NOT NULL AUTO_INCREMENT,
      `eml` varchar(50) DEFAULT NULL,
      `pass` varchar(120) DEFAULT NULL,
      `type` varchar(10) NOT NULL DEFAULT 'user',
      PRIMARY KEY (`user_id`),
      UNIQUE KEY `idx_sam_user_eml` (`eml`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    +---------+---------------+--------------------------------------------------------------+-------+
    | user_id | eml           | pass                                                         | type  |
    +---------+---------------+--------------------------------------------------------------+-------+
    |       1 | curly@abc.com | $2y$10$OKAmeyWZpKJcg/VgPAcx3uQr7R1KF23pPZFapmOmn0BhnWLqqVAP6 | user  |
    |       2 | larry@abc.com | $2y$10$NeqCtTFo79wxGyAacPJLbeyU7Er4hPKrjwZv1G/Vr6YgHV/vnV9.6 | std   |
    |       3 | mo@abc.com    | $2y$10$6TBuStg179rLeMOm2URoNuwEOseYyOIXEVTvbwq7x9G5c9Jw0Bxoi | admin |
    +---------+---------------+--------------------------------------------------------------+-------+

     

    This is my version of your code ...

    <?php
        session_start();
        include 'db_inc.php';                            // database credentials and custom pdoConnect function
        $db = pdoConnect('test');                        // connect to DB 'test' using PDO
        
        // DEFAULT FORM VALUES
        $eml = '';
        $pass = '';
        $messages = '';
        
        // HAS FORM DATA BEEN POSTED?
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $post = array_map('trim', $_POST);
            $eml = $post['eml'] ?? '';
            $pass = $post['pass'] ?? '';
            
            $errors = [];
            
            if ($post['eml']=='') {
                $errors[] = 'You must enter your email address';
            }
            if ($post['pass']=='') {
                $errors[] = 'You must enter your password';
            }
            $stmt = $db->prepare("SELECT user_id
                                       , pass
                                       , type
                                  FROM sam_user
                                  WHERE eml = ?
                                ");
            $stmt->execute([$post['eml']]);
            $row = $stmt->fetch();
            if (!$row) {
                $errors[] = "Invalid login request";
            } else {
                if (!password_verify($post['pass'], $row['pass'])) {                //  verify the hashed password
                    $errors[] = "Invalid login request";
                }
            }
            if (!$errors) {
                $_SESSION['user'] = $row['user_id'];
                $qdata = [];
                switch ($row['type']) {
                    case 'admin':
                        $page = 'wel.php';
                        $qdata['msg'] = 'Administrator successfully logged in';
                        break;
                    case 'std':
                        $page = 'mod.php';
                        $qdata['msg'] = 'Moderator successfully logged in';
                        break;
                    default:
                        $page = 'sim.php';
                        $qdata['msg'] = 'User successfully logged in';
                        break;
                }
                $qstr = http_build_query($qdata);
                $url = "{$page}?{$qstr}";
    //          header("Location: $url");                                         // uncomment in production version
                echo $url;                                                        // TESTING ONLY
                exit;
            }
            else {
                unset($_SESSION['user']);
                $messages = "<div class='errors'>" . join('<br>', $errors) . "</div>\n";
            }
        }
    ?>
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="content-language" content="en">
    <meta charset="utf-8">
    <title>Example Login</title>
    <style type="text/css" media="screen">
        body  { font-family: calibri, sans-serif; font-size: 12pt; }
        header { padding: 25px; text-align: center; background-color: #2DABE1; color: #FFF;}
        label { width: 100px; height: 40px; font-weight: 600; display: inline-block; }
        fieldset { width: 300px; margin: 100px auto; padding: 20px; }
        .errors  { width: 300px; background-color: #E02222; color: #FFF; margin: 0 auto; padding: 20px;}
    </style>
    </head>
    <body>
        <header>
            <h1>Example Login</h1>
        </header>
        <form action="" method="post">
            <fieldset>
                    <label>Email</label><input type="text" name="eml" value='<?=$eml?>'><br>
                    <label>Password</label><input type="password" name="pass" value='<?=$pass?>'><br>
                    <label>&nbsp;</label><input type="submit" name="sb" value='Log In'>
            </fieldset>
        </form>
        <?=$messages?>
    </body>
    </html>
  3. 24 minutes ago, phppup said:

    I am starting with File A and altering it and overwriting it as File A again. 

    Then it sounds like your rotation function is the same as you posted earlier - yes?

    $filename = '/images/myphoto.jpg';
    
    $exif = exif_read_data($filesname);
    echo '<pre>BEFORE: ' . print_r($exif, 1) . '</pre>';
    
    correctImageOrientation($filename);
    
    $exif = exif_read_data($filesname);
    echo '<pre>AFTER: ' . print_r($exif, 1) . '</pre>';

     

  4. You start with FileA. You rotate it and store it in FileB.

    If you now output the exif data for FileA then of course it's the same. You need to get the exif from FileB to see changes (but there won't be much exif data there)

  5. 1 hour ago, benanamen said:

    Why do you have duplicate table structures? This points to a design flaw.

    Not necessarily

    TABLE customer               TABLE customer_order
    +--------------+             +------------------+
    | customer_id  |             | order_no         |
    | cust_name    |             | order_date       |
    | address      |             | customer_id      |
    +--------------+             | deliver_to       |
                                 +------------------+ 
    
    SELECT cust_name
         , order_no
         , order_date
         , COALESCE(deliver_to, address) as deliver_to
    FROM customer_order o 
            JOIN
         customer c USING (customer_id)   

     

×
×
  • 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.