
tberger
Members-
Posts
11 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
tberger's Achievements

Newbie (1/5)
0
Reputation
-
Brilliant - that did the trick. Thank you so much. Yes - you are correct the code blocks are much easier to read - will use in the future!! Thank you so much for you help!!!!!
-
Ok so I tried this: if($count==1){ // Register $username, $pass $row = mysql_fetch_array($result) or die(mysql_error()); $_SESSION['username'] = $username; $_SESSION['fName'] = $first_name; $_SESSION['lName'] = $last_name; setcookie ("ok", $username); return TRUE; } else { echo "Wrong Username or Password"; } } On the welcome page where I am calling in these sessions, it is still not displaying the firstname and last name. The username does work in both the session and the setcookie. Here is where it is being called: require('library.pinc'); $cookie= $HTTP_COOKIE_VARS["ok"]; if (!isset($cookie)){ header("Cache-Control: no-cache, must-revalidate"); } echo "Welcome, "; echo $_SESSION[ 'first_name'] . " " . $_SESSION['last_name'], "<br />"; echo "You have successfully logged in as "; echo $_SESSION['username'], "<br />"; echo "Your first and last names were passed by session data; your username was stored in the cookie. ", "<br />"; echo "The cookie value is: "; echo $cookie, "<br />"; I am thinking I am not fetching correctly - any suggestions??
-
When someone logs into my application - a login function runs from a pinc file. What is suppose to happen is if the username and password match - it is suppose to assign a session to the username - which is being passed from form and to the first and last name which are in the table for the user. Can I assign a session variable to value in a mysql table? It does properly set the cookie I am assigning on the setCookie line but is is not setting any of the three sessions. Here is the function I am using: session_start(); function getLogin($username, $pass) { $username = trim($_POST['email_address']); $pass = trim($_POST['password']); $db=mysql_connect('monet.homeip.net','conn1','conn1') or die ("Cannot connect to server"); mysql_select_db('test',$db) or die ("Cannot select DB"); // Mysql_num_row is counting table row $result=mysql_query("SELECT * FROM seebergerLogin WHERE username='$username' and password='$pass'"); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched username and password, table row must be 1 row if($count==1){ // Register $username, $pass $_SESSION['username'] = $username; $_SESSION['fName'] = $first_name; $_SESSION['lName'] = $last_name; setcookie ("ok", $username); return TRUE; } else { echo "Wrong Username or Password"; } } ?> I am sure I am missing something simple (at least I hope that is all) I appreciate any help you can offer. TJ
-
I am setting up a member form for users. When the person submits there information. The database checks to make sure the record doesn't already exist - if it does, it should tell them it does and direct them to the login page. If it doesn't exist, it should insert a record into the database. My problem - it displays like it is putting the records into the table but when I display the table results - I get nothing. It worked when I just had an insert statement but when I put that inside an if statement to satisfy the criteria I listed above - it seems to have stopped working. Any suggestions? Here is the code: <html> <head> <title>Create Process</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <?php /* Tracy Seeberger (00835940) create_processSQL.php Module 4 - Assignment */ //Escapes and enquotes variables function clean($var){ return trim(addslashes($var)); } //Variable declaration $fname = clean($_POST['first_name']); $lname = clean($_POST['last_name']); $email = clean($_POST['email_address']); $pw = clean($_POST['password']); // Connect to server and select databse. $db=mysql_connect('monet.homeip.net','conn1','conn1') or die ("Cannot connect to server"); mysql_select_db('test',$db) or die ("Cannot select DB"); print "Connected to MySQL<br>"; if (!$_POST['email_address'] | !$_POST['password'] | !$_POST['first_name'] | !$_POST['last_name']) { die('You must complete all required fields.'); } $usercheck = $_POST['email_address']; $check = mysql_query("SELECT username FROM seebergerLogin where username = '$_POST[email_address]'") or die(mysql_error()); if ($check != 0 ) { $query="INSERT INTO seebergerLogin (username, password, first_name, last_name)VALUES ('$_POST[email_address]','$_POST[password]','$_POST[first_name]','$_POST[last_name]')"; $_POST[password] = md5($_POST[password]); echo $fname; echo ', your account has been created <br />'; echo "<html> <body> To Sign into your account <a href='loginsql.php'> Click Here!</a>"; } else { echo $_POST['email_address']; echo ("You are already registered"); echo "<html> <body> To Sign into your account <a href='loginsql.php'> Click Here!</a>"; } ?> </body> </html>
-
Thanks - I did make that change but there was no difference. I think the problem is this line: if(preg_match("/^.+?:.+?:".preg_quote($username).":".preg_quote($password)."$/s", trim($line))) Can I do an explode here instead of the preg_match?
-
I want PHP to read data I have stored in a text file to pull out certain pieces of data. Right now when you log in - I want it to check my user text file to determine if the data is there. If so, I want the page to welcome the person - if not to let them know there is no match. Right now the page always returns no matches and I think it is in the function. I believe it is how the function is reading the file. I think if I explode the data in the text file, I might get it to work properly but i am not sure how. The current function is: <?php function getLogin($username, $password) { $email = trim($_POST['email']); $pass = trim($_POST['pass']); $file = "/staff/seebetra/homepage/ciss225/registered_users.txt"; $lines = file($file); $logged = FALSE; foreach($lines as $line) { if(preg_match("/^.+?:.+?:".preg_quote($email).":".preg_quote($pass)."$/s", trim($line))) { list($first, $last, $f_email, $f_pass) = explode(":", trim($line)); echo "Hello ".$first." ".$last."!"; $logged = TRUE; break; } } if(!$logged) echo "Sorry, you didn't match!"; } ?> Is there a way to explode on the text file instead to find the match? I appreciate any help I can get on this.
-
Thanks for your help. I did change the code to write to file to be fwrite ($fp, "$email:$pw:$fname:$lname\n"); but it still is telling me I have not matches when I know I do. I really think the problem is in the function - <?php function getLogin($username, $password) { $email = trim($_POST['email']); $pass = trim($_POST['pass']); $file = "/staff/seebetra/homepage/ciss225/registered_users.txt"; $lines = file($file); $logged = FALSE; foreach($lines as $line) { if(preg_match("/^.+?:.+?:".preg_quote($email).":".preg_quote($pass)."$/s", trim($line))) { list($first, $last, $f_email, $f_pass) = explode(":", trim($line)); echo "Hello ".$first." ".$last."!"; $logged = TRUE; break; } } if(!$logged) echo "Sorry, you didn't match!"; } ?> Any other suggestions?
-
Currently I have a form that collects basic user information - first and last name, email and password. This is being stored in a txt file. Here is the code that is processing the information into the txt file. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Create Process</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <?php //Escapes and enquotes variables function clean($var){ return trim(addslashes($var)); } //Variable declaration $fname = clean($_POST['first_name']); $lname = clean($_POST['last_name']); $email = clean($_POST['email_address']); $pw = clean($_POST['password']); //Declare the file $file = "/staff/seebetra/homepage/ciss225/registered_users.txt"; //Open File in append mode $fp = fopen ($file, "a+"); //Append Data to file fwrite($fp, $email); fwrite($fp, ":"); fwrite($fp, $pw); fwrite($fp, ":"); fwrite($fp, $fname); fwrite($fp, ":"); fwrite($fp, $lname); fwrite($fp, ":"); echo 'Done<br />'; echo $fname; echo ', your account has been created'; // Close the file fclose($fp); ?> </body> </html> Once you are registered, you will be able to log in. Right now once I confirm login data - they will go to a wlecome page as this is a work in progress. The login is process in a login_process.php that will call in the function from a file called library.pinc. The problem that I am having is that it never finds my data. My guess is that it has something to do with how it is being set up in the txt file but I am not sure. I know a database is a better option there but this is what I have to work with at this time. Here is the code for the login_process: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Login Process</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <?php include('/staff/seebetra/homepage/ciss225/library.pinc'); if(!isset($_POST['submit'])) { getLogin($username, $password); } ?> </body> </html> Here is the function in library.pinc <?php function getLogin($username, $password) { $email = trim($_POST['email']); $pass = trim($_POST['pass']); $file = "/staff/seebetra/homepage/ciss225/registered_users.txt"; $lines = file($file); $logged = FALSE; foreach($lines as $line) { if(preg_match("/^.+?:.+?:".preg_quote($email).":".preg_quote($pass)."$/s", trim($line))) { list($first, $last, $f_email, $f_pass) = explode(":", trim($line)); echo "Hello ".$first." ".$last."!"; $logged = TRUE; break; } } if(!$logged) echo "Sorry, you didn't match!"; } ?> Can anyone help me with this??
-
Thanks for the help, I am going to try that. Do you know is there a way I could write it in a separate function? Something that leads with function getLogin($username, $password) to get the login information?
-
Sure - It is being stored like this firstname:lastname:email:password Here is the code that is putting the data into the registeredusers file: <?php //Escapes and enquotes variables function clean($var){ return trim(addslashes($var)); } //Variable declaration $fname = clean($_POST['first_name']); $lname = clean($_POST['last_name']); $email = clean($_POST['email_address']); $pw = clean($_POST['password']); //Declare the file $file = "/staff/seebetra/homepage/ciss225/registered_users.txt"; //Open File in append mode $fp = fopen ($file, "a+"); //Append Data to file fwrite($fp, $email); fwrite($fp, ":"); fwrite($fp, $pw); fwrite($fp, ":"); fwrite($fp, $fname); fwrite($fp, ":"); fwrite($fp, $lname); echo 'Done'; // Close the file fclose($fp); ?> Thanks for looking at this! TJ
-
I am really new to PHP and my first projects are working with PHP and txt files - I am not yet using MYSQL. I created a registeredusers.txt file that contains user names, emails, and passwords. The users will then fill in a login in page with their email address and password. This form will them process so that another PHP file will open and be available to them. I am having trouble writing the login script that will check the txt file to confirm they have a email address and password on file. I am being told to write it in a function that will be placed in a pinc file that will be included on my loginprocess page. Are there any tutorials that help with writing login functions that work with txt files rather than databases or can someone help me write a function that will work? I appreciate any help.