Jump to content

convert multiple files into php to 1 file


gomesgomes

Recommended Posts

I am trying to convert 6 files into a single 1 php file. I have attached the original files. I need help because I don't know where I am going wrong. this what I have done so far :

 

<?php session_start();

if ($_SESSION['ON'] =="FALSE" || $_SESSION['ON']==null) {

  header( 'Location: index.php?error=invalid-login' );

  session_unset();

  session_destroy();

  exit();

}

?>

 

<html><head><meta http-equiv="content-type" content="text/html; charset=iso-8859-1">

 

<title>LOGIN WEB SESSION</title>

<link rel="stylesheet" type="text/css" href="loginsession.css" />

</head>

<body>

 

 

 

<?php

// If the step is one, show the correct form //

 

 

if ($step == 0)

{

 

echo '<form action="index.php?step=2" method="post">

<table>

<tr><td width="100">Username:</td><td width="200"><input type="text" name="username"></td></tr>

<tr><td width="100">Password:</td><td width="200"><input type="password" name="password"></td></tr>

<tr><td colspan="2" align="center"><input type="submit" value="Login"></td></tr>

</table>

</form>';

}

 

else

if ($step == 1)

{ // Create the step 2 section of the page //

 

function clean($data)

{

    $data = trim($data);

    $data = stripslashes($data);

    $data = htmlspecialchars($data);

    return $data;

}

 

$user = clean($_POST['username']);

$pass = clean($_POST['password']);

 

if ($user == "webdeveloper" && $pass == "master")

{

  session_start();

  $_SESSION['username'] = $user;

  $_SESSION['password'] = $pass;

  $_SESSION['ON']="TRUE";

  $lifetime=600;

  setcookie(session_name(),session_id(),time()+$lifetime);

  header( 'Location: index.php?step=2' ) ;

  exit();

}

else

{

header( 'Location: index.php' );

 

session_destroy();

exit();

}

 

}

 

else

if ($step == 2)

  <div>LOGIN WELCOME</div>

<div>

HERE IS YOUR USER DATA:<br />

<label class="data">username:';

<?php echo $_SESSION['username'] ?>

<br>

password: <?php echo $_SESSION['password'] ?>

<br></label>

HERE IS YOUR SESSION DATA:<br />

<label class="data">

<?php echo (session_name().": ".session_id()) ?><br>

<?php echo ("SESSION DATA: ".session_encode() )?>

</label>

</div>index.php?step=3">Logoff</a></div>

}

 

else

if ($step == 3)

{ // Create the step 4 section of the page //

header( 'Location: index.php' );

session_start();

session_unset();

session_destroy();

exit();

}

 

 

?>

 

</body>

</html>

 

Link to comment
Share on other sites

In  if ($step == 2)

{

 

 

}

 

i suppose to convert that part to a string but when i try I am getting errors.

 

 else
      if ($step == 2)
      <div>LOGIN WELCOME</div>
         <div>
         HERE IS YOUR USER DATA:<br />
         <label class="data">username:';
         <?php echo $_SESSION['username'] ?>
         <br>
         password: <?php echo $_SESSION['password'] ?>
         <br></label>
         HERE IS YOUR SESSION DATA:<br />
         <label class="data">
         <?php echo (session_name().": ".session_id()) ?><br>
         <?php echo ("SESSION DATA: ".session_encode() )?>
         </label>
         </div>index.php?step=3">Logoff</a></div>
      }

 

You have not used { to open the if statement and also you have not closed the php tag before you used the html

Link to comment
Share on other sites

I added that and it still doesn't work and I get this error

parse

error: syntax error, unexpected '<' in C:\Users\Gomes\Desktop\XAMPP\htdocs\index.php on line 74

 

I need them to be converted into a single file.

 

I cannot upload the files so I am going to paste the originals here

file 1 : index.php

 

<html><head><meta http-equiv="content-type" content="text/html; charset=iso-8859-1">

<!--USERID: webdeveloper  PASSWORD: master  -->

<title>LOGIN WEB SESSION</title>

<link rel="stylesheet" type="text/css" href="loginsession.css" />

</head>

<body>

<form action="logon.php" method="post">

<table>

<tr><td width="100">Username:</td><td width="200"><input type="text" name="username"></td></tr>

<tr><td width="100">Password:</td><td width="200"><input type="password" name="password"></td></tr>

<tr><td colspan="2" align="center"><input type="submit" value="Login"></td></tr>

</table>

</form>

</body>

</html>

 

 

file 2 : logon.php

 

<?php

function clean($data)

{

    $data = trim($data);

    $data = stripslashes($data);

    $data = htmlspecialchars($data);

    return $data;

}

 

$user = clean($_POST['username']);

$pass = clean($_POST['password']);

 

if ($user == "webdeveloper" && $pass == "master")

{

  session_start();

  $_SESSION['username'] = $user;

  $_SESSION['password'] = $pass;

  $_SESSION['ON']="TRUE";

  $lifetime=600;

  setcookie(session_name(),session_id(),time()+$lifetime);

  header( 'Location: inside.php' ) ;

  exit();

}

else

{

header( 'Location: index.php' );

 

session_destroy();

exit();

}

 

?>

 

file 3 : checker.php

<?php

session_start();

if ($_SESSION['ON'] =="FALSE" || $_SESSION['ON']==null) {

  header( 'Location: index.php?error=invalid-login' );

  session_unset();

  session_destroy();

  exit();

}

?>

 

file4: inside.php

<?php include "checker.php" ?>

<html><head><title>LOGIN WEB SESSION</title>

<link rel="stylesheet" type="text/css" href="loginsession.css" />

</head>

<body><div>LOGIN WELCOME</div>

<div>

HERE IS YOUR USER DATA:<br />

<label class="data">username:<?php echo $_SESSION['username'] ?><br>

password: <?php echo $_SESSION['password'] ?><br></label>

HERE IS YOUR SESSION DATA:<br />

<label class="data">

<?php echo (session_name().": ".session_id()) ?><br>

<?php echo ("SESSION DATA: ".session_encode() )?>

</label>

</div>

<div><a href="logoff.php">Logoff</a></div>

</body>

</html>

 

file5: logooff.php

 

<?php

header( 'Location: index.php' );

session_start();

session_unset();

session_destroy();

exit();

?>

 

Link to comment
Share on other sites

I am trying to do it with a series of if statements. therefore, it should work based on the conditions of each if statement but I cannot put together.

 

CAN YOU GET THE FIRST 4 TO WORK BY PUTTING THEM ALL TOGETHER? I WILL TRY TO FIGURE OUT HOW THE LOGOUT PART WORKS.

 

Nope sorry, I think it will be impossible to have all 5 (or even 4) in one file. file1 and 2 can go together, but that is about it.

 

But I may be wrong, maybe someone more advanced may be able to do it. But I cannot help. Sorry

Link to comment
Share on other sites

I am trying to do it with a series of if statements. therefore, it should work based on the conditions of each if statement but I cannot put together.

 

CAN YOU GET THE FIRST 4 TO WORK BY PUTTING THEM ALL TOGETHER? I WILL TRY TO FIGURE OUT HOW THE LOGOUT PART WORKS.

 

Nope sorry, I think it will be impossible to have all 5 (or even 4) in one file. file1 and 2 can go together, but that is about it.

 

But I may be wrong, maybe someone more advanced may be able to do it. But I cannot help. Sorry

thank you for trying.
Link to comment
Share on other sites

Looking at your original post, see this code:

 

      if ($step == 2)
      <div>LOGIN WELCOME</div>
         <div>
         HERE IS YOUR USER DATA:<br />
         <label class="data">username:';
         <?php echo $_SESSION['username'] ?>
         <br>
         password: <?php echo $_SESSION['password'] ?>
         <br></label>
         HERE IS YOUR SESSION DATA:<br />
         <label class="data">
         <?php echo (session_name().": ".session_id()) ?><br>
         <?php echo ("SESSION DATA: ".session_encode() )?>
         </label>
         </div>index.php?step=3">Logoff</a></div>
      }

 

You didn't include an echo, print, or close the php interpreter.. That should be more like this:

 

      if ($step == 2)
?>
      <div>LOGIN WELCOME</div>
         <div>
         HERE IS YOUR USER DATA:<br />
         <label class="data">username:';
         <?php echo $_SESSION['username'] ?>
         <br>
         password: <?php echo $_SESSION['password'] ?>
         <br></label>
         HERE IS YOUR SESSION DATA:<br />
         <label class="data">
         <?php echo (session_name().": ".session_id()) ?><br>
         <?php echo ("SESSION DATA: ".session_encode() )?>
         </label>
         </div>index.php?step=3">Logoff</a></div>
<?php
      }

Link to comment
Share on other sites

Looking at your original post, see this code:

 

      if ($step == 2)
      <div>LOGIN WELCOME</div>
         <div>
         HERE IS YOUR USER DATA:<br />
         <label class="data">username:';
         <?php echo $_SESSION['username'] ?>
         <br>
         password: <?php echo $_SESSION['password'] ?>
         <br></label>
         HERE IS YOUR SESSION DATA:<br />
         <label class="data">
         <?php echo (session_name().": ".session_id()) ?><br>
         <?php echo ("SESSION DATA: ".session_encode() )?>
         </label>
         </div>index.php?step=3">Logoff</a></div>
      }

 

You didn't include an echo, print, or close the php interpreter.. That should be more like this:

 

      if ($step == 2)
?>
      <div>LOGIN WELCOME</div>
         <div>
         HERE IS YOUR USER DATA:<br />
         <label class="data">username:';
         <?php echo $_SESSION['username'] ?>
         <br>
         password: <?php echo $_SESSION['password'] ?>
         <br></label>
         HERE IS YOUR SESSION DATA:<br />
         <label class="data">
         <?php echo (session_name().": ".session_id()) ?><br>
         <?php echo ("SESSION DATA: ".session_encode() )?>
         </label>
         </div>index.php?step=3">Logoff</a></div>
<?php
      }

 

 

I got that part to work on my own but the following code I need to convert it into a string.

<div>
HERE IS YOUR USER DATA:<br />
<label class="data">username:<?php echo $_SESSION['username'] ?><br>
password: <?php echo $_SESSION['password'] ?><br></label>
HERE IS YOUR SESSION DATA:<br />
<label class="data">
<?php echo (session_name().": ".session_id()) ?><br>
<?php echo ("SESSION DATA: ".session_encode() )?>
</label>
</div>
<div><a href="logoff.php">Logoff</a></div>

 

 

Link to comment
Share on other sites

no, personal challege

 

If it is a personal challange, why are you asking how to do it? :shrug:

 

But, this may work. At the end of each script, have a form that goes to the next script. Example:

<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>"> 
<input type=submit name="submittochecker" value="Submit">
</form>
</html>
<?php 
if(isset($_POST['submittochecker']
{
.......... ;
}

 

That is VERY rough and may not even work, but it is the best I can think of. Just change the submit name of the the script you want to run next, and change that if(isset($_POST['submittochecker'] to whatever you named the submit button, and it should run that script. Then place another one at the end of that. If you know what I mean.

Link to comment
Share on other sites

It would be quite simple to condense all of that into one single script.  But, you will need to divide the logic and the display.  When you do this, you notice that you can lose a lot of the code that you have.

<?php

session_start(); //start the session.

$message = NULL; //set a message variable.

$login = FALSE; //login is false on every page start.

if($_SERVER['REQUEST_METHOD'] == 'POST') { //if the form was submitted.

function clean($data) //generic clean function.

	{

		$data = trim($data);

		$data = stripslashes($data);

		$data = htmlspecialchars($data);

		return $data;

	}	

	$user = clean($_POST['username']); //"cleaned" post data.

	$pass = clean($_POST['password']); //"cleaned" post data.



	if ($user == "webdeveloper" && $pass == "master") //if the user and password fits the hardcoded strings.

	{
	  $_SESSION['username'] = $user; //set user in the session array.

	  $_SESSION['password'] = $pass; //set password in the session array.

	  $_SESSION['ON'] = TRUE; //session ON is now true.
	  $lifetime=600;

		setcookie(session_name(),session_id(),time()+$lifetime); //setting a cookie ??			  

	}

	else {

		$message = 'Wrong Username or Password'; //if login failed, send a message to the user.

	}

}





if (empty($_SESSION['ON']) || $_SESSION['ON'] == FALSE || isset($_GET['Logout'])) { //if session is not ON, or LOGOUT is requested.

  $login = FALSE; //set the login to false.

  session_unset(); //unset the session.

  session_destroy(); //terminate the session.

}

elseif(!empty($_SESSION['ON']) && $_SESSION['ON'] == TRUE) { //else if the session is NOT empty, and is TRUE.

 $login = TRUE; //LOGIN is also true.

}



if($login == TRUE) { //if LOGIN is true, print the block below to the page.

?>



<html><head><title>LOGIN WEB SESSION</title>

<link rel="stylesheet" type="text/css" href="loginsession.css" />

</head>

<body><div>LOGIN WELCOME</div>

<div>

HERE IS YOUR USER DATA:<br />

<label class="data">username:<?php echo $_SESSION['username'] ?><br>

password: <?php echo $_SESSION['password'] ?><br></label>

HERE IS YOUR SESSION DATA:<br />

<label class="data">

<?php echo (session_name().": ".session_id()) ?><br>

<?php echo ("SESSION DATA: ".session_encode() )?>

</label>

</div>

<div><a href="?Logout=1">Logoff</a></div>

</body>

</html>



<?php

}

else { //else login will be false, so show the form.

?>

<html><head><meta http-equiv="content-type" content="text/html; charset=iso-8859-1">

<!--USERID: webdeveloper  PASSWORD: master  -->

<title>LOGIN WEB SESSION</title>

<link rel="stylesheet" type="text/css" href="loginsession.css" />

</head>

<body>

<form action="?Login=1" method="post">

	<?php echo $message; //show a message if it exists.?> 

<table>

<tr><td width="100">Username:</td><td width="200"><input type="text" name="username"></td></tr>

<tr><td width="100">Password:</td><td width="200"><input type="password" name="password"></td></tr>

<tr><td colspan="2" align="center"><input type="submit" value="Login"></td></tr>

</table>

</form>

</body>

</html>

<?php

}

?>

 

Don't know why copy/paste from Geany double spaces!

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.