0

refering as previous question here HTML Generator: Convert HTML to PlainText and put in a textbox using PHP

Now i got some problems even if the reply produce the expected result.

I got these 3 pages:

Page1.php

// This page contain two columns, one for the form that take the 
variables, and other one that contain the iframe that must to display the plaintext

Page2.php

// Cutted code that take $_GET variables and store in $_SESSION

$html = file_get_contents('page3.php');

echo '<textarea readonly style="border:none;resize:none" rows="50" cols="116" value="'. $html .'"></textarea>';

Page3.php

// This is the file page3.php that must to be in plaintext, but first
 it must take the variables from $_SESSION and complete the code

Now I get the plain text file but the variables aren't passed since i've stored them in session. i got $var instead of the value.

And the textbox displays only half of the file, not showing the <link> and the whole <style> tags.

Community
  • 1
  • 1
andreaem
  • 1,635
  • 2
  • 20
  • 49

1 Answers1

1

<textarea> does not have value.

You need to echo that variable inside the tags.

$html = "Text here";
echo '<textarea readonly style="border:none;resize:none" rows="50" cols="116">'. $html .'</textarea>';

"it must take the variables from $_SESSION and complete the code"

Also note that you are using sessions. Make sure the session was started having session_start(); at the top of that page and for any other pages that may be using sessions.

Example:

session_start();

if(isset($_SESSION['var'])){
   $_SESSION['var'] = "var";
}

else{
   echo "Session is not set.";
}

N.B.: Make sure you are not outputting before header.

Consult the following on Stack if you get a headers sent notice/warning:

Add error reporting to the top of your file(s) which will help find errors.

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Then the rest of your code

Sidenote: Displaying errors should only be done in staging, and never production.


Test example which proved successful, echoing var inside <textarea>:

<?php 
session_start();

if(isset($_SESSION['var'])){
   $_SESSION['var'] = "var";

$var = $_SESSION['var'];
}

else{
   echo "Session is not set.";
}

// $html = "Text here";

$html = $var;
echo '<textarea readonly style="border:none;resize:none" rows="50" cols="116">'. $html .'</textarea>';

Edit:

Base yourself on the following model to assign GET arrays to sessions arrays.

<?php 
session_start();

$_GET ['lb1'] = "lb1";
$lb1 = $_GET ['lb1'];
$_GET ['lb1'] = $_SESSION["lb1"];
$_SESSION["lb1"] = $lb1;
//echo "Hey LB1 " . $lb1;
$lb1_session = $lb1;

$_GET ['lb2'] = "lb2";
$lb2 = $_GET ['lb2'];
$_GET ['lb2'] = $_SESSION["lb2"];
$_SESSION["lb2"] = $lb2;
//echo "Hey LB2" . $lb2;
$lb2_session = $lb2;

$html = $lb1_session . "\n". $lb2_session;
echo '<textarea readonly style="border:none;resize:none" rows="50" cols="116">'. $html .'</textarea>';

?>

<a href="check_get_sessions.php">Check GET sessions</a>

check_get_sessions.php

<?php 
session_start();

if(isset($_SESSION['lb1'])){

   $lb1_session = $_SESSION['lb1'];

   echo $lb1_session;
}


if(isset($_SESSION['lb2'])){
   $lb2_session = $_SESSION['lb2'];

   echo $lb2_session;
}

$html = $lb1_session . "\n". $lb2_session;
echo '<textarea readonly style="border:none;resize:none" rows="50" cols="116">'. $html .'</textarea>';

That's the best I can offer you.

Doing $html = $lb1_session . "\n". $lb2_session; you can use "\n" as seperators between each variable to be echo'd. Or, <br> if you want; the choice is yours.

The above assigns the $html variable to chained variables. You can add the others that may need to be added $lb3, $lb4, $lb5 etc.

Good luck! (buon fortunato)

Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • Thanks, that stupid error is gone now the file display correctly. Using error reporting i see that the variables isn't setted. there is a point in your reply that i can't undestand, figure the variables to be passed is a total of 8, how can i use `$html = $var;`? – andreaem Jan 22 '16 at 16:16
  • @andreaem You're welcome. I used `$var` as an example variable taken from the session array, which in turn is then assigned to the `$html` variable, in turn echoing in the textarea. You stated in your question that you were using sessions, so I made up a quick test file to show you an example. – Funk Forty Niner Jan 22 '16 at 16:23
  • Thanks, should it work, i've replaced var with my variable name and no error is reporting. The point is that i got the full file as plain text but, this file contain some variables that must to show his values before outputting as plaintext, and now i got the $var1 instead of "somevalue", there is anyway to set the variables first of put content in the textbox? Maybe a visual example can explain better [link](https://ebay-mm-desc-andreaem-dev.c9users.io/index.php) – andreaem Jan 22 '16 at 16:30
  • @andreaem well I'd keep what you have now for `$html = file_get_contents('page3.php');` and use what I posted in my answer about `echo '';`. Hard to say exactly about what you meant as *"this file contain some variables that must to show his values before outputting"* - You may need to use a heredoc http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc or nowdoc http://php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc – Funk Forty Niner Jan 22 '16 at 16:36
  • follow my link in previous reply, will reach the page i'm working on, i'm italian so maybe i can't explain what i mean. in the page completing the form with random values and clicking generate it will display the page code, in this page you will see that we have $lb1,$lb2,$lb3 etc.. i must to assign a value to this variables first of showing the output, but even if i do, it will show $lb1 cause it's the file original content – andreaem Jan 22 '16 at 16:39
  • @andreaem io capito la lingua bene, ma... not fluently. I have to leave for an hour or so right now, but I'll be back later see what I do. *ciao, a presto!* – Funk Forty Niner Jan 22 '16 at 16:43
  • #Fred Grazie, sei molto bravo con l'italiano! No problems, i'll wait, thank you so much for your time! – andreaem Jan 22 '16 at 17:46
  • @andreaem ciao, io ritorno,e prego (sono francese). Ok, well I would need to see what the contents are of the file that holds all these variables. If you're using sessions, and in order to be able to retain those variables, they need to be assigned to session arrays. I.e.: `$var1 = $_SESSION['var1']; $var2 = $_SESSION['var2']; $var3 = $_SESSION['var3'];` etc. – Funk Forty Niner Jan 22 '16 at 18:08
  • Hi Fred, in the 'page2.php' I take the values from $_GET and put in the session using $_SESSION.here is the cutted code of page2.php: `[...] session_start(); $lb1 = $_GET ['lb1']; $lb2 = $_GET ['lb2']; $lb1 = $_SESSION["lb1"]; $lb2 = $_SESSION["lb2"]; [...]` – andreaem Jan 23 '16 at 13:58
  • i notice now that there is an error, i've changed in $_SESSION['lb1'] = $_GET ['lb1']; and $lb1 = $_SESSION['lb1']; I think now is correct and using var_dump i get string 'bla' [lenght = 3] when check $lb1 value, so the session is correctly setted – andreaem Jan 23 '16 at 15:24
  • @andreaem Hi. Reload my answer and look near the bottom under **Edit**. That is the best I can offer you given the information you've provided. You will need to take it from there, *buon fortunato, salute!*. – Funk Forty Niner Jan 23 '16 at 15:36
  • Thanks but did not produce the expected result, it write the value in textbox but not where i want, i think isn't possibile to reach te result cause file_get_content does not process php code, so if i want to assign a value to variable it doesn't change nothing. So, maybe i must to first change variables writing in the file and then get the content to put in the textarea. Don't worry about, i will find another solution, now will mark the question as answered, thanks a lot! – andreaem Jan 23 '16 at 16:41
  • @andreaem Prego Andrea. I am sure you will find the solution to what you want the final results to be. All the best, *cheers!* – Funk Forty Niner Jan 23 '16 at 16:45