I have a split and explode function which I'm using on my website to show data but for some reason when I place the code into my production file and run it nothing comes up. The same code works perfect when I test it on a local server though...
<?php
$page = file_get_contents("https://www.ato.gov.au/tax-
professionals/prepare-and-lodge/due-dates/");
$split = explode("</span><h1>", explode("</span></Div>",
$page)[0])[1];
$split = str_replace("/tax-professionals/",
"https://www.ato.gov.au/tax-professionals/", $split);
echo $split
?>
Please check your allow_url_fopen is on in your php.ini file on production server.
You can also check it via
echo phpinfo()
Related
i need to call one variable (keyword) from remote php file (config.php) --> server2
and to include in php function which is in another web server
i know by default php doesnt allow inclusion
is there any way around for me to get the variable without setting allow_url_include on
this is the function.php on server 1
<?php
include('config.php');
if ($_GET){
$req_url = $_SERVER['QUERY_STRING'];
$page = substr($req_url, strrpos($req_url, '=')+1);
$number = (int)$page;
$xurl=('https://example.com/?q=' . $keyword .'');
}
echo xurl;
?>
and here's the config.php on server 2
<?php
$base="http://example2.com";
$baseurl="http://example2.com/get.php?";
$basejson="http://example.com/function.php";
$keyword = "mountain";
?>
No, you cannot do that. It would be an extreme security gap.
If you have access to the remote webserver you may do an scp via exec and copy the file to your local server on each request. Or define a caching time and do it once every hour or whatever.
I have the following code within some code i wrote:
foreach ($appfields as $key => $field) {
if (isset($app->{$field}) && isset($app->{$field}['und'][0]['value'])) {
$node->{$contactfields[$key]}['und'][0]['value'] = $app->{$field}['und'][0]['value'];
}
}
i added an echo after the foreach with this:
$app->{$field}['und'][0]['value']
and on my staging server it prints nothing; but on my local dev machine it works correctly.
Has anyone ever come across this syntax not being supported? The staging server is running: PHP Version 5.5.9-1ubuntu4.25
there is no error message generated; it simply doesn't evaluate the code correctly.
found my mistake.. oops... $appfields items had newline characters at the end. The server was linux, which cared, the dev machine was Windows, which didn't care. I added trim() in function which builds $appfields and now it works on both machines. Thank you for the hints.
Really stumped on this one and feel like an idiot! I have a small PHP cron job that does it's thing every few minutes. The client has requested that the app emails them with a daily overview of issues raised....
To do this, I decided to dump an array to a file for storage purposes. I decided against a SQL DB to keep this standalone and lightweight.
What I want to do is open said file, add to a set of numbers and save again.
I have tried this with SimpleXML and serialize/file_put_contents.
The issue I have is what is written to file does not correspond with the array being echo'd the line before. Say I'm adding 2 to the total, the physical file has added 4.
The following is ugly and just a snippet:
echo "count = ".count($result);"<br/>";
$arr = loadLog();
dumpArray($arr, "Pre Load");
$arr0['count'] = $arr['count']+(count($result));
echo "test ".$arr0['count'];
dumpArray($arr0, "Pre Save");
saveLog($arr0);
sleep(3);
$arr1 = loadLog();
dumpArray($arr1, "Post Save");
function saveLog($arr){
$content = serialize($arr);
var_dump($content);
file_put_contents(STATUS_SOURCE, $content);
}
function loadLog(){
$content = unserialize(file_get_contents(STATUS_SOURCE));
return $content;
}
function dumpArray($array, $title = false){
echo "<p><h1>".$title."</h1><pre>";
var_dump($array);
echo "</pre></p>";
}
Output View here
Output File: a:1:{s:5:"count";i:96;}
I really appreciate any heads up - Have had someone else look who also scratched his head.
Check .htaccess isn't sending 404 errors to the same script. Chrome was looking for favicon.ico which did not exist. This caused the script to execute a second time.
I got a very strange problem.
Today I tried to implement caching into my PHP application.
It works like a charm on my localhost WAMP server (Windows 8).
But it does not work online.
Hence I do not have a clue what I am doing wrong.
The code is somewhat like:
<?php
function write_cache(){
$contents = ob_get_contents();
/// do something with contenst (like writing it..
}
$tpl_content = 'loooooong string'; // gets filled throughout the application
echo $tpl_content;
/// should be filling the cache
write_cache();
?>
This should work. I echo it hence it is in the buffer.
And I am somewhere doing it correctly because locally it is working.
But online it remains empty..
Does anyone know what I am doing wrong??
Thanks in advance!!
#faintsignal
You where right!! ob_start(); was missing.
It is probably not needed on a WAMP server.
But on a LAMP server it is needed.
The code now looks like:
<?php
ob_start();
function write_cache(){
$contents = ob_get_contents();
/// do something with contenst (like writing it..
}
$tpl_content = 'loooooong string'; // gets filled throughout the application
echo $tpl_content;
/// should be filling the cache
write_cache();
?>
And it works!!
Thanks!!!!
I’m using DOMDocument to retrieve several bits of text from a webpage and place them into an array. The same code works on another server, yet doesn’t on mine. I get Trying to get property of non-object for each iteration of the while loop and the array remains empty at the end.
$html = file_get_contents("http://sugarkettle.site44.com/catering.html");
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML($html);
libxml_clear_errors();
$meatPrices = array();
function fillArrayFromDOM($array,$type) {
global $doc;
$i = 0;
$label = 1;
$array = array();
while ($label <= 15):
$array[$i] = $doc->getElementById($type.$label)->textContent;
$i++;
$label++;
endwhile;
return $array;
}
fillArrayFromDOM($meatPrices,"meat");
echo var_dump($meatPrices);
Here’s a link to it working:
http://www.evintr.com/willtest.php
He’s running a GoDaddy server and I have a local WAMP (2.2) server. Any configuration options I can provide that might explain why this is happening? Or does the problem have nothing to do with my server config?
Any help much appreciated. Thanks in advance!
Update 1 - 11/16/12
On my server, I've tested $meatPrices[1] = $doc->getElementById('meat1')->textContent; and it works. For whatever reason, inside the while loop the same expression (except with variables in the getElementById parameters) tosses an error: Trying to get property of non-object.
Update 2 - 11/17/12
My WAMP server is running PHP version 5.3.13.
My friend's server is running PHP version 5.3.6.
Try with adding allow_url_fopen=on in your PHP configuration file (php.ini). Save it and restart Apache; it should work...
EDIT:
Check also if you have extension php_openssl.dll enabled (extension=php_openssl.dll in your php.ini file). Again, restart of Apache would be required.
EDIT:
It depends on PHP version you have but here are two potential solutions:
replace line fillArrayFromDOM($meatPrices,"meat"); with
$meatPrices = fillArrayFromDOM($meatPrices,"meat"); You can also
change your function to remove necessary $meatPrices parameter).
or
replace line function fillArrayFromDOM($array,$type) { with function fillArrayFromDOM(&$array,$type) { //note new character &; it will keep reference to $array variable so it could be changeable; you can also remove line: $array = array();
Both should work; I am in rush have no time to wait on your comment response. Let us know what you get...