Jump to content

PHP Login


aftabn10

Recommended Posts

Hi,

 

I am looking to create a website that will allow users to login and then allow them to specify their availability through a calendar (e.g. Available, Busy) for any specific day. This will then allow me to see all the registered users and their availability for a particular day.

 

The problem is that i dont know where to start as i have never created a login system let alone have an admin section as well.

 

Could somebody please help to get me started.

 

Thanks in advance.

Link to comment
Share on other sites

Ok well first thing you will have to do is figure out how you want to manage the user information.

will you be using sessions in files / DB

will you store the schedule in ranges.

lets start with the user management....

 

tell me where you stand as far as progress..

Link to comment
Share on other sites

Thanks for your reply Manny. All User information will be stored in a MySQL database and I would like to use sessions to secure the site, and also only allow registered users access to secured pages, i.e. their calendar page.

 

I would also like the users to be able to tell me if for example they are available or busy and select an option from the calendar for that day (02/04/09 Busy) and this again will need to be stored in the database.

 

I have also managed to gather data that I would require from the user as well which will be added onto the register section of the site.

 

Thats all i have for now. Thanks once again for your help.

 

 

Link to comment
Share on other sites

He was helping you along, but: Now that you have an idea of what you want you need to start planning out the structure of your scripts. Your session handler needs to work closely with the login script, and will have to be included on every page that is considered secure. The session handler should detect any inconsistancies in the user's static settings, and should take action based on those changes. The Database interaction will be controled via a script that will be updating basicly calendar dates.

From here you have to start coding it, no one here is going to do it for you, unless you pay and even then that is a different forum. Good luck, and report back when you have questions or errors needing resolved.

Link to comment
Share on other sites

Ok thanks to Larry Ullman and his PHP Book I have managed to write Login/Logout scripts. I am trying to create pages that will only be accesible when a user has logged in but no text shows up, the header and footer do show up tho. Where am i going wrong? The following is a script I have wrote:

 

<?php # Script 13.11 - change_password.php
// This page allows a logged-in user to change their password.

// Include the configuration file for error management and such.
require_once ('./includes/config.inc.php'); 

// Set the page title and include the HTML header.
$page_title = 'Change Your Password';
include ('./includes/header.html');

// If no first_name variable exists, redirect the user.
if (!isset($_SESSION['first_name'])) {

// Start defining the URL.
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// Check for a trailing slash.
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
	$url = substr ($url, 0, -1); // Chop off the slash.
}
ob_end_clean(); // Delete the buffer.
header("Location: $url");
exit(); // Quit the script.

	require_once ('../mysql_connect.php'); // Connect to the database.

?>
<p> Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary </p>
<?		mysql_close(); // Close the database connection.

} // End of the main Submit conditional.

?>
<?php
include ('./includes/footer.html');
?>

 

Thanks in advance.

Link to comment
Share on other sites

I could be wrong, but try this

<?php
if(isset($_SESSION['first_name']) == FALSE
{

   // Start defining the URL.
   $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
   // Check for a trailing slash.
   if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
      $url = substr ($url, 0, -1); // Chop off the slash.
}
?>

Link to comment
Share on other sites

Thanks Timmah for your help.

 

This is the full code I have ran and I get the following error:

 

Parse error: syntax error, unexpected '{' in /....../...../.../.....php on line 3

 

<?php
if(isset($_SESSION['first_name']) == FALSE
{

   // Start defining the URL.
   $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
   // Check for a trailing slash.
   if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
      $url = substr ($url, 0, -1); // Chop off the slash.
}
?>
<p> Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary </p>
<?		mysql_close(); // Close the database connection.

} // End of the main Submit conditional.

?>
<?php
include ('./includes/footer.html');
?>

 

Any ideas?

Link to comment
Share on other sites

<?php
if(!isset($_SESSION['first_name']))
{

// Start defining the URL.
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// Check for a trailing slash.
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
	$url = substr ($url, 0, -1); // Chop off the slash.
}
echo "<p> Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary Diary </p>";
mysql_close(); // Close the database connection.

} // End of the main Submit conditional.
include ('./includes/footer.html');
?>

Link to comment
Share on other sites

Thanks jonsjava for your reply. The page shows up fine, but this page is accesible even though im not logged in.

 

Im guessing this has something to do with the session?

 

I have a forgotten password page which only works if a user is logged in so I need to be implement the same concept but need a blank template that i could save and reuse for whatever pages are required.

 

This is the code for the forgotten password page:

 

<?php # Script 13.10 - forgot_password.php
// This page allows a user to reset their password, if forgotten.

// Include the configuration file for error management and such.
require_once ('./includes/config.inc.php'); 

// Set the page title and include the HTML header.
$page_title = 'Forgot Your Password';
include ('./includes/header.html');

if (isset($_POST['submitted'])) { // Handle the form.

require_once ('../mysql_connect.php'); // Connect to the database.

if (empty($_POST['email'])) { // Validate the email address.
	$uid = FALSE;
	echo '<p><font color="red" size="+1">You forgot to enter your email address!</font></p>';
} else {

	// Check for the existence of that email address.
	$query = "SELECT user_id FROM users WHERE email='".  escape_data($_POST['email']) . "'";		
	$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
	if (mysql_num_rows($result) == 1) {

		// Retrieve the user ID.
		list($uid) = mysql_fetch_array ($result, MYSQL_NUM); 

	} else {
		echo '<p><font color="red" size="+1">The submitted email address does not match those on file!</font></p>';
		$uid = FALSE;
	}

}

if ($uid) { // If everything's OK.

	// Create a new, random password.
	$p = substr ( md5(uniqid(rand(),1)), 3, 10);

	// Make the query.
	$query = "UPDATE users SET pass=SHA('$p') WHERE user_id=$uid";		
	$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
	if (mysql_affected_rows() == 1) { // If it ran OK.

		// Send an email.
		$body = "Your password to log into SITENAME has been temporarily changed to '$p'. Please log in using this password and your username. At that time you may change your password to something more familiar.";
		mail ($_POST['email'], 'Your temporary password.', $body, 'From: admin@sitename.com');
		echo '<h3>Your password has been changed. You will receive the new, temporary password at the email address with which you registered. Once you have logged in with this password, you may change it by clicking on the "Change Password" link.</h3>';
		mysql_close(); // Close the database connection.
		include ('./includes/footer.html'); // Include the HTML footer.
		exit();				

	} else { // If it did not run OK.

		echo '<p><font color="red" size="+1">Your password could not be changed due to a system error. We apologize for any inconvenience.</font></p>'; 

	}		

} else { // Failed the validation test.
	echo '<p><font color="red" size="+1">Please try again.</font></p>';		
}

mysql_close(); // Close the database connection.

} // End of the main Submit conditional.

?>

<h1>Reset Your Password</h1>
<p>Enter your email address below and your password will be reset.</p> 
<form action="forgot_password.php" method="post">
<fieldset>
<p><b>Email Address:</b> <input type="text" name="email" size="20" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Reset My Password" /></div>
<input type="hidden" name="submitted" value="TRUE" />
</form>

<?php
include ('./includes/footer.html');
?>

 

Thanks once again, really appreciate it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.