gomesgomes Posted December 20, 2011 Share Posted December 20, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/253568-convert-multiple-files-into-php-to-1-file/ Share on other sites More sharing options...
scootstah Posted December 20, 2011 Share Posted December 20, 2011 So what's the problem? Quote Link to comment https://forums.phpfreaks.com/topic/253568-convert-multiple-files-into-php-to-1-file/#findComment-1299879 Share on other sites More sharing options...
gomesgomes Posted December 20, 2011 Author Share Posted December 20, 2011 In if ($step == 2) { } i suppose to convert that part to a string but when i try I am getting errors. Quote Link to comment https://forums.phpfreaks.com/topic/253568-convert-multiple-files-into-php-to-1-file/#findComment-1299880 Share on other sites More sharing options...
melloorr Posted December 20, 2011 Share Posted December 20, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/253568-convert-multiple-files-into-php-to-1-file/#findComment-1299883 Share on other sites More sharing options...
gomesgomes Posted December 20, 2011 Author Share Posted December 20, 2011 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/253568-convert-multiple-files-into-php-to-1-file/#findComment-1299891 Share on other sites More sharing options...
melloorr Posted December 20, 2011 Share Posted December 20, 2011 Having them all in one file will not work. file 5 is the logout script. Which should be in its own file, because if it was all in one file, as soon the session starts, the session will be finished by that script. Quote Link to comment https://forums.phpfreaks.com/topic/253568-convert-multiple-files-into-php-to-1-file/#findComment-1299893 Share on other sites More sharing options...
gomesgomes Posted December 20, 2011 Author Share Posted December 20, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/253568-convert-multiple-files-into-php-to-1-file/#findComment-1299896 Share on other sites More sharing options...
Pikachu2000 Posted December 20, 2011 Share Posted December 20, 2011 When posting code, enclose it within the forum's . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/253568-convert-multiple-files-into-php-to-1-file/#findComment-1299898 Share on other sites More sharing options...
melloorr Posted December 20, 2011 Share Posted December 20, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/253568-convert-multiple-files-into-php-to-1-file/#findComment-1299906 Share on other sites More sharing options...
gomesgomes Posted December 20, 2011 Author Share Posted December 20, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/253568-convert-multiple-files-into-php-to-1-file/#findComment-1299910 Share on other sites More sharing options...
gomesgomes Posted December 20, 2011 Author Share Posted December 20, 2011 Can anyone else help me? Quote Link to comment https://forums.phpfreaks.com/topic/253568-convert-multiple-files-into-php-to-1-file/#findComment-1299919 Share on other sites More sharing options...
gomesgomes Posted December 21, 2011 Author Share Posted December 21, 2011 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/253568-convert-multiple-files-into-php-to-1-file/#findComment-1299953 Share on other sites More sharing options...
m3bik Posted December 21, 2011 Share Posted December 21, 2011 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 } Quote Link to comment https://forums.phpfreaks.com/topic/253568-convert-multiple-files-into-php-to-1-file/#findComment-1299955 Share on other sites More sharing options...
gomesgomes Posted December 21, 2011 Author Share Posted December 21, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/253568-convert-multiple-files-into-php-to-1-file/#findComment-1299957 Share on other sites More sharing options...
melloorr Posted December 21, 2011 Share Posted December 21, 2011 gomesgomes, why do you only want it in one file anyway? I will work much better and easier if it is in multiple files. Is this a school project or something? Quote Link to comment https://forums.phpfreaks.com/topic/253568-convert-multiple-files-into-php-to-1-file/#findComment-1299963 Share on other sites More sharing options...
gomesgomes Posted December 21, 2011 Author Share Posted December 21, 2011 no, personal challege Quote Link to comment https://forums.phpfreaks.com/topic/253568-convert-multiple-files-into-php-to-1-file/#findComment-1299967 Share on other sites More sharing options...
melloorr Posted December 21, 2011 Share Posted December 21, 2011 no, personal challege If it is a personal challange, why are you asking how to do it? 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. Quote Link to comment https://forums.phpfreaks.com/topic/253568-convert-multiple-files-into-php-to-1-file/#findComment-1299969 Share on other sites More sharing options...
jcbones Posted December 21, 2011 Share Posted December 21, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/253568-convert-multiple-files-into-php-to-1-file/#findComment-1299989 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.