eZe616 Posted May 12, 2007 Share Posted May 12, 2007 Currently I have this piece of code. <?php $page = $_GET['page']; $page = ($page != '') ? $page : 'index' ; $page .= '.txt'; $page = preg_replace('%(?:\.\./)+%', '', $page); if (!is_dir($page) && file_exists($page)) { if (!(@include($page))) { include '404.txt'; } } else { echo 'File does not exist'; } ?> Now I have a navigation menu with the options "home","Contact us", "Login" etc.. Now I want to call the Login in page, but the entire page is in php, and since the above script is calls .txt files, I tried putting the php code in just a .txt file, thinking the original index.php will process the php in the .txt file, but it doesn't. Is there a way I can call the functions to show the login form. The code of the form validation and such that I'm using can be somewhat be seen here http://www.phpfreaks.com/forums/index.php/topic,139638.0.html. Ofcourse I've modified it, but it's the same concept. When I call on the login.txt, it doesn't display the form. it looks like it takes space, but no form appears. How can I make the form appear while still using this form of site navigation or won't it work? a preview can be seen here http://eze.110mb.com/a.r.e.s/index.php Quote Link to comment https://forums.phpfreaks.com/topic/51100-navigation-help/ Share on other sites More sharing options...
Trium918 Posted May 12, 2007 Share Posted May 12, 2007 Is there a login form on the index.php? If so, may I see it? Quote Link to comment https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251521 Share on other sites More sharing options...
eZe616 Posted May 12, 2007 Author Share Posted May 12, 2007 Yeah there is... <?php function Show(){ $html = ""; // Called by the client, shows the form if(ValidateForm()){ // Form is valid, so we process $html = ProcessForm(); }else{ // Form is invalid, so we show it $html = ShowForm(); } return $html; } echo Show(); ?> <?php function ShowForm() { global $form_errors; $html = ""; // Start off empty if(is_array($form_errors) && count($form_errors)){ // Form had errors, so we are redisplaying $html .= "The follow errors were encountered:<ul><li>" . implode("</li><li>", $form_errors) . "</li></ul>"; } // Now build the form $html .= " <form id=\"myform\" method=\"post\" action=\"". $_SERVER['PHP_SELF'] . "\"> <fieldset class=\"lform\"> <label> <span> Username: </span> <input class=\"inputlog\" type=\"text\" name=\"uname\" maxlength=\"32\" /> </label> <label> <span> Password: </span> <input class=\"inputlog\" type=\"password\" name=\"pass\" maxlength=\"10\" /> </label> <label> <input type=\"submit\" name=\"login\" value=\"login\" class=\"login\" /> </label> <br /> <label class=\"text\"> <a href=\"reg.php\"> Register</a> | <a href=\"\"> Forgot password?</a> </label> </fieldset> </form>"; return $html; } function ValidateForm(){ global $form_errors; $has_errors = false; $form_errors = Array(); // If the form has not been submitted, it is obviously invalid if(count($_POST) == 0){ return false; // This will cause ShowForm() to be called from our Show() function } // A form has been submitted, so we can validate each field. $regexp = '/^[a-zA-Z0-9]+$/'; // Fields are alphanumeric // Check valid username if(!preg_match($regexp, trim($_POST["uname"]))){ $has_errors = true; $form_errors[] = "Valid user names are alphanumeric."; } // Check for a password if(strlen(trim($_POST['pass'])) == 0){ $has_errors = true; $form_errors[] = "You must insert a password."; } return !$has_errors; // Negative logic } function ProcessForm() { $uname = $_POST['uname']; $pass = $_POST['pass']; $server = ""; $username = ""; $password = ""; $db = ""; $my_connect = mysql_connect () or die( "Could not Connect to server"); $db_select = mysql_select_db ($db) or die ("Could not Connect to Database"); $sql = "SELECT * FROM usertable WHERE username ='". $uname ."'"; $result = mysql_query($sql) or die ( msql_error()); $valid = mysql_fetch_array($result); if ( empty($valid) ) { echo "This username does not exist"; exit; } if ( $valid['pass'] == $pass ) { echo "Thank you for loggin in:<b>" .$uname. "</b>"; $_SESSION['uname'] = $valid['username']; header("location: index.php"); } else { echo "Your password is invalid"; } } ?> I also want a link that you can just click login, and it'll show the login form in the content area. since I want to do it like that also for the registesration. Quote Link to comment https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251532 Share on other sites More sharing options...
eZe616 Posted May 12, 2007 Author Share Posted May 12, 2007 I just tried entering a simple <?php echo("hello"); ?> and save it as text file, to see if it is processed as php. and it does echo the Hello back, I just can't understand why the form doesn't show up Quote Link to comment https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251602 Share on other sites More sharing options...
Trium918 Posted May 12, 2007 Share Posted May 12, 2007 Try this! Note: Try and Post quickly. I will help you, but I don't have all day! <?php function Show(){ $html = ""; // Called by the client, shows the form if(ValidateForm()){ // Form is valid, so we process $html = ProcessForm(); }else{ // Form is invalid, so we show it $html = ShowForm(); } return $html; } echo Show(); ?> <?php function ShowForm() { global $form_errors; $html = ""; // Start off empty if(is_array($form_errors) && count($form_errors)){ // Form had errors, so we are redisplaying $html .= "The follow errors were encountered:<ul><li>" . implode("</li><li>", $form_errors) . "</li></ul>"; } ?> <form id="myform" method="post" action="". $_SERVER['PHP_SELF'] . " "> <fieldset class="lform"> <label> <span> Username: </span> <input class="inputlog" type="text" name="uname" maxlength="32" /> </label> <label> <span> Password: </span> <input class="inputlog" type="password" name="pass" maxlength="10" /> </label> <label> <input type="submit" name="login" value="login" class="login" /> </label> <br /> <label class="text"> <a href="reg.php"> Register</a> | <a href=" "> Forgot password?</a> </label> </fieldset> </form> <?php } // End ShowFunction() function ValidateForm(){ global $form_errors; $has_errors = false; $form_errors = Array(); // If the form has not been submitted, it is obviously invalid if(count($_POST) == 0){ return false; // This will cause ShowForm() to be called from our Show() function } // A form has been submitted, so we can validate each field. $regexp = '/^[a-zA-Z0-9]+$/'; // Fields are alphanumeric // Check valid username if(!preg_match($regexp, trim($_POST["uname"]))){ $has_errors = true; $form_errors[] = "Valid user names are alphanumeric."; } // Check for a password if(strlen(trim($_POST['pass'])) == 0){ $has_errors = true; $form_errors[] = "You must insert a password."; } return !$has_errors; // Negative logic } function ProcessForm() { $uname = $_POST['uname']; $pass = $_POST['pass']; $server = ""; $username = ""; $password = ""; $db = ""; $my_connect = mysql_connect () or die( "Could not Connect to server"); $db_select = mysql_select_db ($db) or die ("Could not Connect to Database"); $sql = "SELECT * FROM usertable WHERE username ='". $uname ."'"; $result = mysql_query($sql) or die ( msql_error()); $valid = mysql_fetch_array($result); if ( empty($valid) ) { echo "This username does not exist"; exit; } if ( $valid['pass'] == $pass ) { echo "Thank you for loggin in:<b>" .$uname. "</b>"; $_SESSION['uname'] = $valid['username']; header("location: index.php"); } else { echo "Your password is invalid"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251605 Share on other sites More sharing options...
eZe616 Posted May 12, 2007 Author Share Posted May 12, 2007 Nope, nothing...it's still blank Quote Link to comment https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251606 Share on other sites More sharing options...
Trium918 Posted May 12, 2007 Share Posted May 12, 2007 Nope, nothing...it's still blank Is there any other code? Quote Link to comment https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251610 Share on other sites More sharing options...
Eugene Posted May 12, 2007 Share Posted May 12, 2007 $page = ($page != '') ? $page : 'index' ; $page .= '.txt'; $page = preg_replace('%(?:\.\./)+%', '', $page); look at your preg_replace statement. Lets say the page = index page = index.txt you are then replace the "." with "" so your code is search for a file called indextxt, which doesn't exist. Quote Link to comment https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251611 Share on other sites More sharing options...
eZe616 Posted May 12, 2007 Author Share Posted May 12, 2007 $page = ($page != '') ? $page : 'index' ; $page .= '.txt'; $page = preg_replace('%(?:\.\./)+%', '', $page); look at your preg_replace statement. Lets say the page = index page = index.txt you are then replace the "." with "" so your code is search for a file called indextxt, which doesn't exist. but the code works though...i does look up index.txt , that file does come up just the login one doesn't. Quote Link to comment https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251613 Share on other sites More sharing options...
eZe616 Posted May 12, 2007 Author Share Posted May 12, 2007 Nope, nothing...it's still blank Is there any other code? Like what? As you can see from the link I put there..the only other code there is the login form when the site comes up...Which is basicly the same code I'm trying to call with the Login link. which i put like <a href="index.php?page=login">login</a> But the Login form there is embed directly into the index.php, it's when I try to call the login.txt, with the form in the text file the form won't show up.that's about the only php code in the file.with the session_start() at the top. But, it the same when I call the registration form, nothing shows up Quote Link to comment https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251614 Share on other sites More sharing options...
eZe616 Posted May 12, 2007 Author Share Posted May 12, 2007 ^^ modified there Quote Link to comment https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251615 Share on other sites More sharing options...
Trium918 Posted May 12, 2007 Share Posted May 12, 2007 If you create a file called test.php and insert the code I provided the login will come up. Quote Link to comment https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251632 Share on other sites More sharing options...
eZe616 Posted May 12, 2007 Author Share Posted May 12, 2007 Yeah, but can't I include it in a .txt file?...I have no problem with a seperate .php file calling the function it works perfectly...It's only when I try to put a link to it..and include it from a .txt file it won't show up Quote Link to comment https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251639 Share on other sites More sharing options...
Trium918 Posted May 12, 2007 Share Posted May 12, 2007 Why would you want to use a text file? Quote Link to comment https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251643 Share on other sites More sharing options...
eZe616 Posted May 12, 2007 Author Share Posted May 12, 2007 Since I'm using the navigation style I mentioned ^^...it easier to update a txt file and inlcude it. I'll try changing it from including .txt to .php and see what happens.. Quote Link to comment https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251644 Share on other sites More sharing options...
Trium918 Posted May 12, 2007 Share Posted May 12, 2007 You are one weird guy. Good Luck! Quote Link to comment https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251645 Share on other sites More sharing options...
eZe616 Posted May 12, 2007 Author Share Posted May 12, 2007 just new to this navigation thing...lol, don't know no other way to do it... tnx though Quote Link to comment https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251646 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.