PHP error after new install of xampp - php

I was recently switched computers at work, and am trying to get all my projects up and running again. I am working on testing some php/html/javascript pages for a website using a local xampp server. I had everything working properly on the only computer, but when I try to load the pages now I get the following error:
Uncaught SyntaxError: Unexpected token <
I have tried a php-only test page, so I know the sever is capable of parsing php.
I also know it is not the short tag issue, as all of the php code is wrapped in
<?php...?>
Are there any other configuration settings that would be causing this issue?

The error message doesn't look like a PHP error. Check this discussion maybe you can find the solution there.
It seems the error is reported by Google Chrome when it expects to parse a .js file and it finds HTML (or PHP?) instead.

I think it is a JavaScript error, you should check your js code, not php.
The following reasons might cause this error:
href attribute value "javascript: void ()", no brackets add "0"
Button // error
Button // correct
Non-compliant JSON string
etc.

Related

XML Parsing Error: xml processing instruction not at start of external entity

I have a vBulletin 3.8 forum.
When we click Edit button of any post (so the Quick Edit form should displayed), I get this error on the browser's console:
XML Parsing Error: xml processing instruction not at start of external entity
Location: http://www.xxxxx.xx/ajax.php?do=quickedit&p=438
Row number 2, Column 1:
... the Quick Edit form is not appearing the the progress bar displayed permanently.
I have try to disable hooks/ plugins, but the problem still appears.
I have this row on config.php: ini_set("display_errors", false); so I don't think it is a fatal error/ warning by PHP which brokes the xml normal syntax.
I have informed that this appear starts after the move of the site to another server. Does it say something to you?
Any general idea about this error?
EDIT:
Well, I found the reason of this issue, but I don't know how to fix it. Exact the same site on a localhost testing board works perfectly, but on the live server ANY html page/ ajax call etc, has a useless empty line as line #1.
For normal html pages, there is no reason for the browser to return an error, but when we're talking about an ajax call, this empty line at the top of the response, breaks the xml parsing from the browser. So it seems it is a server/ PHP/ Apache setting that applies this empty line. Any idea how to fix it? https://imgur.com/a/4neb0
It might be late for you but any new comers with php/nginx/apache can get an understanding of why.
Answer is simple: When moving the code, you might not be using git/rsync/scp but let me guess, you used zip (and probably Windows/Linux involved).
How to discover it was a two-day journey with many things tried:
We have the same error, we were also moving our servers. We tried:
We thought the server software version was a problem.
We thought the cloud provider OS image was a problem.
We used docker to avoid these problems, but the empty line problem persists.
We thought the code ?> ending was a problem, I went through all of them. But it wasn't.
I finally asked my colleague: How did you get the code? From Git? He said he downloaded from ZIP and then uploaded to server.
I removed code on the server (which extracted from a zip) and used git to download a fresh copy from our github.
Magic, problem solved. The empty line gone.
So I think the problem is with the zipping progress might have changed some file empty lines. Always use git.

Http request failed after site migration - server issue

So I have a website built in php and it was working perfectly on one server, I then moved the website to a server I have on Digital Ocean and am running into several errors, they seem to be based around http request failures while using the imagick library...
I was hoping to not to have to start debugging this from a code point of view as it was already working perfectly and would prefer to change server settings.
Fatal error: Uncaught exception 'ImagickException' with message 'Imagick::__construct(): HTTP request failed! HTTP/1.1 404 Not Found .
I cannot figure out what differences there, on both server allow_url_fopen is set to on.
The php version is different, 5.520 on the original server, 5.5.9 on the new server.
The versions of imagick are the same. I am also getting some other errors using the mpdf library but I will try deal with these later (Im hoping if I can resolved the first ones these ones will also get resolved).
My question is , is there possibly any other setting on the server I should be looking out for that may be causing these php errors?
EDIT:
Just to add more information, i can get rid of some of the errors by changing the file path https://www.example.com/myimage.jpg to /var/www/example/myimage.jpg . This solves some of the errors but I would rather get the root of the issue thats causing it not to work in the first place, because I feel that its the same problem thats causing other errors.
The error code says it: 404, file not found. You are probably using the wrong URL.
Are you able to fetch https://www.example.com/myimage.jpg using a webbrowser?
On several popular linux distros, /var/www/example/myimage.jpg would be served at https://www.example.com/example/myimage.jpg instead of https://www.example.com/myimage.jpg with the default configuration.
[edit]
It just came to my attention that the URL is HTTPS, there is a possibility that the script is rejecting the server certificate. Try with regular HTTP - no point in using SSL if the file is on the same machine.

json_decode doesn't work in local server

I just installed my first LAMP and NetBean in Ubuntu. I imported a small website and tried to run it both locally and remotely, but the pages that use json_decode (and other functions) don't work on the local server.
For example this page:
<?php
echo "X ";
var_dump(json_decode("{}"));
echo " Y";
?>
On the managed server shows X object(stdClass)#1 (0) { } Y, but on the local server shows X only.
I ctrl+clicked on the json_decode function name, and the file json.php opened with a json_decode function with the empty body. I don't understand if that's just the definition of an interface or the real function (I'm learning PHP), but the fact that the rendering stops there, without error messages, sounds weird.
UPDATE:
I uninstalled all the packages listed at the "Starting over" section in this page, and re-installed with sudo tasksel install lamp-server.
The next day there was a massive automatic update. I don't know if there is a relation between the installation and the update, or if the update would have come anyway.
Right now I'm still at the same position: some pages are rendered correctly locally, but my website uses json on almost every page, so I can't use the local server. (I was hoping to be able to use it in the next days, when I will be visiting the in-laws, where Internet is still an unknown concept.)
UPDATE 2:
The fact mentioned earlier that json_decode() has an empty body is not a problem. I just right clicked on session_start();, and the file session.php opened with the function defined as function session_start () {}. I don't understand why the library functions contain empty bodies, but session_start() works, so json_decode() should as well.
The fact that you are not seeing the "Y" would probably indicate a fatal error occuring during your json_decode (you could use ini_set("display_errors",1); at the top of your script to be sure)
The fatal would probably be something like:
PHP Fatal error: Call to undefined function json_decode()
Do some googling on that error. This post may help, if I am right about the fatal error:
PHP Fatal error: Call to undefined function json_decode()
Try installing the json extension separately. I think it's called php-services-json on Ubuntu, so run apt-get install php-services-json
Try not to use LAMP and install apache2 manually try if that works, maybe the LAMP package is causing you trouble. That is if you're not afraid of some extra work.
You could also check your configs if they forbid anything.

PHP - Weird behaviour after calling functions in a map

I'm experiencing quite a strange reaction from the browser when invoking this PHP script.
<?php
$map = array(
'a' => function(){
print_r('a');
},
'b' => function(){
print_r('b');
}
);
$map($_GET['v']);
?>
I already noticed that there is a mistake there. The syntax of the call is wrong, as it should be like this:
$map[$_GET['v']]();
The thing is that the reaction of the browser to this mistake is not what it should be.
The result of running this script is a 'The connection was reset' message. The server is up and running correctly, as other PHP files (and this one after correcting the mistake) run perfectly.
But what is actually puzzling me is what the navigation bar of the browser does. When I punch in the URL
localhost/cerdo.php?v=a
the content of the bar changes to
www.localhost.com/cerdo.php?v=a
The www.localhost.com part seems to happen only in Firefox. I've tried it on Chromium and, despite showing a similar message ('No data received') the URL stays the same.
What is happening? Does this make any sense? Shouldn't PHP be reporting a syntax error? And why on earth would Firefox redirect to www.localhost.com?
Shouldn't PHP be reporting a syntax error?
No. If PHP is not reporting $map($_GET['v']); as syntax error is because it is expecting the code to be syntactically valid. So it ends up executing some very weird stuff that you are not expecting. This results in redirecting your browser to some unexplainable location.
The key here is to understand what $map($_GET['v']); actually means.
The redirection doesn't have anything to do with your code. How is your environment setup, e.g. are you using Xampp etc.? In that case make sure there is any index.php or .htaccess or anything else that contains a redirection script in your web root.
If it's not your first time with you dev enviroment, please ignore this:
I think your problem is: the OS couldn't recognise the domain name (and the OS extends it).
Under Windows you can find the 'hosts' file here:
"%SYSTEMROOT%\System32\drivers\etc\"
Add this line to the end of the file:
127.0.0.1 localhost
(Maybe you should restart your computer.)
It should solve your

Issues on eclipse generated php files uploaded through ftp

I have uploaded my PHP project created using Eclipse-PDT to the siteground server.
After completing the upload, i tried to run the php pages and it throws an error saying "Expected End of statement".
Then i logged in to the CPANEL and found that all the line breaks are removed from the script. since i have used "single line comments" in my php script ,its throwing error(next line will also append to the previous line)
can anybody help to solve this issue? i have a lot of php pages ,so its not possible to remove all single line comments from all the pages.
Maybe its caused by different file encoding?
Check which format is used in your editor.

Categories