How can I convince xdebug to output files as HTML? - php

I want xdebug's trace function to output files in .html instead .xt.
This are the arguments of xdebug_start_trace function:
http://grahamwideman.wikispaces.com/PHP+trace+with+XDebug
I tested them, but they're not working.
Is there a way to output files with .html format using xdebug, and avoid typing more code?

You want the xdebug.trace_format setting, the documentation is here: http://xdebug.org/docs/execution_trace
Don´t forget to restart your webserver to make the new settings take effect.
There is another profiler that provides its results through a nice webinterface by default, maybe you would like to give it a try:
https://github.com/facebook/xhprof

You need to set xdebug.trace_format = 2 in your php.ini.
After that restart apache

i did it before
and the xdebug made a .xt file with html codes
like tr and td and..raw html code
this is it https://gist.github.com/057ffa704f21f645e086
i want to make a .html file to view it instantly.
i can do that by rename fun but i want xdebug do that

By far the easiest way to do this is to use an .htaccess file in your output directory to add a MIME type to files with an xt extension using the AddType directive. Like so:
AddType text/html .xt
Or you could enable it globally in your http.conf as well:
<IfModule mod_mime.c>
AddType text/html .xt
</IfModule>
If you're interested, I cover a bunch of this sort of stuff in a recent post on configuring a LAMP server and PhpStorm for debugging.

Related

Showing PHP Scripts [duplicate]

for a certain folder on my local Apache-Server (running with Ubuntu) I'd like that all *php-files will be displayed as if they were plain text-files. I need this since I only want to see the source code of these files and NOT run them.
While searching, I found that most people have the opposite problem :-) and couldn't really find a solution for me.
What would I need to include in the .htacces-file of my folder?
THANKS!
THE ANSWER:
in .htaccess-file type
php_flag engine off
#This will prevent apache from executing *.php-files
AddType text/plain php
#this wil display php-files in browser (if not, browser will want to download file!)
Thanks to Brad!
My Godaddy setup wont allow me to edit the httpd.conf files, and the php_flag command doesn't work due to how they've implemented php for me.
I was able to use this in my .htaccess file:
SetHandler default-handler
AddType text/plain php
I put this in the directory above where my FTP user is allowed to access, which forces all PHP files in that directory, as well as all sub-directories to show php as plain text.
This will work for other file types as well. All you need to do is add another line with whatever extension of file you want to be forced to display in plain text. AddType text/plain cgi for example
Look at your httpd.conf file for the AddType of .php extension, and change it fortext/plain, and php_flag engine to the offvalue just as sait by Sam Bisbee.
But prefer do these change in the httpd.conf, the .htaccess are useless if you have a dedicated server, and lowing your perfs.
But you can also just change the extensions of your PHP scripts...
Two solutions off the top of my head...
Change their file name extensions to .phps. Ex., index.phps.
Change the Content-type for them in the .htaccess file. AddType text/plain .php uses mod_mime to do this. More info at http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addtype
Turn off the the PHP module in apache? (if you won't be needing php execution, of course)

PHP only coming out with code

I'm honestly not sure exactly what is going on here. I'm teaching myself php and I think I've finally gotten the server working, but now I have more questions. When I plug in the code, I should get a single output. In this case, it should just come out with "hello world." Instead I literally get this:
<?php
echo "hello world";
?>
I'm pretty sure that's not supposed to happen. If I put in the HTML code, it will do exactly the same thing, but with the html code as well. Someone in a chat room mentioned I might have a php configuration problem, but after following another set of instructions online it appears I have nothing wrong.
I'm using OSX 10.7 with the onboard apache server, and I'm testing in Google Chrome. Also, I have to have very specific instructions on how to do something in Terminal since I also have very little formal computer training and therefore have no idea what I'm doing.
Edited: Turns out my files weren't allowing me to access them. A friend showed me how to alter the files so I could view them properly. It was an obscure problem and required a somewhat obscure solution.
Try this page. By default Apache in Lion does not have PHP enabled so you'll need to change the configuration so you can use it.
Looks like, PHP is not enabled!
Open terminal and type!
sudo nano /etc/apache2/httpd.conf
Remove '#' before (You can use search)
LoadModule php5_module libexec/apache2/libphp5.so
Save the conf file and you should have it!
In my Apache for windows I have
LoadModule php5_module "C:/Program Files/PHP/php5apache2_2.dll"
PHPIniDir "C:/Program Files/PHP"
AddType text/html .php .phps
AddHandler application/x-httpd-php .php
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
On any other system it should look alike except paths to files.
Take a look what Nab Raj wrote. After completing it might be needed to restart server. These lines are to say to Apache that it is going to give PHP files that have extensions of .php

Why are my php tags converted to html comments?

A friend's lamp host seems to be misconfigured. I try to execute php, but it doesn't seem to be working.
In Chrome's inspect element:
<?php echo 'test'; ?>
becomes :
<!--?php echo 'test'; ?-->
Furthermore, its been triggering a file download, rather than opening it as a webpage.
I've tried various code in an .htaccess file, but it doesn't seem to have any effect:
AddType x-mapp-php5 .php
AddType application/x-httpd-php .php
AddHandler x-mapp-php5 .php
The place to correctly configure PHP operation is the httpd.conf file, which resides in the conf subdirectory of your Apache installation directory.
In there, you'll want to look for the module loading section, which will be a bunch of lines that start with LoadModule. Somewhere in there, you should have the following (or something very similar):
LoadModule php5_module "location\of\your\php\installation"
AddType application/x-httpd-php .php
PHPIniDir "location\of\your\php\configuration\file"
I'm not all too familiar with Linux, but in Windows (WAMP) installations, those would be something along the lines of:
LoadModule php5_module "c:/program files/php/php5apache2.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:/program files/php"
And the httpd.conf file, on my machine, is at C:\Program Files\Apache Group\Apache2\conf\httpd.conf.
It could also be that PHP is simply not installed at all on your machine, in which case, you will have to download it and install it. Brad's already posted the relevant link in one of his comments, (+1, by the way, Brad), but for the sake of having everything in one spot:
PHP: Installation and Configuration - Manual
Your Chrome is lying to you.
Your PHP source file is <?php echo 'test'; ?>. Because PHP is not executed, this file is sent to the browser. If the browser should interpret this text, it will stumble upon the <? ?> marks. They have a meaning - they are "XML processing instructions", and the text after the opening angle defines the target.
Obviously the browser does not know about a target named "PHP", so this text is ignored.
And then the element inspector tries to display the DOM and is lying about the original source code, because he is working on the PARSED source - which is great because you usually want to know on which data the browser acts, and this includes how the browser interpreted your source.
But if you make any error, the browser will try to fix it, and the fix is included in the element inspector.
Obviously the fix for an unknown XML processing instruction is to disable it by commenting it out.
This just happened to me. Turned out I had forgotten to change the filetype from .html to .php
Sounds to me that your PHP is not correctly configured or installed in your lamp configuration. What distribution are you using? It might be as simple as running a command to re-install PHP, otherwise you will likely need to compile apache with php support.
This answer doesn't apply to the OP's specific variant of this problem, but I had the basic same issue – <? var_dump($test); ?> being converted to <!--? var_dump($test); ?--> – which I could solve by enabling short_open_tag in php.ini.
I was faced with exact same problem when I accidently tried to test local php file in browser on server through file:// protocol, not through installed site.
So the answer is one: "Mr. PHP has left the building". We need to check the configuration, location of a file or access.
And browser is just trying to fix a web page and help us.
If you are placing your code outside the standard directories (development scenario, in my case) you should check in your /etc/apache2/mod-enabled or /etc/apache2/mod-available in the php5.conf (for ubuntu) and comment the lines that the comment indicates:
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_value engine Off
</Directory>
</IfModule>
Sounds like you are using an editor that is changing what you enter. Make sure that what you want in the file is what is actually in the file. Using FTP to upload a php file should ensure this.
I just solved this same problem.
You need to open your file from your WAMP, and not from your hard drive directrory.
In your browser, put: localhost/...../yourfile.php
Otherwise, your browser will replace all <?php ?>
with <!-- ?php ?-->
It seems you have to instruct apache explicitly to handle html files as php files, I was having the same problem but renaming the file to .php solved the issue for me.
On an Ubuntu system, installing the apache php5 plugin worked for me:
sudo apt-get install libapache2-mod-php5
sudo service apache2 restart
I have same problem sometimes, probably the extension of your file is "html".
Change It to "php" and it'll OK.

How to show php-files as plain text in Apache

for a certain folder on my local Apache-Server (running with Ubuntu) I'd like that all *php-files will be displayed as if they were plain text-files. I need this since I only want to see the source code of these files and NOT run them.
While searching, I found that most people have the opposite problem :-) and couldn't really find a solution for me.
What would I need to include in the .htacces-file of my folder?
THANKS!
THE ANSWER:
in .htaccess-file type
php_flag engine off
#This will prevent apache from executing *.php-files
AddType text/plain php
#this wil display php-files in browser (if not, browser will want to download file!)
Thanks to Brad!
My Godaddy setup wont allow me to edit the httpd.conf files, and the php_flag command doesn't work due to how they've implemented php for me.
I was able to use this in my .htaccess file:
SetHandler default-handler
AddType text/plain php
I put this in the directory above where my FTP user is allowed to access, which forces all PHP files in that directory, as well as all sub-directories to show php as plain text.
This will work for other file types as well. All you need to do is add another line with whatever extension of file you want to be forced to display in plain text. AddType text/plain cgi for example
Look at your httpd.conf file for the AddType of .php extension, and change it fortext/plain, and php_flag engine to the offvalue just as sait by Sam Bisbee.
But prefer do these change in the httpd.conf, the .htaccess are useless if you have a dedicated server, and lowing your perfs.
But you can also just change the extensions of your PHP scripts...
Two solutions off the top of my head...
Change their file name extensions to .phps. Ex., index.phps.
Change the Content-type for them in the .htaccess file. AddType text/plain .php uses mod_mime to do this. More info at http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addtype
Turn off the the PHP module in apache? (if you won't be needing php execution, of course)

Apache not handling files correctly (Handler Help)

I'm trying to set up my .htaccess file correctly and I'm having an issue.
The only thing my .htaccess file at the moment is:
AddType application/x-httpd-php .php .html .htm
This is included because my server is not parsing php in my html files.
However when this is included in my .htaccess file, when I open a page in my browser, the user is prompted to save or open the file locally.
I believe the answer to my issues is setting up an action to be done (run with php) however I cannot find out the path to my php files.
Any help is appreciated.
You will need to edit the configuration for enabled modules. On a Debian/Ubuntu type system this will be in /etc/apache2/mods-enabled The file you are looking for is php5.conf
So far all you have done is specify that (dot) htm, html or php files should be served -by default- as application/x-httpd-php, and to my knowledge there is not a single web browser that would attempt to interpret such content -- hence the save-as dialog.
Either you could fix your .htaccess file not to be broken (it is broken behaviour to serve html files as application/x-httpd-php), or you could manually output the correct HTTP headers using the PHP header() function.
Unfortunately, everyone seems to love abusing AddType (and then complain e.g. that MultiViews is broken). See this article, please.
This is not supposed to work in all cases. It depends on the AllowOverride directive of the web server.
You shoud specify the AddType in the serveur config file rather than in the htaccess.

Categories