In my ionic app I have an $http.post() that sends user information to my PHP file. The PHP file then calls a proc to store the information in MySQL and echos the success. The problem I'm seeing however is when I log the response to the console, the entire PHP file is printed instead of 1/0, from success. I found that instead of running the PHP file, it just seems to be printed to the log. Is there a way to fix this?
Asked
Active
Viewed 670 times
0
-
I think After doing all the stuff in php file you are not returning anything. try to return 1 or 0 based on success or failure and then check. Also put exit after return value. – Alive to die - Anant May 02 '15 at 23:15
-
That's actually what I have but the entire file is being returned as the response instead of running it – Ph33ly May 03 '15 at 02:46
1 Answers
2
You need to setup the handler for .php
on the server.
In your .htaccess or httpd.conf add this handler.
AddHandler application/x-httpd-php5 .php

Misunderstood
- 5,534
- 1
- 18
- 25
-
Thanks! I can't seem to find the httpd.conf on ubuntu. Would I just add the line to etc/apache2.conf? – Ph33ly May 03 '15 at 00:02
-
Sorry, not a Linux expert. Same thing happened to me years ago. I do believe on Ubuntu that is the correct conf file. You should see similar statements in that file. – Misunderstood May 03 '15 at 00:06
-
Glad you got it working. Good reason not to put passwords in your PHP. I use includes to a file in a non-public directory just for that reason. A simple misconfig and your passwords are exposed. – Misunderstood May 03 '15 at 03:03
-
Yea I completely agree lol but unfortunately when I added the line the problem is still occurring. I've been fighting with the thing for a while now. – Ph33ly May 03 '15 at 03:09
-
You can do it by creating an .htaccess file in the same folder as the script like this: http://stackoverflow.com/questions/17495382/apache-2-server-on-ubuntu-cant-parse-php-code-inside-html-file – Misunderstood May 03 '15 at 03:18
-
When I create the file would I need to include the AddHandler line in addition to `AddType application/x-httpd-php5 .html .htm`? Because I tried creating the file as instructed but with no avail – Ph33ly May 03 '15 at 03:52
-
NO! That is for someone that wants to make their PHP work with an .htm or .html extension. They don't want users to know it is PHP. Only the one line: `AddHandler application/x-httpd-php5 .php` – Misunderstood May 03 '15 at 03:55
-
-
Or I can let you put your stuff on my Shared Server. I can create an account for you. – Misunderstood May 03 '15 at 03:58
-
Though I would really appreciate that, I can't just because I'm working with someone else's system/database. And sorry about before, I tried changing the .htaccess file to the correct line but the php is still being printed. I'm starting to think there might be a problem with my lamp installation.. – Ph33ly May 03 '15 at 04:24
-
It's not supposed to be this difficult. A lot of the times when something like this happens, it is some small stupid detail that was over looked. – Misunderstood May 03 '15 at 04:35
-
Well I have the.htaccess file in my script directory which is inside the public_html. I took out the changes in apache2.conf. Maybe it's an issue with CORS when I use ionic serve? I have a CORS extension on my chrome browser and I have to include http://localhost:8100 to the url's or else I get an XMLHTTPRequest error. – Ph33ly May 03 '15 at 04:47
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/76794/discussion-between-misunderstood-and-get-otter-here). – Misunderstood May 03 '15 at 04:48
-