
TheJoey
Members-
Posts
334 -
Joined
-
Last visited
Never
Everything posted by TheJoey
-
thank you so much... was going insane!
-
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'; }
-
<?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
-
<?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.
-
Help with login.. works at home but not at school
TheJoey replied to TheJoey's topic in PHP Coding Help
is there mabye another way i can go about doing this. -
Help with login.. works at home but not at school
TheJoey replied to TheJoey's topic in PHP Coding Help
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. -
<?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..
-
im having trouble with that code snipped Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING
-
Parse error: syntax error, unexpected '!' hmm... because i want it to display the error if session is not.
-
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
-
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 }
-
had to do it a different way, but i guess it still works fine.
-
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) {
-
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 '>'
-
What would be the best way to go about doing some server side validation on PHP? Any example would be great
-
[SOLVED] Trying to create a simple login function
TheJoey replied to TheJoey's topic in PHP Coding Help
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. -
[SOLVED] Trying to create a simple login function
TheJoey replied to TheJoey's topic in PHP Coding Help
$username=test1 $usernamematch=test1 $password=test2 $passwordmatch=test2 -
[SOLVED] Trying to create a simple login function
TheJoey replied to TheJoey's topic in PHP Coding Help
test1test2 i get that for all 4 variables. could it be that it isnt retrieveing the information from the file correctly? -
[SOLVED] Trying to create a simple login function
TheJoey replied to TheJoey's topic in PHP Coding Help
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 -
[SOLVED] Trying to create a simple login function
TheJoey replied to TheJoey's topic in PHP Coding Help
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. -
[SOLVED] Trying to create a simple login function
TheJoey replied to TheJoey's topic in PHP Coding Help
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 -
[SOLVED] Trying to create a simple login function
TheJoey replied to TheJoey's topic in PHP Coding Help
test1:test2:test3:test4:test5:test6 test1 being my username test2 being my password -
[SOLVED] Trying to create a simple login function
TheJoey replied to TheJoey's topic in PHP Coding Help
i fixed the blank page stupid error on my behalf location url instead of being location: url im always getting wronginfo.php though now. -
[SOLVED] Trying to create a simple login function
TheJoey replied to TheJoey's topic in PHP Coding Help
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'); } ?> -
[SOLVED] Trying to create a simple login function
TheJoey replied to TheJoey's topic in PHP Coding Help
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