I'm inheriting some html/php code.
I've installed apache and php on my windows box. At first, things sort of worked until I realized that php.ini is not being sourced. When I changed the path to the ini file to somewhere other than the "Program Files (x86)" dir, the file is sourced, but the code I'm running stops working.
The code has a bunch of places that say <? foobar ?> instead of <?php foobar?>
I tried googling for '<?' vs '<?php', but it ignored the <? parts.
What configuration do I need telling apache that <? means php?
you have to set short_open_tag = On in php.ini. However due to conflicts with XML this is generally seen as a bad idea.
It doesn't look like the best idea. What about creating a script to process the files searching for strings containing "<?" without "php" in order to correct them? Using regular expressions it shouldn't be hard.
Related
I am having the following piece of code in a php file:
<?php
include_once('includes/connection.php');
include_once('includes/article.php');
$article = new Article;
$articles = $article->fetch_all();
?>
<html>....</html>
Instead of getting the expected result, I get the message "fetch_all(); ?>, which means that the above code is treated as HTML comment. I have read the similar threads(that blame the short_open_tag value mainly) around but didn't help me at all. Any ideas?
Edit: Many thanks for your responses. Seems that the specific weird problem was about an update on my Linux system which messed up a little my permissions. I changed the user to http instead of root and the problem is gone.
The problem is somewhere inside either includes/connection.php or includes/article.php. A line in there seems to indicate the start of the comment which goes all the way down to the -> part.
In case you did not installed php. you might look at WAMP server. It includes php en mysql and works great on your local (windows) computer.
http://www.wampserver.com/en/
Is this your output?
Your code isn't being parsed by PHP and there might be several reasons for it:
Check your URL. Does it look like you're fetching the file directly (C:\Users\Name\...) or are you going through your host http://localhost/file.php.
Check your file extensions. Make sure it's .php and not .html.
Check your server capabilities. Is PHP installed?
This specific problem was brought about by an update on my Linux system, which messed up my permissions a little. I changed the user in the Apache directory to http instead of root, and the problem is now gone.
New to php and taking a class for it. Bought php6 and mysql 6 bible to get started. Of course the hello world script is the first you get and it doesn't show. It just reads part of my script and I'm not sure the problem. Link to test - http://harden6615.com/
I am using a hosted server I bought for class, but I have also check it using MAMP. I figured my script is wrong, but I have copied and pasted and still no Hello World. Any suggestions?
What I copied:
<?php
print("Hello, World<BR />\n");
phpinfo();
?>
Safe the file as index.php instead of index.html.
Checklist:
host allows PHP
file has .php extension
file was edited with a programmer's text editor (not word/wordpad under windows or TextEdit under Mac) because some encode <, > symbols when saving the file
Well actually it isn't, try to use just <?php phpinfo(); ?> If this doesn't show anything - take a look at your webhost if he supports php...
There are a few reasons why PHP may not be being executed.
The most basic error is saving the file as a .html file instead of .php. Make sure you use the correct extension on your file.
Next, make sure your webhost supports PHP. Most free hosts do not, so it's always a good idea to double-check.
There is nothing wrong with your code. If the above two solutions didn't help, try contacting your webhost and asking them why PHP isn't working for you.
I have Joomla installed in my computer, but recently have been writing php files that aren't related to the Joomla-managed site. For some reason, when I try to open those php files in the web browser using xampp (note: Joomla also is using xampp), the browser doesn't process the code w/in the tags as php code.
For example, after opening a basic page (a page with title "test", no content except in the body tags) in the web browser and going to the source code, the following is shows up in the source code:
<body>
<?php echo "hello"; ?>
</body>
instead of the HTML conversion. (i.e. just "hello")
Does anyone have an idea about what's going on here?
Thanks.
It's probably because PHP module isn't loaded in your apache. Be sure it is enabled
PHP is interpreted in the server, not the browser. Whatever's going wrong, you need to look at the SERVER side to resolve it.
My first guess: maybe you didn't suffix the file ".php" (so the server doesn't recognize it as a PHP file?)
Second guess: is the directory containing your PHP files configured to parse PHP?
If you have Joomla, you probably have PHP. You probably also have Apache.
So check your Apache configuration, and check your file naming conventions.
Is the file extension .php? The server doesn't magically know when you're serving php files, this is a good way to ensure it knows what you're doing.
Apache is looking into your localhost's defined root directory for files it can parse. In this case htdocs. This is the default for XAMPP. As far as Apache is concerned, it will not interpret any files outside of that folder.
if the problem in php module it better to re install php5 in to the system and it will work fine. probably the problem is in php module you should try re installing php in your system.
Just restart httpd service. It will work fine.
sudo systemctl restart httpd.service
if it has not worked please reinstall PHP once again.
My Environmental Variables (& I crosschecked every possible place in the Registry) show my PHP include path as: "C:\PHP\" --and PHP (5.2.9-2) works fine on the system, so that is correct. However, running
ini_get("include_path")
shows the path as "C:\PHP5\". This causes problems with PEAR, etc. I've searched the system (i.e. php.ini files, httpd.conf, & everywhere else I can think of--there are no .htaccess files) & can find nothing that points at PHP5. Where in the world is this coming from??
Try searching for the literal PHP5 using a grep search tool (like windows grep http://www.wingrep.com/) it will take a while, but I think it's the best approach after you've checked all config files and environment variables.
Cheers
If you run a script with a call to phpinfo() PHP will tell you where the values come from:
<php
phpinfo();
?>
The top table will tell you what php.ini files it's reading and you'll find the value of the include_path directive in the Core table.
Something could be setting it using ini_set.
Or, after running the aforementioned grep on the whole system, you can try these:
Debug PHP to see what causes this.
Use Filemon from Sysinternals to see what files PHP is accessing.
This isn't really an answer to your problem however if you install WAMP or XAMPP you can usually avoid all of these annoying configuration issues.
I took over a PHP project and I'm trying to get it running on my dev box. I'm a developer and not a sysadmin, so I'm having trouble getting it working.
The previous developer used .h files to include PHP. My current configuration is taking that .h file and including it without executing it. What do I need to look for in my apache config (or is it my php.ini)?
EDIT:
Something clicked when I read one of the comments below. The code is using ASP style tags "<?". I've turned the option on in php.ini and according to phpinfo(), it's enabled, but apache is still just including the code as text.
I just checked it and running the code with the full opening PHP tag "<?php" fixes the problem. Having said that, I'd still like it to work the other way.
I'm running the code on a Macbook with the latest versions available. PHP 5.2.6, postgresql 8.3 and apache 2.
The code works on the staging server, but I can't figure out what the difference it.
EDIT
Durrr...I didn't have short_open_tags enabled in php.ini.
Could the problem be that the .h file you are including just starts into php code without the opening "<?php" tag?
From include documentation:
When a file is included, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes again at the end. For this reason, any code inside the target file which should be executed as PHP code must be enclosed within valid PHP start and end tags.
PHP is an interpreted language, so you can't 'include' a file without executing it. Remember that '.h' is just a file extension, so although the previous coder may have put PHP in a '.h' file, it's still just PHP.
More details on the problems you're running into would be helpful.
you can use a .htaccess file and add:
php_value auto_prepend_file /path/to/include-file.h
Edit
I've just read that .htaccess only works with the module version of php.
You should change them all to .php extensions. But, if you are going to leave them as .h, you change the mapping in Apache. It's Apache that runs the file through the proper interpreter, not PHP. The PHP engine will process anything passed to it.
include and require will execute the included file. If you are using readfile, it simply echoes the file without treating it as PHP code.
If the .h files are "missing" the <?php directive, then you may have to switch from include to something like:
eval( file_get_contents("file.h") );
Personally I try to avoid eval whenever I can, but sometimes there is just no choice.