Jump to content

TheJoey

Members
  • Posts

    334
  • Joined

  • Last visited

    Never

Everything posted by TheJoey

  1. thank you so much... was going insane!
  2. thank you worked a treat. may i ask what you changed. and say i wanted to register a session could i do it like this if ($login == true) { $_SESSION['login'] = true; echo 'hi there user'; } else { echo 'nope'; }
  3. <?php $username = $_POST['username']; $password = $_POST['password']; $file = fopen("user.txt", "r"); /* Set login to false initially */ $login = false; /* Break out of loop if login becomes true OR EOF is encountered */ while(($login == false) && (!feof($file))) { $data = explode(":", fgets($file)); /* assume field 0 is username, field 1 is password */ if( ($data['0'] == $username) && ($data['1'] == $password)) { /* login is true, so will break out of loop after this iteration */ $login = true; } } if ($login = true) { echo 'hi there user'; } else {echo 'nope';} fclose($file); ?> <html> <body> <form action="login4.php" method="post"> <ul> <li><label for="username"> USERNAME: </label><input type="text" name="username" id="username"/></li> <li><label for="password"> PASSWORD: </label><input type="password" name="password" id="password"/></li> </ul> <input name="login" type="submit" value="Login"/ </form> </body> </html> the code is fixed, and a few other errors are now fixed althought its always displaying 'hi there user' even in the password is wrong
  4. <?php $file = fopen('user.txt', 'r'); /* Set login to false initially */ $login = false /* Break out of loop if login becomes true OR EOF is encountered */ while(($login == false) && (!eof($file))) { $data = explode(":", fgets($file)); /* assume field 0 is username, field 1 is password */ if( ($data['0'] == $username) && ($data['1'] == $password) { /* login is true, so will break out of loop after this iteration */ $login = true; } } if $login = true { echo 'hi there user'; } else {echo 'nope';} fclose($file); ?> <html> <body> <form action="login4.php" method="post"> <ul> <li><label for="username"> USERNAME: </label><input type="text" name="username" id="username"/></li> <li><label for="password"> PASSWORD: </label><input type="password" name="password" id="password"/></li> </ul> <input name="login" type="submit" value="Login"/ </form> </body> </html> Parse error: syntax error, unexpected T_WHILE in C:\xampplite\htdocs\login tests\login4.php on line 8 having trouble writing a login script that uses .txt files.
  5. is there mabye another way i can go about doing this.
  6. i have a script that uses this <?php session_start(); $username = $_POST['username']; $password = $_POST['password']; if ($username == 'super' && $password == 'super') { $_SESSION['success'] = true; header("location: adminsuccess.php"); } else { header("location: adminunsuccess.php"); } ?> and it works fine i just keep getting refered to unsuccess.
  7. <?php session_start(); $username = $_POST['username']; $password = $_POST['password']; $lines = file("data/users.txt",FILE_IGNORE_NEW_LINES); // read the lines into an array $find = "$username:$password"; // form a string like you expect it to be in the array if(in_array($find,$lines)){ $_SESSION['loginsuccessfull'] = true; # If successfull header("location: loginsuccess.php"); # redirect to this page } else { # Else redirect to header("location: loginunsuccess.php"); # this page } ?> im completly stuck and have no idea why its not working..
  8. im having trouble with that code snipped Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING
  9. Parse error: syntax error, unexpected '!' hmm... because i want it to display the error if session is not.
  10. Would i just put <?php session_start(); if(isset(!$_SESSION['login'])) { echo 'You not meant to be here'; } in the include ? instead of html code
  11. Hello just wondering if theres a way i can apply an efficient sessions check to every page like <?php session_start(); if(isset(!$_SESSION['login'])) { echo 'You not meant to be here'; } else{ HTML CODE }
  12. had to do it a different way, but i guess it still works fine.
  13. No errors, but nothing seems to be happening. $displayEmailError = 'Email Must be Valid'; $displayAgeError = 'Age must be Valid'; $displayFirstError = 'First Name cant be Empty'; $displayLastError = 'Last Name cant be Empty'; if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email)) { $displayEmailError = true; } if ($_POST['Age'] < 18 OR $_POST['Age'] > 67) { $displayAgeError = true; } if (empty($_POST['FirstName'])) { $displayFirstError = true; } if (empty($_POST['LastName'])) { $displayLastError = true; } if (!$displayEmailError && !$displayAgeError && !$displayFirstError && !$displayLastError) {
  14. Hey i need help with this i wrote this out <?php $displayEmailError = 'Email Must be Valid'; $displayAgeError = 'Age must be Valid'; $displayFirstError = 'First Name cant be Empty'; $displayLastError = 'Last Name cant be Empty'; if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email)) $displayEmailError = true; if (($_POST['Age']) <18 & > 67) $displayAgeError = true; if (empty($_POST['FirstName']) $displayFirstError = true; if (empty($_POST['LastName']) $displayLastError = true; if ($displayEmailError, $displayAgeError, $displayFirstError, $displayLastError) = false {save to database} but im getting syntax's alover the joint i need a litle help Parse error: syntax error, unexpected '>'
  15. What would be the best way to go about doing some server side validation on PHP? Any example would be great
  16. Ive worked it out... after all that the reason it wasnt working was because of all the r_prints & i had to change the values within post. All working now thanks for that guys.
  17. $username=test1 $usernamematch=test1 $password=test2 $passwordmatch=test2
  18. test1test2 i get that for all 4 variables. could it be that it isnt retrieveing the information from the file correctly?
  19. print_r($username); print_r($usernamematch); print_r($password); print_r($passwordmatch); wont work for me. could it be that $usernamematch == $username ? insted of $username == $usernamematch
  20. if ($username == $usernamematch && $password == $passwordmatch) i was thinking thats where the problem lies, and i did try that. Im still getting Whooops error meaning im being directed to the wronginfo.php page.
  21. test1:test2:test3:test4:test5:test6 test1test2 is what was displayed and that is exactly what im typing in even copied pasted to make sure
  22. test1:test2:test3:test4:test5:test6 test1 being my username test2 being my password
  23. i fixed the blank page stupid error on my behalf location url instead of being location: url im always getting wronginfo.php though now.
  24. im still getting a a empty page... ive tried fixing it with soloution's and i keep changing it and its always a blank page heres the complete code. <?php session_start(); $usernamematch = $_POST['username']; $passwordmatch = $_POST['password']; $fp = fopen("registrationinfo/info.txt","a+"); $fileData = fread($fp,filesize("registrationinfo/info.txt")); fclose($fp); $array = explode(':', $fileData); $username = trim($array[0]); //user-name $password = trim($array[1]); //password if ($username == $usernamematch & $password == $passwordmatch) { $_SESSION['loginsuccessfull'] = true; header('location indexsuccessfull.php'); } else { header('location wronginfo.php'); } ?>
  25. Warning: fclose() expects parameter 1 to be resource, null given on line 8 Warning: Cannot modify header information - headers already sent by on line 18 running into a few error
×
×
  • 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.