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.

5
  • 1
    <textarea> does not have value. Commented Jan 22, 2016 at 15:45
  • What Fred means is echo '<textarea readonly style="border:none;resize:none" rows="50" cols="116">'.$html.'</textarea>'; Commented Jan 22, 2016 at 15:48
  • @mplungjan I posted an answer below but can honestly say that I did not rely on your comment about it. I was busy testing it and did not see it, as I was typing it up. Commented Jan 22, 2016 at 15:49
  • @mplungjan Thanks, cheers Commented Jan 22, 2016 at 15:50
  • Seeing no activity yet and from my initial post, have made a few edits to my answer below, in case you didn't see them. Not much else I can add to it. Commented Jan 22, 2016 at 16:10

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

13 Comments

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 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.
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
@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 '<textarea readonly style="border:none;resize:none" rows="50" cols="116">'. $html .'</textarea>';. 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 php.net/manual/en/… or nowdoc php.net/manual/en/…
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
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.