4

I have an inconsistency between two pages.The PHP is dumping the variables and I need to be able to see the raw data in the variable without an HTML render rendering anything that might be in them.

The post rendered version are 100% identical, but when I take the strings and hash_hmac then they get different resulting hashes.

Is there any way to dump these strings and see the raw data?

Arun Kumar
  • 6,534
  • 13
  • 40
  • 67
Case
  • 4,244
  • 5
  • 35
  • 53
  • 3
    You can prevent the browser from rendering the page by adding `header('Content-type: text/plain');` to the top of the page – Gerald Schneider Oct 08 '12 at 09:32
  • possible duplicate of [display text without HTML markup](http://stackoverflow.com/questions/7117404/display-text-without-html-markup) – Baba Oct 10 '12 at 14:54

4 Answers4

5

Sevaral options come to mind. Either

  • send header('Content-Type: text/plain');
  • or wrap the dump in <pre> elements.
  • Or simply look into the source code which will have the raw output as well.

You might also be interested in xdiff.

Gordon
  • 312,688
  • 75
  • 539
  • 559
2

try strip_tags function in php This will srip all tags

or

use this

header('Content-Type: text/plain');
Codesen
  • 7,724
  • 5
  • 29
  • 31
0

It wouldn't work, I tried. I was making an Amazon FPS system and the signature was invalid because they hard rendered new lines in the post request to make the signature. The system I build had spaces. After posting this I dumped the results into a database and say in the db that it had newlines.

Answer: Take the strings and dump them into a database. Then use the database to see the differences. This was the only way I found to solve my issue.

Case
  • 4,244
  • 5
  • 35
  • 53
  • 3
    Please use the *Post answer* button only for actual answers. You should modify your original question to add additional information. – vascowhite Oct 08 '12 at 09:49
  • It is an actual answer for my question. If someone has the same issue dumping it to a database is a viable solution. – Case Oct 08 '12 at 10:10
  • Sorry, I didn't realise. It doesn't read like an answer, more like a comment. – vascowhite Oct 08 '12 at 10:19
  • You're absolutely right, I should have formatted it better. I did edit it some to hopefully clear up the confusion. – Case Oct 08 '12 at 10:24
0

I use this function to print array values to the screen:

function PrintArray($array)
{
    echo " <pre>";
    print_r($array);
    echo " </pre> ";
}

For instance, to gain access to posted data:

if ($submit)
{
  if ($debug)
  {
    printarray($_POST);
  }
}

The rest of your script data (that which isn't immediately shown through markup) will need to be echoed/printed to file in $debug conditional statements.

You should build your app to include debug statements wherever potential for trouble may be found. At the top of your page, declare $debug = true; (or set it to false when not in use).

edited:

BTW, in my environment the debug statements are turned off if the script is served from production (detected programmatically). They can only show in test, and when $debug is set to true. As a commenter writes below, you should not display (or allow through mistake) debug information to show in production/live applications.

It's better to write your debug info to a file residing below the web root.

a coder
  • 7,530
  • 20
  • 84
  • 131
  • You should log, sure. But don't do it by declaring a variable at the top of script. Should that script be pushed live with debug on, you're going to be left with a fair bit of egg on your face, and also a potential security risk. – Martin Bean Oct 08 '12 at 10:32
  • In my environment the debug statements are turned off if the script is served from production (detected programmatically). They can only show in test, and when $debug is set to true. – a coder Oct 08 '12 at 10:34
  • So if you programmatically detect the environment, why do you have a variable in the first place? – Martin Bean Oct 08 '12 at 10:36
  • To enable/disable debug for an entire page. $debug can be set to either true or false, but this occurs above the page_header include. page_header includes a check to make sure debug is off if being served from production. This is cleaner than writing the logic into each individual debug condition throughout the script and has the same effect. – a coder Oct 08 '12 at 10:40
  • 1
    I don't see a reason not to use a debug variable in development. I do things entirely differently however. I have a silent logger that catches all php, mysql, everything errors and put them into a database so the user never knows anything is up. Enhances the users experience. – Case Oct 08 '12 at 11:34