Jump to content

navigation help


eZe616

Recommended Posts

 

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

Link to comment
https://forums.phpfreaks.com/topic/51100-navigation-help/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251532
Share on other sites

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";

				}

			}



		?>

Link to comment
https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251605
Share on other sites

$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.

 

Link to comment
https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251611
Share on other sites

$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.

Link to comment
https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251613
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/51100-navigation-help/#findComment-251614
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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