Jump to content

wizzy886

Members
  • Posts

    25
  • Joined

  • Last visited

About wizzy886

  • Birthday 05/11/1996

Profile Information

  • Gender
    Male

Contact Methods

  • Skype
    harry-traynor

wizzy886's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Interesting - it does work?? Haha well thanks sorry I didn't understand quite what you meant first time round.
  2. Is it because they are essentially different sessions?? As they have been created and viewed on different aspects of the site? Is that possible?
  3. All I wanted was to have the code similar to the original where all the CAPTCHA was in one file and was called. I was echoing it to illustrate that the values of the $_SESSION were incorrect. This is also the true value of the session as even when putting the image version in it doesn't work (the image and session are not the same).
  4. Fixed, but is there any way of getting it to be in the CAPTCHA page??
  5. Sorry let me re word that - I confused myself it seems.. Image displays. Let me run through what it would do. So page loaded with random string of 12345 saved to $_SESSION. The image will display 54321. I refresh the page and then the value of $_SESSION will be 54321 and the image another random value. This random value on the image will then be the $_SESSION value next time i refresh.
  6. Image displays. Let me run through what it would do. So page loaded with random string of 12345 lets say saved to session. The image will display 54321. I refresh the page and then the value of session will be 54321 and the session another random value. The random value seems to always be one step ahead and I have no idea why.
  7. SO I have been developing a log in system and wanted to make my own simple CAPTCHA. I found one on the internet and ported the code across to get started and see how someone had made it. The issue I am having is that the dynamically generated image that I have created it seems is one step ahead of the session variable (the string is generated and then saved into session - then generates the image). But when i echo back the session it is always one step behind the actual image... Anyway here is my code and ask away please <?php require('includes/util.inc.php'); $form = ' <form action="register.php" method="post"> <p>username <input type="text" name="username" id="usrinp"></p> <p>email <input type="text" name="email" id="emainp"></p> <p>password <input type="password" name="password1" id="psw1inp"></p> <p>re-enter password <input type="password" name="password2" id="psw2inp"></p> <p><img src="captcha.php"/></p> <p>captcha <input type="text" name="captcha" id="capinp"></p> <p><input type="submit" value="Register" id="subinp"></p> </form> '; if(isset($_SESSION['captcha'])) { echo $_SESSION['captcha']; } if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['username']) && !empty($_POST['email'])) { if($_POST['captcha'] == $_SESSION['captcha']) { $username = $_POST['username']; $email = $_POST['email']; $password = SHA1($_POST['password1']); $password = SHA1($_POST['password2']); $q = 'SELECT username FROM users WHERE username = :username'; $stmt = $pdo->prepare($q); $stmt->bindParam(':username', $username); $stmt->execute(); if($stmt->rowCount() > 0) { echo "<pre>This username has already been taken</pre>"; } else { $qi = 'INSERT INTO users ( username, password, email ) VALUES ( :username, SHA1(:password), :email )'; $query = $pdo->prepare($qi); $result = $query->execute( array( ':username'=>$username, ':password'=>$password, ':email'=>$email ) ); if($result) { header("location:login.php"); exit; } else { echo '<pre>Error, please try again</pre>'; } } } } $pageTitle = 'Register'; include('includes/header.inc.php'); include('pages/register.html'); ?> <?php require('includes/util.inc.php'); $string = ''; for ($i = 0; $i < 5; $i++) { $string .= chr(rand(97, 122)); } $_SESSION['captcha'] = $string; $font_path = 'includes/fonts/'; $captcha_image = imagecreatetruecolor(150, 60); $text_color = imagecolorallocate($captcha_image, 0, 0, 0); $bg_color = imagecolorallocate($captcha_image, 255, 255, 255); imagefilledrectangle($captcha_image, 0, 0, 399, 99, $bg_color); imagettftext($captcha_image, 30, 0, 10, 40, $text_color, $font_path . "dashdot.ttf", $_SESSION['captcha']); header("Content-type: image/png"); imagepng($captcha_image); ?> <?php session_start(); function class_loader($class) { require 'classes/' . $class . '.class' . '.php'; } spl_autoload_register('class_loader'); $user = (isset($_SESSION['user'])) ? $_SESSION['user'] : null; $cat = (isset($_SESSION['cat'])) ? $_SESSION['cat'] : null; try { $pdo = new PDO('mysql:dbname=phpcat; host=localhost', 'root', ''); } catch (PDOException $e) { $pageTitle = 'Error!'; include('header.inc.php'); include('../pages/error.html'); exit(); }
  8. Thank you did not know this was required but will structure it like that from now on.
  9. Changes made, and still no alert as to what has happened to the data Live version is up btw = http://wytraining.net
  10. So basically I am attempting to make my code work with AJAX also to get rid of the page refreshing to the user. It does physically submit the data to the file and write it how it is supposed to be. However the notifications are not working at all. I am not the best at bug shooting JS stuff as I don't use it a lot - but would be grateful if someone can point out where I am going wrong. <!DOCTYPE html> <html> <head> <meta charset=utf-8 /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <meta name="HandheldFriendly" content="true" /> <link rel="stylesheet" type="text/css" href="css/default.css" /> <script src="scripts/jquery-1.11.1.min.js"></script> <script> $(document).ready(function() { $('#formContainer').submit(function() { var formData = $(this).serialize(); $.post('index.php', formData, processData); function processData(data) { if (data=='1') { $('.form').html('<p>success</p>'); } else if (data=='2') { $('#form').prepend('<p>already exists</p>'); } else if (data=='3') { $('#form').prepend('<p>fail</p>'); } } return false; }); }); </script> <title>WyTraining</title> </head> <body class="background"> <header> <div class="logo"><a href="index.php"><img src="images/logo.png" alt="wyTraining"></a></div> </header> <div class="form"> <div class="title">coming soon</div> <?php /* email entered = 1 */ /* email exists = 2 */ /* email incorrect = 3 */ if($_SERVER['REQUEST_METHOD'] == 'POST') { $trimmed = array_map('trim', $_POST); if(filter_var($trimmed['email'], FILTER_VALIDATE_EMAIL)) { $file = 'data\emails.txt'; if( strpos(file_get_contents($file),$trimmed['email']) == false) { $email = $trimmed['email']; echo '1'; $current = file_get_contents($file); $current .= "$email,\n"; file_put_contents($file, $current); } else { echo '2'; } } else { echo '3'; } } ?> <center><form action="index.php" method="POST" id="formContainer"> <input type="text" name="email" value="" placeholder="enter email to stay updated" autocomplete="off"/> <input type="submit" name="submit" value=" " class="button"/> </form></center> </div> </body> </html>
  11. So i am working on a system to simply log in and out a user. I have a column in the data schema that is called user_level. If this is set to 0 it is a default user, if set to 1 it is an admin, and if set to 2 it is inactive. So i have tried to look up the rows value after a successful login and it doesn't appear to have the result i want. It ignores the users level and logs in anyway. login.php
  12. Sorry, It basically looks like its submitting something (in both registration and login). After this nothing. Ive tried to output the results of the script throughout its process with little luck. The main problems are in registration and login if you could give them a look over please. Im sure its something ive just missed.
  13. So i have the problem where the registration was working before, but now isn't and now it isn't. On top of this the actual login doesn't work either. I honestly don't know what is wrong with it so can i please have some guidance. I have troubleshot all of that I know how to and tried to output any error messages but fail in doing so. Thanks. index.php login.php register.php connection.php footer.php header.php
  14. That's the problem when you copy and paste and don't pay attention. I think I will learn from that. Thanks for your time as its now working.
  15. Have I used the preg_match properly?? As I have wondered if its actually working properly.
×
×
  • 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.