This question already exists:
PHP's white screen of death [duplicate]
Closed 7 years ago.
I am trying to make use of RESTful service using php. I am able to get the JSON format output wen i run the php file through terminal. But if I try running it using apache webserver i am getting a blank web page. please help me.
<?php
$client=curl_init("http://wwwdev.ebi.ac.uk/pdbe/api/emdb/entry/map/EMD-1200");
curl_setopt($client,CURLOPT_RETURNTRANSFER,1);
//get response from resource
$response=curl_exec($client);
echo $response;
//decode
// $res=array(json_decode($response));
// echo $res;
?>
This is my code.
Run
phpinfo();
and make sure you have curl enabled!
If not then uncomment this line from php.ini.
;extension=php_curl.dll
Then restart your server.
Related
This question already has answers here:
How to update a website without making it go down?
(3 answers)
Closed 3 years ago.
when I update a php file via ftp (filezilla), pages using that file stop to work until transfer is complete. The server is linux with nginx/php-fpm, but I had the same problem with apache. The only "solution" I found is to edit directly the php file on a server remote shell, and update the content. But this is a very uncomfortable solution.
Is there anybody with a better solution?
Thanks
It is normal if you are doing upload via FTP. the Best solution is using Continues Deployment services with zero downtime approach.
Continuous deployment without downtime
But if you talk about one file. You can just check php file if it exists or correct uploaded file else you can use old copy of this file.
Somesthing like this :
$file = 'uploaded.php';
$oldFile = 'uploaded_old.php';
if (file_exists($file)) {
require_once($file);
} else {
require_once($oldFile);
}
This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 3 years ago.
Firefox is not interpreting PHP code at all.
I have already tried activating PHP via terminal (I am on a mac). I have tried a total of 5 different browsers. Chrome, Brave, and Opera simply downloads the PHP file, Safari is weird about FTP and Firefox has the problem explained below. I have tried replacing all instances of ">" with >. All files have a .php extension and are in the same folder.
Viewing a simple PHP file on an FTP server, Firefox either displays a blank page with PHP code such as:
<?php
echo "Hello World!";
?>
or stops at the greater than sign (>) in code such as:
<?php
echo "<P>Hello World!</P>";
?>
In the above instance, the browser displays, in plain text:
Hello World!
"; ?>
This is not the code I am using, obviously, but my more complex code is having the same problem - namely not working at all or stopping at the greater than sign.
Any help would be greatly appreciated. Full Disclosure: I am very much a beginner at this.
The fact is that your web server is not properly configured. What you see is a text and your browser tries to show to you as a plain HTML (or even download it as a file). Your web server "believes" that this file is a plain text and you get it as is without any modification by PHP.
You should configure your web server (usually, PHP + Apache/Nginx) to execute .php files. I also highly recommend you play with <?php phpinfo(); instead of <?php echo 'Hello World'; to understand that PHP is able to launch .php files.
More detailed answer about the server configuration can be found in the Google by the search request "Mac LAMP" or "Mac LEMP" depends on your desired web server (A = Apache, E = nginx).
This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 6 years ago.
I created a database table using phpmyadmin and MySQL. Im trying to establish a connection to my database using a PHP script. Ive searched all alone and have found the right syntax and script to establish a simple connection. When i run the php file on my live server, the browser simply displays the actual code of the php file rather than a error message or any output.
Here is my php script that i am working with.
<?php
$username = "*******";
$password = "********";
$hostname = "*********";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL <br>";
?>
Any help or direction as to what might be causing me to have absolutely no output?
Because my duplicate flag was disputed despite this entire question being about PHP not rendering and the raw source being displayed instead I'm just going to quote #schmeeps' original answer. It's very thorough and covers a lot of the possible reasons PHP might not be being processed. If you found it useful, upvote the original answer here.
Sounds like there is something wrong with your configuration, here's a
few things you can check:
Make sure that PHP is installed and running correctly. This may sound silly, but you never know. An easy way to check is to run php
-v from a command line and see if returns version information or any errors.
Make sure that the PHP module is listed and uncommented inside of your Apache's httpd.conf This should be something like LoadModule
php5_module "c:/php/php5apache2_2.dll" in the file. Search for
LoadModule php, and make sure that there is no comment (;) in
front of it.
Make sure that the http.conf file has the PHP MIME type in it. This should be something like AddType application/x-httpd-php .php. This
tells Apache to run .php files as PHP. Search for AddType, and then
make sure there is an entry for PHP, and that it is uncommented.
Make sure your file has the .php extension on it, or whichever extension specified in the MIME definition in point #3, otherwise it
will not be executed as PHP.
Make sure you are not using short tags in the PHP file (<?), these are deprecated not enabled on all servers by
default. Use <?php instead (or enable short tags in your php.ini
whith short_open_tag=On if you have code that relies on them).
Make sure you are accessing your file over your webserver using an URL like http://localhost/file.php not via local file access
file://localhost/www/file.php
And lastly check the PHP manual for further setup
tips.
From a website I'm developing, I'm sending a Curl request to a php file (on the same server) that should process the request and return a response. The response I get is the contents of the php file that is supposed to process the request.
It's all run on Ubuntu 13.10 server.
This problem is not related with your curl. Rather its related with your php configuration. I am suspecting this problem is related to php short tag.
For example your server might have the php code started with <? instead of <?php. If this is true, then you have to enable the short_open_tag=On from your php.ini file. Here is more detail about How to enable PHP short tags.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Read pdf files with php
Hi,
I have a bulk of pdf documents. I want to read that using php script. I searched a lot, but everyone is about creating pdf files. Here I dont want to create pdf file but I want to read it. Is there any way to read it php?
-Arun
To just get the text from a PDF file, try these:
- http://davidwalsh.name/read-pdf-doc-file-php
- http://www.webcheatsheet.com/php/reading_clean_text_from_pdf.php (more in-depth)
For a more heavyweight solutions, have a look at:
- http://www.setasign.de/products/pdf-php-solutions/fpdi/
You can easily read the contents of a PDF file using a command-line utility like Pdftotext which you can call through exec.
This is an example of what i mean, actually using system
system("pdftotext your.pdf /tmp/txtfile.txt");
$text = file_get_contents("/tmp/txtfile.txt");
EDIT
didn't know about the dash syntax - this is even better:
$content = shell_exec('pdftotext your.pdf -');
This does require pdftotext to be installed on your server though. On a CentOS server this would be:
yum install xpdf