dave101 Posted April 22, 2009 Share Posted April 22, 2009 <?php // Define your username and password $username = "Fileuser"; $password = "test98"; if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) { ?> <h1>Login</h1> <form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p><label for="txtUsername">Username:</label> <br /><input type="text" title="Enter your Username" name="txtUsername" /></p> <p><label for="txtpassword">Password:</label> <br /><input type="password" title="Enter your password" name="txtPassword" /></p> <p><input type="submit" name="Submit" value="Login" /></p> </form> <?php } else { ?> <? } ?> <? How can i make thsi call another php file after it has authenticated the user? Thanks! Dave Link to comment https://forums.phpfreaks.com/topic/155261-web-page-auth-with-a-call-to-another-php-script/ Share on other sites More sharing options...
dave101 Posted April 22, 2009 Author Share Posted April 22, 2009 Basically I am trying to haev a secure webpage that has a listiogn of files that are in the directory but I do not want the files to show up until after the user has authenticated. Thanks! Link to comment https://forums.phpfreaks.com/topic/155261-web-page-auth-with-a-call-to-another-php-script/#findComment-816896 Share on other sites More sharing options...
tang Posted April 22, 2009 Share Posted April 22, 2009 Something like this: <?php session_start(); // Define your username and password $username = "Fileuser"; $password = "test98"; if (!isset($_SESSION['loggedIn'])) { $_SESSION['loggedIn'] = false; } if (isset($_POST['txtUsername']) && isset($_POST['txtPassword'])) { if ($_POST['txtUsername'] === $username && $_POST['txtPassword'] === $password) { $_SESSION['loggedIn'] = true; } } if ($_SESSION['loggedIn']) { // list your files } else { // display the login form ?> <h1>Login</h1> <form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p><label for="txtUsername">Username:</label> <br /><input type="text" title="Enter your Username" name="txtUsername" /></p> <p><label for="txtpassword">Password:</label> <br /><input type="password" title="Enter your password" name="txtPassword" /></p> <p><input type="submit" name="Submit" value="Login" /></p> </form> <?php } // end display the login form Link to comment https://forums.phpfreaks.com/topic/155261-web-page-auth-with-a-call-to-another-php-script/#findComment-816905 Share on other sites More sharing options...
dave101 Posted April 23, 2009 Author Share Posted April 23, 2009 Thank you for the help. It seems to bypass the login piece of the script and still display the files with no auth. Also is there a way to only list a certain type of fiels in the directory? Such as only list the files that ahve a pdf extention? This is the script I have so far. <?php session_start(); // Define your username and password $username = "Fileuser"; $password = "test98"; if (!isset($_SESSION['loggedIn'])) { $_SESSION['loggedIn'] = false; } if (isset($_POST['txtUsername']) && isset($_POST['txtPassword'])) { if ($_POST['txtUsername'] === $username && $_POST['txtPassword'] === $password) { $_SESSION['loggedIn'] = true; } } if ($_SESSION['loggedIn']) { // list your files $dir = "."; $dh = opendir($dir); while (($file = readdir($dh)) !== false) { echo "<A HREF=\"$file\">$file</A><BR>\n"; } closedir($dh); //end list files } else { // display the login form ?> <h1>Login</h1> <form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p><label for="txtUsername">Username:</label> <br /><input type="text" title="Enter your Username" name="txtUsername" /></p> <p><label for="txtpassword">Password:</label> <br /><input type="password" title="Enter your password" name="txtPassword" /></p> <p><input type="submit" name="Submit" value="Login" /></p> </form> <?php } // end display the login form Thanks! Link to comment https://forums.phpfreaks.com/topic/155261-web-page-auth-with-a-call-to-another-php-script/#findComment-817364 Share on other sites More sharing options...
jonsjava Posted April 23, 2009 Share Posted April 23, 2009 <?php session_start(); // Define your username and password $username = "Fileuser"; $password = "test98"; if (isset($_POST['txtUsername']) && isset($_POST['txtPassword'])) { if ($_POST['txtUsername'] == $username && $_POST['txtPassword'] == $password) { $_SESSION['loggedIn'] = true; } } if (isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] == true) { // list your files $dir = "."; $dh = opendir($dir); while (($file = readdir($dh)) !== false) { if (strstr($file, ".pdf")){ echo "<A HREF=\"$file\">$file</A><BR>\n"; } } closedir($dh); //end list files } else { // display the login form ?> <h1>Login</h1> <form name="form" method="post" action="?"> <p><label for="txtUsername">Username:</label> <br /><input type="text" title="Enter your Username" name="txtUsername" /></p> <p><label for="txtpassword">Password:</label> <br /><input type="password" title="Enter your password" name="txtPassword" /></p> <p><input type="submit" name="Submit" value="Login" /></p> </form> <?php } // end display the login form ?> Link to comment https://forums.phpfreaks.com/topic/155261-web-page-auth-with-a-call-to-another-php-script/#findComment-817384 Share on other sites More sharing options...
dave101 Posted April 23, 2009 Author Share Posted April 23, 2009 Ok now that is working!! AWESOME!!. Now how woudl i make it show only a directory listing? For example if i had 3 directories under the directory /home/files/uploads/ Thanks!! Link to comment https://forums.phpfreaks.com/topic/155261-web-page-auth-with-a-call-to-another-php-script/#findComment-817517 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.