Jump to content

wizzy886

Members
  • Posts

    25
  • Joined

  • Last visited

Everything posted by wizzy886

  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.
  16. Sorry I mean to say that by what I can still see after that change its still not working.
  17. Ahh yes thanks. However I still think its not working. Any other ideas?
  18. No errors are displayed and no records are entered. I cannot really say much more as its not even displaying errors. So I'm of the impression it might be how I've structured it or something?
  19. Here is the code for both the connection file and the main body of script. I assure you the passwords and actual names do match as I have done other tests before hand. register.php <?php $title = "Register"; include 'includes/header.php'; if($_SERVER['REQUEST_METHOD'] == 'POST') { require 'includes/connection.php'; //create FALSE figures $username = $password = FALSE; //trim all data $trimmed = array_map('trim', $_POST); $errors = array(); //check username if(preg_match ('/[A-Za-z0-9]{2,20}/', $trimmed['username'])) { $username = mysqli_real_escape_string($dbc, $trimmed['username']); } else { $errors[] = 'Enter a username'; } //check password if(preg_match ('/[A-Za-z0-9]{4,20}/', $trimmed['password'])) { $username = mysqli_real_escape_string($dbc, $trimmed['password']); } else { $errors[] = 'Enter a password'; } //variables not == FALSE if($username && $password) { $q = "SELECT user_id FROM users WHERE username='$username'"; $r = mysqli_query ($dbc, $q) OR trigger_error("Query: $q\n<br />MYSQL Error: ". mysql_error($dbc)); if(mysqli_num_rows($r) == 0) { $q = "INSERT INTO users (username, password, registration_date) VALUES ('$username', SHA1('$password'), NOW() )"; $r = mysqli_query ($dbc, $q) OR trigger_error("Query: $q\n<br />MYSQL Error: ". mysql_error($dbc)); } if(mysqli_affected_rows($dbc) == 1) { echo "success"; //header('Location: database.php'); } } else { foreach ($errors as $msg) { echo " - $msg<br />\n"; } } } ?> <form action="register.php" method="POST"> <input type="text" name="username" value="<?php if(isset($trimmed['username'])) echo $trimmed['username']; ?>" placeholder="Username"/> <input type="password" name="password" value="<?php if(isset($trimmed['username'])) echo $trimmed['password']; ?>" placeholder="Password"/> <input type="submit" class="button1" name="Sign Up" /> </form> connection.php <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'password'; $db = 'ze'; $dbc = mysqli_connect($dbhost, $dbuser, $dbpass) OR die ('Could not connect. MYSQL:' .mysql_error() ); mysql_select_db($db); Whenever I run this it does not seem to want to work, and also outputs no errors. I probably cant see something and need a second opinion.
  20. <?php $page_title = "Calculating Profit"; include ('includes/header.php'); $pnd = "&pound"; $answer = $_POST['answer']; if (!defined($income && $costs)) { $income= number_format(rand(50, 30000),1); $costs= number_format(rand(100, 20000),1); } else { if (empty($_POST['submitted_income' && 'submitted_costs'])) { $_POST['submitted_income'] = $income; $_POST['submitted_costs'] = $costs; } } ?> <div id="spacer"></div> <div id="title" class="text1"><h1><?php echo $page_title ?></h1></div> <div id="spacer"></div> <div id="question" class="text2"> <p>If a company makes a total turnover of <?php echo $pnd.$income; ?> and all the costs come to <?php echo $pnd.$costs; ?>.</p> <p>What is the total profit made by this company?</P> <?php $profits= number_format($_POST['submitted_income'] - $_POST['submitted_costs'], 1); if (!empty($_POST['answer'])) { number_format($answer, 1); if ($answer == $profits) { echo '<div class="correct"></div>'; } else { echo '<div class="incorrect"></div>'; } } else { $answer = NULL; echo "Enter in your answer below."; } ?> </div> <div id="spacer"></div> <div id="submit_box"> <form action="profit_calc.php" method="POST" name="form"> <input type="text" size="12" name="answer"> <div id="input_submit"><input type="submit" name="submit" value="SUBMIT"></div> <input type="hidden" name="submitted_income" value="<?php echo $_POST['submitted_income']; ?>"> <input type="hidden" name="submitted_costs" value="<?php echo $_POST['submitted_costs']; ?>"> </form> </div> <script type="text/javascript" language="JavaScript"> document.forms['form'].elements['answer'].focus(); </script> <?php include ('includes/footer.php'); ?> So I have written this and still no success. I am new to using this hidden form part, and wondered what I am doing and why it is wrong?
  21. Now thats clever. I will have a shot at it. Thanks for quick reply.
  22. profit_calc.php <?php $page_title = "Calculating Profit"; include ('includes/header.php'); $pnd = "&pound"; $answer = $_POST['answer']; /*if (!defined($income && $costs)) { }*/ if (!isset($_POST['answer'])) { $income= number_format(rand(50, 30000),1); $costs= number_format(rand(100, 20000),1); } else { $income_new = $income; $costs_new = $costs; } ?> <div id="spacer"></div> <div id="title" class="text1"><h1><?php echo $page_title ?></h1></div> <div id="spacer"></div> <div id="question" class="text2"> <p>If a company makes a total turnover of <?php echo $pnd.$income; ?> and all the costs come to <?php echo $pnd.$costs; ?>.</p> <p>What is the total profit made by this company?</P> <?php $profits= number_format($income_new-$costs_new, 1); if (!empty($_POST['answer'])) { number_format($answer, 1); if ($answer == $profits) { echo '<div class="correct"></div>'; } else { echo '<div class="incorrect"></div>'; } } else { $answer = NULL; echo "Enter in your answer below."; } ?> </div> <div id="spacer"></div> <div id="submit_box"> <form action="profit_calc.php" method="POST" name="form"> <input type="text" size="12" name="answer"> <div id="input_submit"><input type="submit" name="submit" value="SUBMIT"></div> </form> </div> <script type="text/javascript" language="JavaScript"> document.forms['form'].elements['answer'].focus(); </script> <?php include ('includes/footer.php'); ?> So basically I want this script to randomly generate two numbers that are then taken away from each other to give you another value. This value will then be validated and display whether you got it right or not. The bit I am struggling with is to get the randomly generated number to follow through to the validation of the actual answer itself. How would I go about doing this. Thank you in advance.
  23. Thank you a lot. I believe it is working fully.
  24. I am currently trying to make a simple math sort of form where I can define two main variables that I then subtract to work out a theoretical profit. I may try and plug in a rand() into the income and costs but for now I kept it simple. I am struggling to make the final If statement work. It does not know that the variable is 5 9I have put a comment where I am referring to). All help will be greatful, thanks. profit_calc.php <?php $pnd = "&pound"; $income= 10; echo '<p>Income = ' .$pnd.$income. '</p>'; $costs= 5; echo '<p>Costs = ' .$pnd.$costs. '</p>'; $profits=$income-$costs; echo '<p>Profit = ' .$pnd.$profits. '</p>'; if (!empty($_REQUEST['answer'])) { $_REQUEST['answer'] = $answer; /* What Do I Do Here */ if ($answer == $profits) { echo "Correct."; } else { echo "Incorrect."; } } else { $answer = NULL; echo "You did not enter anything."; } ?> <form action="profit_calc.php"> <p><input type="text" name="answer"></p> <p><input type="submit" name="submit" value="submit"></p> </form>
  25. Ok so I am trying to make it so that I have the option to make my site display one of two pages. Maintenance.php if I put the site down, and Index.php for the default site. Here is my code so far but I am unsure as to why it does not work?? Maintenance.php <?php function maintenance($mode){ if($mode = TRUE){ echo '<META HTTP-EQUIV="Refresh" Content="0; URL=maintenance.php">'; exit; } else { echo '<META HTTP-EQUIV="Refresh" Content="0; URL=index.php">'; exit; } } ?> Under maintenance Index.php <?php require_once('maintenance.php') maintenance($mode = TRUE); ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Home</title> <link rel="stylesheet" type="text/css" href="css/style.css"> <link rel="SHORTCUT ICON" href="favicon.ico"> </head> Not under maintenance What seems to be the problem??
×
×
  • 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.