hugoriffic's Profile
Reputation: 0
Apprentice
- Group:
- Active Members
- Active Posts:
- 185 (0.14 per day)
- Joined:
- 16-September 09
- Profile Views:
- 1,940
- Last Active:
May 06 2013 10:26 AM- Currently:
- Offline
Previous Fields
- Country:
- US
- OS Preference:
- Windows
- Favorite Browser:
- FireFox
- Favorite Processor:
- Intel
- Favorite Gaming Platform:
- Who Cares
- Your Car:
- Who Cares
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: Redirecting to previous page after login using HTTP_REFERER
Posted 4 Apr 2013
I finally figured everything out. I don't know how I couldn't see the issues I was creating for myself (maybe a case of looking at the code so long you no longer see it) but I resolved them.
I sat down and wrote out exactly what I wanted to do and in what order. Then I cleared all of my previous code and started fresh using the step by step process I had written out. Working through the logic this way made everything easier to code.
Here is the code I came up with for my logIn.php page:
<?php session_start(); $validate_error = ''; // check where the user needs to be redirected to after successful login $url = !empty($_SESSION['itweb.fvtc.edu']) ? $_SESSION['itweb.fvtc.edu'] : "index.php"; if(!empty($_SESSION['UserName'])) { header("Location: $url"); exit(); } elseif(isset($_POST['btnSubmit']) AND !isset($_SESSION['UserName'])) { if(empty($_POST['txtUserName'])) { $validate_error = 'Please Enter A User Name'; }else if(empty($_POST['txtPassword'])) { $validate_error = 'Please Enter A Valid Password'; }elseif(empty($validate_error)) { $UserName = trim($_POST['txtUserName']); $Password = $_POST['txtPassword']; if($Password != Password($UserName, $Password, $url)) { showForm('User Name And Password Do Not Match!'); exit(); } }else { showForm($validate_error); exit(); } }else { showForm('Welcome'); exit(); } function Password($LoginUserName, $LoginPassword, $url='index.php') { //database login $dsn = 'mysql:host=XXX;dbname=XXX'; $username='XXX'; $password='XXX'; //variable for errors $options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION); //try to run code try { //object to open database $db = new PDO($dsn,$username,$password, $options); //check username against password $SQL = $db->prepare('SELECT * FROM user WHERE USER_NAME = :UserName and USER_PASSWORD = :Password'); $SQL->bindValue(':UserName', $LoginUserName); $SQL->bindValue(':Password', $LoginPassword); $SQL->execute(); $username = $SQL->fetch(); if($username === FALSE) { $LoginPassword = NULL; showForm('Invalid log in information.'); exit(); } if($username == TRUE) { $_SESSION['UserName'] = $username['USER_NAME']; header("Location: $url"); exit(); } return $LoginPassword; $SQL->closeCursor(); $db = null; } catch(PDOException $e){ $error_message = $e->getMessage(); echo("<p>Database Error: $error_message</p>"); exit(); } }
I'm pretty sure from there you can figure out what I put on the top of every other page. So absolutely frustrated with myself for not writing the logic out on paper before attempting to code. It makes it so much easier when you can see what you want to do and in what order. -
In Topic: Redirecting to previous page after login using HTTP_REFERER
Posted 3 Apr 2013
Any other observations or helpful advice?? -
In Topic: Redirecting to previous page after login using HTTP_REFERER
Posted 3 Apr 2013
Thanks. I'll fix that. -
In Topic: Redirecting to previous page after login using HTTP_REFERER
Posted 3 Apr 2013
There should be no {?> in the if line. -
In Topic: Redirecting to previous page after login using HTTP_REFERER
Posted 3 Apr 2013
Here is my last attempt to get help with this assignment as it is due in about 18 hours and I still cannot get it to work. Here is my latest code. Could someone please help me out with this? I really am struggling and nowhere is any help available but here. I have not asked anyone to write the code for me so all I want is a tutorial or someone to guide me through the logic. I'm at the end of my rope here and seriously need advice and help.
logIn.php:
<?php session_start(); if(isset($_SESSION['UserName'])) { $url = $_SESSION['logIn.php']; } else { $url = "index.php"; } if (!isset($_SESSION['UserName'])){ //if username and password are empty display welcome message if(empty($_POST['txtUserName']) && empty($_POST['txtPassword'])) { showForm('Welcome to Wiscon'); exit(); } //validate text was entered in UserName text box if(empty($_POST['txtUserName']) && isset($_POST['btnSubmit'])) { showForm('Please Enter A User Name'); exit(); } else { $UserName = $_POST['txtUserName']; } //validate text was entered in password text box if(empty($_POST['txtPassword']) && isset($_POST['btnSubmit'])) { showForm('Please Enter A Valid Password'); exit(); } else { $Password = $_POST['txtPassword']; } $UserName = $_POST['txtUserName']; $Password = $_POST['txtPassword']; //validate username and password match if($Password != Password($UserName) && isset($_POST['btnSubmit'])) { showForm('User Name And Password Do Not Match!'); exit(); } } function Password($UserName) { //database login $dsn = 'mysql:host=itsql.fvtc.edu;dbname=teamc'; $username='teamc'; $password='teamc'; //variable for errors $options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION); //try to run code try { //object to open database $db = new PDO($dsn,$username,$password, $options); //check username against password $SQL = $db->prepare('SELECT * FROM user WHERE USER_NAME = :UserName and USER_PASSWORD = :Password'); $SQL->bindValue(':UserName', $UserName); $SQL->bindValue(':Password', $Password); $SQL->execute(); $username = $SQL->fetch(); if($username === FALSE) { $Password = null; showForm('Invalid log in information.'); exit(); } if($username == TRUE) { $_SESSION['UserName'] = $username['USER_NAME']; header("Location: http://itweb.fvtc.edu.com".$url"); exit(); } return $Password; $SQL->closeCursor(); $db = null; } catch(PDOException $e){ $error_message = $e->getMessage(); echo("<p>Database Error: $error_message</p>"); exit(); } }
Code at the top of every page to grab the URI
<?php session_start(); $_SESSION['itweb.fvtc.edu'] = $_SERVER['REQUEST_URI'];
And the header.php page where all the changes are to take place if a valid log in was achieved.
<php session_start(); //Check to see if user is logged in. If session does not exist, serve header without personal greeting. If session does exist, serve second header if(isset($_SESSION['UserName'])){ $UserName = $_SESSION['UserName']; } if (isset($_SESSION['UserName'])){?>{ <div id="header"> <div id="headerTop"> <div id="greeting"> <p>Welcome <?=$UserName;?>!</p> </div><!--end div id=greeting--> <ul id="logIn"> <li><a href="logOut.php">Log-Out</a></li> <li><a href="registerResponse.php">My Profile</a></li> </ul> </div><!--end div id=headerTop--> <div id="headerBottom"> <div id="logo"> </div><!--end div id=logo--> <div id="keyboard"> </div><!--end div id="keyboard"--> </div><!--end div id=headerBottom--> </div><!--end div id=header--> <?php } else {?> <div id="header"> <div id="headerTop"> <div id="greeting"> </div><!--end div id=greeting--> <ul id="logIn"> <li><a href="logIn.php">Log-In</a></li> <li><a href="registerResponse.php">Register</a></li> </ul> </div><!--end div id=headerTop--> <div id="headerBottom"> <div id="logo"> </div><!--end div id=logo--> <div id="keyboard"> </div><!--end div id="keyboard"--> </div><!--end div id=headerBottom--> </div><!--end div id=header--> <?php } ?>
My Information
- Member Title:
- D.I.C Head
- Age:
- 42 years old
- Birthday:
- June 12, 1970
- Gender:
-
- Years Programming:
- 1
- Programming Languages:
- HTML, JavaScript, PHP, CSS
Contact Information
- E-mail:
- Private
Friends
hugoriffic hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
hugoriffic has no profile comments yet. Why not say hello?