Question

Ok, I got a PHP page wherein it reads a.txt file (large server log) and stores it in a variable $logcontents. I then need to pass that variable to another php page where it will process the $logcontents contents accordingly. I am using a form inside the main php page to submit that variable to the other php page, the code is:

<input type="hidden" name="hiddenlogcontents" value="<?php echo $logcontents ?>">

My problem is $logcontents when passed to the other php page, it contains only 1 character which is {. I'm thinking php can't pass a variable that contains a large amount of data? The first page is able to echo $logcontents in the page, it is only when forwarding this variable to another php page that it displays empty or one character. Any ideas? I tried researching but I'm lost of keywords to use for this issue.

Was it helpful?

Solution

I thought someone would pick up the slack here, but apparently nobody is...

<input type="hidden" name="hiddenlogcontents" value="<?php echo $logcontents ?>">

Since you say the first and only character that gets transmitted is "{", I'll make a lucky guess that the log data consists of JSON strings and looks something like this:

{"foo":"bar"...

Well, let's interpolate that data into your HTML to see the result of your code snippet:

<input type="hidden" name="hiddenlogcontents" value="{"foo":"bar"...">

Can you see it here in the SO code highlighter? The value of the value attribute is "{". The rest that follows is incorrectly formatted garbage. You're just creating the attribute value="{" as far as the HTML parser is concerned.

If you want to embed quotes in HTML attributes, those need to be HTML encoded:

<input type="hidden" name="hiddenlogcontents" value="<?php echo htmlspecialchars($logcontents, ENT_QUOTES); ?>">

Please read The Great Escapism (Or: What You Need To Know To Work With Text Within Text).


Secondarily I'd question how wise it is to transfer huge data blobs this way, forcing the client to download and upload the data repeatedly. But that's another topic...

OTHER TIPS

I'm not sure if is that your issue but encode your $logcontents for url like that :

<?php echo urlencode($logcontents); ?>

If your text are too long you could short it with encode_base64 :

<?php echo base64_encode($logcontents); ?>

And use decode_base64 where your retrieve your data :

<?php echo base64_decode($logcontents); ?>

Hope that could help you ;)

You may close the echo. Try GET to see if the correct value is sent by the URL. If yes, check your echo command.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top