[Php-calendar-discussion] Calendar tweaks I have made 9/9
Brought to you by:
sproctor
From: Larry J. <joh...@gm...> - 2008-07-19 14:57:27
|
Below is another minor tweak I made: -- Larry #9 - (optional) Put in a login screen just to see the calendar, with redirecting if attempt to go right to calendar Put in the following code at the top of the index.php file: <?php include "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/Calendars/Calendar_000_LarryJohnsonPersonal/authorized_check.php"; ?> Added the following files: authorized_check.php login_regular.php login_redirect.php authorized_check.php <?php // Check to make sure that the user is logged into the session session_start(); if (isset($_SESSION['logged0LJ']) && $_SESSION['logged0LJ'] == 1) { // Do nothing, the user is logged into the session } else { // Redirect the user to the login page as they are NOT yet logged into the session $redirect = $_SERVER['PHP_SELF']; header("Refresh: 3; URL= http://localhost/Calendars/Calendar_000_LarryJohnsonPersonal/login_redirect.php?redirect=$redirect"); // redirect in 3 seconds echo "You must be logged in to view this page!<br><br>"; echo "You are now being redirected to the login page.<br><br>"; echo "(If your browser doesn't support this, " . "<a href=\" http://localhost/Calendars/Calendar_000_LarryJohnsonPersonal/login_redirect.php?redirect=$redirect\">click here</a>)"; die(); } ?> login_regular.php <?php include "header.php"; ?> <?php session_start(); $_SESSION['logged'] = 0; if (isset($_POST['submit'])) { // The user clicked the Submit button, i.e. the variable $_POST['submit'] has a value // Check username and password information against the database mysql_connect("localhost", "root", "hellocar"); mysql_select_db("calendar"); $user_check = $_POST['username_check']; $passwd_check = md5($_POST['password_check']); $calendar_name_check = $_POST['calendar_check']; $result = mysql_query("SELECT * FROM phpc_users WHERE calendar = '". $calendar_name_check . "' AND username = '". $user_check . "' AND password = '". $passwd_check ."'") or die('Could not look up user information; ' . mysql_error()); if ($row = mysql_fetch_array($result)) { // The user logged in correctly $_SESSION['logged0LJ'] = 1; $tmenu = " http://localhost/Calendars/Calendar_000_LarryJohnsonPersonal/index.php"; header ("Refresh: 3; URL=\"" . $tmenu . "\""); // redirect in 3 seconds echo "<br>"; echo "Successful login! You are being directed to the Larry Johnson Personal calendar!<br>"; echo "(If your browser doesn't support this, " . "<a href=\"" . $tmenu . "\">click here</a>)"; } else { // The user did NOT log in correctly // End the PHP ?> <!-- // Go into HTML and start the login form again --> <html> <body> <p> Invalid Username and/or Password!<br><br> <form action="login_regular.php" method="post"> <table border="0" cellspacing="1" cellpadding="4" bgcolor="#C0C0C0" align="left"> <tr> <td bgcolor="#FFFFFF" width="42%"><B>Username</B></td> <td bgcolor="#FFFFFF"> <select name="username_check"> <option value="" selected>Select a userid...</option> <option value="johnlaus">johnlaus</option> </select> </td> </tr> <tr> <td bgcolor="#FFFFFF"><B>Password</B></td> <td bgcolor="#FFFFFF"> <input type="password" name="password_check"> </td> </tr> <tr> <td bgcolor="#FFFFFF"><B>Calendar</B></td> <td bgcolor="#FFFFFF"> <select name="calendar_check"> <option value="" selected>Select a calendar...</option> <option value="0">Calendar 000 - Larry Johnson Personal</option> </select> </td> </tr> <tr> <td bgcolor="#FFFFFF" colspan=2 align="left"> <input type="submit" name="submit" value="Login"> </td> </tr> </table> </form> </p> <?php } } else { // The user has NOT YET clicked the Submit button // End the PHP ?> <!-- // Go into HTML and start the login form --> <html> <body> <p> <form action="login_regular.php" method="post"> <table border="0" cellspacing="1" cellpadding="4" bgcolor="#C0C0C0" align="left"> <tr> <td bgcolor="#FFFFFF" width="42%"><B>Username</B></td> <td bgcolor="#FFFFFF"> <select name="username_check"> <option value="" selected>Select a userid...</option> <option value="johnlaus">johnlaus</option> </select> </td> </tr> <tr> <td bgcolor="#FFFFFF"><B>Password</B></td> <td bgcolor="#FFFFFF"> <input type="password" name="password_check"> </td> </tr> <tr> <td bgcolor="#FFFFFF"><B>Calendar</B></td> <td bgcolor="#FFFFFF"> <select name="calendar_check"> <option value="" selected>Select a calendar...</option> <option value="0">Calendar 000 - Larry Johnson Personal</option> </select> </td> </tr> <tr> <td bgcolor="#FFFFFF" colspan=2 align="left"> <input type="submit" name="submit" value="Login"> </td> </tr> </table> </form> </p> <?php } ?> </body> </html> login_redirect.php <?php include "header.php"; ?> <?php session_start(); $_SESSION['logged'] = 0; if (isset($_POST['submit'])) { // The user clicked the Submit button, i.e. the variable $_POST['submit'] has a value // Check username and password information against the database mysql_connect("localhost", "root", "hellocar"); mysql_select_db("calendar"); $user_check = $_POST['username_check']; $passwd_check = md5($_POST['password_check']); $calendar_name_check = $_POST['calendar_check']; $result = mysql_query("SELECT * FROM phpc_users WHERE calendar = '". $calendar_name_check . "' AND username = '". $user_check . "' AND password = '". $passwd_check ."'") or die('Could not look up user information; ' . mysql_error()); if ($row = mysql_fetch_array($result)) { // The user logged in correctly $_SESSION['logged0LJ'] = 1; header ("Refresh: 3; URL=" . $_POST['redirect'] . ""); // redirect in 3 seconds echo "You are being redirected to your original page request!<br>"; echo "(If your browser doesn't support this, " . "<a href=\"" . $_POST['redirect']. "\">click here</a>)"; } else { // The user did NOT log in correctly // End the PHP ?> <!-- // Go into HTML and start the login form again --> <html> <body> <p> Invalid Username and/or Password!<br><br> <form action="login_redirect.php" method="post"> <input type="hidden" name="redirect" value="<?php echo $_POST['redirect']; ?>"> <table border="0" cellspacing="1" cellpadding="4" bgcolor="#C0C0C0" align="left"> <tr> <td bgcolor="#FFFFFF" width="42%"><B>Username</B></td> <td bgcolor="#FFFFFF"> <select name="username_check"> <option value="" selected>Select a userid...</option> <option value="johnlaus">johnlaus</option> </select> </td> </tr> <tr> <td bgcolor="#FFFFFF"><B>Password</B></td> <td bgcolor="#FFFFFF"> <input type="password" name="password_check"> </td> </tr> <tr> <td bgcolor="#FFFFFF"><B>Calendar</B></td> <td bgcolor="#FFFFFF"> <select name="calendar_check"> <option value="" selected>Select a calendar...</option> <option value="0">Calendar 000 - Larry Johnson Personal</option> </select> </td> </tr> <tr> <td bgcolor="#FFFFFF" colspan=2 align="left"> <input type="submit" name="submit" value="Login"> </td> </tr> </table> </form> </p> <?php } } else { // The user has NOT YET clicked the Submit button // End the PHP ?> <!-- // Go into HTML and start the login form --> <html> <body> <p> Please log in.<br> <!-- // Pop into PHP --> <? if (isset($_GET['redirect'])) { $redirect = $_GET['redirect']; } else { $redirect = "index.php"; } ?> <!-- // Exit out of PHP --> <form action="login_redirect.php" method="post"> <input type="hidden" name="redirect" value="<?php echo $_GET['redirect']; ?>"> <table border="0" cellspacing="1" cellpadding="4" bgcolor="#C0C0C0" align="left"> <tr> <td bgcolor="#FFFFFF" width="42%"><B>Username</B></td> <td bgcolor="#FFFFFF"> <select name="username_check"> <option value="" selected>Select a userid...</option> <option value="johnlaus">johnlaus</option> </select> </td> </tr> <tr> <td bgcolor="#FFFFFF"><B>Password</B></td> <td bgcolor="#FFFFFF"> <input type="password" name="password_check"> </td> </tr> <tr> <td bgcolor="#FFFFFF"><B>Calendar</B></td> <td bgcolor="#FFFFFF"> <select name="calendar_check"> <option value="" selected>Select a calendar...</option> <option value="0">Calendar 000 - Larry Johnson Personal</option> </select> </td> </tr> <tr> <td bgcolor="#FFFFFF" colspan=2 align="left"> <input type="submit" name="submit" value="Login"> </td> </tr> </table> </form> </p> <?php } ?> </body> </html> |