I don't know how to search for it, so I'm asking you here.
Situation is the following:
Got a vServer with root. Apache, PHP5, MySQL installed and running.
Now I have an index.php where I want to include 'config.php';. Simple thing!
In the config.php I have a variable like $url = 'http://xxxxxxx';, but I cannot access it in the index.php. There's just an empty Array, when I print_r(parse_url($url)); it.
The curious thing is, when I'm connected with ssh to the server and run php index.php, the output is the whole array as expected.
Do you have any idea?!
Have you tried to include your config.php with absolute path, eg. include('/var/www/config.php');
The best strategy for a config file would be having it written in the following format:
<?php
return array(
'url' => 'http://xxxxxxx',
...
);
Then in your index.php you can do $config = require('wherever/it/is/config.php') and access your parameters like $config['url']. Otherwise you would probably have to use globals which is almost never a good practice.
Damn, I'm so stupid.
I had something like:
config.php
foreach {
if(true){
something;
return false;
}
}
$url = ...;
I just wanted to stop the foreach if it was successful. Maybe worked too good..
But I don't understand, why it hadn't any errors when phping it in the terminal..
Thank you guys!
Related
My copy code doesnt work for some reason. Tried several things.
this is the code that I am trying to use
$fb_foto_url = $userData['picture']['data']['url'];
$plaats = '/assets/images/profielfotos/fiel.jpg';
copy($fb_foto_url, $plaats);
The $userData['picture']['data']['url']is getting filled with this for example: https://lookaside.facebook.com/platform/profilepic/?asid=113831052838678&height=200&width=200&ext=1527931138&hash=AeSlklMNX6l4Uanh
I need that to get stored in on the server. But it isn't working for some reason. I am doing something wrong but can't figure out what.
If someone can help me with this code, would be nice.
Try this:
file_put_contents($plaats,file_get_contents($fb_foto_url));
PHPs copy function expects path's, not URL's.
A (server-) path is a directory name on the machine the PHP code is executed on.
An URL is a virtual name that may or may not point to such a physical path or is resolved dynamically.
Example:
The server path to a websites images might be /var/www/example.org/assets/images/, while the URL is http://example.org/assets/images/.
http://php.net/manual/en/function.copy.php
I am running a PHP site on Windows using Wampserver. All throughout the site there is a hardcoded line such as:
$settings = parse_ini_file("/usr/local/apache2/myconfigs/settings.ini", true);
I know this is bad practice to begin with but it is out of my control.
When the site runs is there any possible way I can trick the site to point to C:\wamp64\bin\apache\apache2.4.27\myconfigs\settings.ini whenever the code is looking for /usr/local/apache2/myconfigs/settings.ini in the parse_ini_file function?
$settings = parse_ini_file(APACHE_INI_PATH, true);
// $settings = parse_ini_file("/usr/local/apache2/myconfigs/settings.ini", true);
This is a bit hackish but I think it's what you are looking for, so the trick here is to redefine the parse_ini_file function and make it ignore the invalid passed path ("/usr/local/apache2/myconfigs/settings.ini") and use your correct file instead.
This seems straightforward but a bit tricky since your new function should also call the original parse_ini_file function somehow, that's why you need to rename it first then override it
You will need PHP runkit extension enabled for this, have look at runkit_function_redefine and runkit_function_rename for reference.
Untested but should work, the code should be something around these lines :
runkit_function_rename('parse_ini_file','original_parse_ini_file');
runkit_function_redefine('parse_ini_file', function() {
original_parse_ini_file("C:\wamp64\bin\apache\apache2.4.27\myconfigs\settings.ini", true);
});
Make sure the code above is executed at the start of your application script and any parse_ini_file call should use your file instead of the hardcoded one.
If there is no single entry point to your application where you can put the code above, you can put it in a separate script and make PHP load before running any script via the auto_prepend_file setting in your settings.ini file, also make sure that runkit.internal_override is set to On since parse_ini_file is not a user defined function.
Hello please check this
runkit_function_rename('parse_ini_file','o_parse_ini_file');
runkit_function_redefine('parse_ini_file', function($p1,$p2) use($someCondition) {
if($someCondition)
o_parse_ini_file("C:\wamp64\bin\apache\apache2.4.27\myconfigs\settings.ini", true);
else
o_parse_ini_file($p1,$p2);
});
it can return
Call to undefined function runkit_function_rename()
to fix this error please read here
or here
If you don't want to do a find and replace as suggested by #cddoma, I propose that you create the directory /usr/local/apache2/myconfigs/ in your windows machine, and copy the file settings.ini from C:\wamp64\bin\apache\apache2.4.27\myconfigs\settings.ini to that directory.
Open your windows command line and enter the following
mkdir C:\usr\local\apache2\myconfigs\
copy C:\wamp64\bin\apache\apache2.4.27\myconfigs\settings.ini C:\usr\local\apache2\myconfigs\
you may be able to do this with a Symbolic link on Windows
I'm trying to figure out how to add to a PHP data array externally using PHP.
Say if this array, below. Was in a file called Index.php
$data=array("user1"=>array("url"=>"user1.pdf","password"=>"pass1"),
"user2"=>array("url"=>"user2.php","password"=>"pass2"));
and I wanted to add third user using a different Php file taking inputs from somewhere else to insert into the url, password and user namespace.
Thanks.
$data['user3']=array("url"=>"user3.pdf","password"=>"pass3")
I believe include_once() or require_once() should do the trick.
include_once('index.php');
array_push($data,"user3"=>array("url"=>"user3.pdf","pass"=>"123"));
include_once or require_once functions are similar to executing that file once and continuing further. http://in1.php.net/include_once
Alternatively, php now allows for object-oriented programming, so if you are familiar with it you can take a shot at that
If you need it from different file, then the simplest way is to include the other file, which adds users to $data.
index.php
$data = array(
"user1"=>array("url"=>"user1.pdf","password"=>"pass1"),
"user2"=>array("url"=>"user2.php","password"=>"pass2")
);
other_file.php
include "other_file.php";
$data["user3"] = array("url"=>"user3.php","password"=>"pass3");
// or
array_push($data, array("user3" => array("url"=>"user3.php","password"=>"pass3"));
Are you sure you need that other file?
I have a php file on my server that takes in two inputs through the URL and then comes back with a result. When a page is loaded, I'd like to have the result of that calculation already loaded. For example:
$var = load("http://mysite.com/myfile.php?&var1=var1&var2=var2");
I know that load isn't a real function for this, but is there something simple that suits what I'm looking for? thanks
Use file_get_contents
$foo = file_get_contents('http://mysite.com/myfile.php?&var1=var1&var2=var2');
Or, a better solution if the file is located on your server:
include('myfile.php');
and either set the $_GET variables in the included script itself, or prior to including it.
If they are running on the same server, consider calling the script directly?
$_GET["var1"] = "var1";
$_GET["var2"] = "var2";
include "myfile.php";
You could use file_get_contents, but it may be a more practical solution to simply include the file and call the function directly in the file, rather than trying to manually load the file.
I'm new to PHP and I seem to be doing something wrong. On one hand, I have a Perl script that looks like this:
use LWP::UserAgent;
my $browser = LWP::UserAgent->new;
my $url = 'https://url/index.php';
my $response = $browser->post($url, [
"command" => "test",
"data" => "123"
]);
die "Error getting $url" unless $response->is_success;
print $response->content;
On the server, the index.php file looks like this:
<?php
if($_SERVER['REQUEST_METHOD'] == "POST"){
echo "Hello!\n";
}else {
echo "Error\n";
}
?>
And... that's it. If I try to execute the Perl script, however, it prints the whole index.php file, instead of Hello! or that other error message. I guess it makes sense that I'm requesting a file and that's what it's printing, however I'm quite confused about what it is I'm doing wrong. I've been looking around for examples for a while but I've found nothing so far that could point me in the right direction.
I think the problem here is that the server doesn't know that it should be treating the PHP file as PHP. Instead of parsing/interpreting it it's just returning it.
Make sure that you have PHP installed on the server and then make sure that the following line is in your Apache config:
AddType application/x-httpd-php php
Sounds like you don't have PHP set up on your server.
Here's some info on the steps required to get it up and running on Apache. Even if you have the module installed, you are likely missing some httpd.conf configuration steps.
Can you load https://url/index.php in your web browser? My first guess would be that your Webserver isn't executing PHP and is just outputting the contents of the index.php file.