Viewing PHP properly with my Localhost using XAMPP - php

This is my first attempt at using a localhost while editing PHP website files (I'm a HTML girl, but have been asked to make some aesthetic changes to a PHP site).
I've installed XAMPP on my Mac already and configured it (as far as I know). MySQL Database, ProFTPD, and Apache Web Server are running. I've succeeded at viewing a simple index.php file from the htdocs files using localhost/index.php. I've placed the entire website directory (named newsite) inside the htdocs folder. When I attempt to view the website in Firefox or Safari via localhost/newsite/index.php I get this message in the browser:
Warning:
include_once(/Applications/XAMPP/xamppfiles/htdocs/inc/simplepie.inc):
failed to open stream: No such file or directory in
/Applications/XAMPP/xamppfiles/htdocs/newsite/index.php on line 2
This is referring to a block of PHP at the beginning of the index.php document. I've checked, the simplepie.inc file is in file inc under file newsite. If I try go around it by commenting out that section of code and any related calls, the browser goes blank. Can anyone please tell me what else I need to do to just view these files via localhost?

Okay, this is simple but might be complex. So you state:
I've checked, the simplepie.inc file is in file inc under file
newsite.
And then the error states:
Warning:
include_once(/Applications/XAMPP/xamppfiles/htdocs/inc/simplepie.inc):
failed to open stream: No such file or directory in
/Applications/XAMPP/xamppfiles/htdocs/newsite/index.php on line 2
So the error is being thrown because it is trying to read this file:
/Applications/XAMPP/xamppfiles/htdocs/inc/simplepie.inc
But it is located here:
/Applications/XAMPP/xamppfiles/htdocs/newsite/inc/simplepie.inc
What are the actual contents of that include_once?
Since you will probably be moving this site from one place to another, I recommend doing this. I am assuming I know what your include_once looks like, but the general concept holds true.
First, in your index.php or main config/init file (if you have one) add this line:
$BASE_PATH='/Applications/XAMPP/xamppfiles/htdocs/newsite';
Then for your include_once change it to read:
include_once($BASE_PATH . '/inc/simplepie.inc');
Basically that will do the equivalent of changing the include_once to this:
include_once('/Applications/XAMPP/xamppfiles/htdocs/newsite/inc/simplepie.inc');
But the flexibility of using $BASE_PATH is it allows you to change the general site $BASE_PATH in one place & then use it wherever in your site you wish.

Related

PHP Form on WordPress (4.6.1) site

forgive me if is a basic question...
I am working on setting up a form on our new hosted Wordpress site - currently hosted inhouse on IIS/PHP/Wordpress server (I am not JR - but this stuff escapes me and would really like to figure it out!! I hate not knowing)
The OP that made the form / got it working is no longer around and I am sure there is a better way but this is what I have - a request form.
When I load the required files in the same path - copy the code from the WP page and paste it in the new Wordpress page - it loads without formating, the pick box doesnt look right and when I submit the form - I get these below PHP file errors. I can open the path in my browser and it exists - I see the class.GA_Parse.php file)
I checked execustion rights on the scripts - its set to execute - apart from that I dont know why it cant fine the files and that include_path I dont see via my hosting companys dir structure via FTP.
Any help would put me forever in your debt, I hope to be able to return the help, this site looks amazing!
Cheers,
Warning: require(/gaparser/class.GA_Parse.php): failed to open stream: No such file or directory in /home/comany/public_html/stage/forms/getfreetrial_v3.php on line 4
Warning: require(/gaparser/class.GA_Parse.php): failed to open stream: No such file or directory in /home/company/public_html/stage/forms/getfreetrial_v3.php on line 4
Fatal error: require(): Failed opening required '/gaparser/class.GA_Parse.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/company/public_html/stage/forms/getfreetrial_v3.php on line 4
PHP will load pages based on the disk location, not the URL. This means it's starting in the server's root / directory, not in /home/company/public_html/stage/forms. When including a file, either you have to use a relative link:
require('./gaparser/class.GA_Parse.php'); // starts in the same directory as the file
Or use PHP's server variable to get the document root:
require($_SERVER['DOCUMENT_ROOT'].'/gaparser/class.GA_Parse.php');
The paths may need to be tweaked depending on where the file actually is.

require_once in PHP giving errors on new server, but not on original

I am in the process of moving a PHP website from a shared hosting server to a DigitalOcean server. I have come across an issue that I'm not sure how to debug.
There is a page that has a log-in form with action=2/login.php. This form is located in /var/www/html/calendar.php (it is a Ubuntu 14.04 DO droplet). When submitting the form, there is a 500 Internal Server Error. I've found the error in question but I am not sure how to debug it (because it runs fine on the other server).
/var/www/html/2/login.php
<?php
require_once('../db_connect.php');
...
db_connect.php is located at /var/www/html/db_connect.php
When I $php 2/login.php I get the following error:
login_error.txt
PHP Warning: require_once(../db_connect.php): failed to open stream: No such file or directory in /var/www/html/2/login.php on line 4
PHP Fatal error: require_once(): Failed opening required '../db_connect.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/html/2/login.php on line 4
When I run $php login.php when in directory /var/www/html/2 it works fine (which I guess makes sense, as ../db_connect.php is a relative path).
I want to know why it is working on the other server and not the DO server?
The php.ini is the same (which could be a problem), but on Server #1 (Verve), it is shared hosting, so our root is /home/[username]/public_html and on the new server is is /var/www/html.
I can link to the live sites in question if necessary (but would prefer not to). The /var/www/html/2/login.php and the /var/www/html/calendar.php scripts are exactly the same, and while I understand this will definitely cause issues later as the absolute path to the root of the web application is different, I don't know what would be causing this specific issue.
I have also looked at this question which is very similar: PHP require_once resetting to current working directory. However, this code works on the other server, and not here, so I think there is something more than just a lack of a relative file path, and I would prefer to find the solution that explains why the script isn't working rather than patching the script, as I'm pretty sure I'd have to change every single other script that uses require_once('../db_connect.php') as well.
Thanks for any help!
Did you try using __DIR__?
require_once(__DIR__ . '../db_connect.php');

php multiple include not working on the same page

I've searched for an answer but found none. So, here it is: simple php page, before anything else I have:
<?PHP
session_start();
require_once("./include/inside_config.php");?>
On the same page, in the body, I have to include another page, a jquery thicker, like this:
<div style="text-align:center; color:#cccccc;">
<?php include('thicker_it.php');?>
</div>
The last one returns error (Warning: include(thicker_it.php) [function.include]: failed to open stream: No such file or directory in...) The fact is that the file exists, at that location (writing before "./" does not resolve the problem).
Note:
the DNS is forwarded to another server (I use another domain's server, the same provider GoDaddy).
the full-path solution does not work either (I changed the php.ini but the error persists).
Please help. Thanks!
This problem can only be one of the following two:
a) Your file doesn't have read/execute premisions for the worker process owner.
b) The file is not where you think it is.
include(file.ext)
This is known as relative path and this is telling PHP that your file is located in the same directory as the script that is currently running, while:
include(/file.ext)
tells PHP that the file is in the root directory, this is known as absolute path.
The solution deppends on where your file is currently located, the relevant part of your directory structure could help us a bit more to help you.

failed to open stream: no suitable wrapper could be found

hello i am implementing php files from one website into another and here is the following error message i am getting when trying to open the following page with implemented php files:
http://www.holidaysavers.ca/europe-destinations-canada.php
basically the php files i am importing from one website into another are identical , however they work on the original website but when i implement them into a new website it does not work anymore.
could you assist me in trying to get this resolved?
thank you
You can't include a PHP script that is on an external website/server into your local script - unless you enable allow_url_include on your php.ini (if you have access to it)
Instead, you can let that website/server render the page and get the resulting html output on your local script.
Replace this line in your script:
include('http://www.holidaysavers.ca/europe-canada.php?detour');
With this:
echo file_get_contents('http://www.holidaysavers.ca/europe-canada.php?detour');
Could you post the code from "europe-destinations-canada.php"? It looks like the script is asking to do stuff that's not configured in your php setup on this new site/server
I don't really know what kind of host you are using or if you are using Xampp, I do have an easy fix to it, for xampp and possibly other web server software. Go to your php.ini file, which you can search for or just look for it in c:\\xampp\php\php.ini, the php.ini should be in the php folder in the server software folder. Now search for allow_url_include in the php.ini file and than replace Off with On, if it isn't already on or something. This is most likely the fix because it worked for me.
I might be able to help further if I know if you are using a hosting or home server. If you are using a hosting website than please share what kind of hosting service you are using so I could inspect it further.
Using as example a random remote php file.
The goal is to use this remote file locally, make sure it hasn't change or be altered. The remote file will be downloaded one time only.
Hard coding the sha256 signature avoid to use the network on startup. This is just a base that can be turned to many scenarios, like checking for updates, depending your needs.
<?php
$lib_url = "https://raw.githubusercontent.com/getopt-php/getopt-php/master/src/CommandInterface.php";
$lib_filename = basename($lib_url);
// SHA256 signature
$lib_signature = hash_file("sha256",$lib_url); // "dba0b3fe70b52adbb8376be6a256d2cc371b2fe49ef35f0c6e15cd6d60c319dd"
// Hardcode the signature to avoid a network call on startup:
//$lib_signature = "dba0b3fe70b52adbb8376be6a256d2cc371b2fe49ef35f0c6e15cd6d60c319dd";
if (!is_file($lib_filename) || $lib_signature != hash_file("sha256",$lib_filename)){
// No local copy found, or file signature invalid, get a copy
copy($lib_url, $lib_filename);
}
require $lib_filename;
It is very useful if you intent to share a program as a single file, without composer.
For the case of a file hosted on Github, an ETag HTTP header is provided, it can be used to avoid to download the whole file.
php -r 'var_dump(json_decode(get_headers("https://raw.githubusercontent.com/getopt-php/getopt-php/master/src/CommandInterface.php", 1)["ETag"]));'
//string(64) "c0153dbd04652cc11cddb0876c5abcc9950cac7378960223cbbe6cf4833a0d6b"
The ETag HTTP response header is an identifier for a specific version
of a resource. It lets caches be more efficient and save bandwidth, as
a web server does not need to resend a full response if the content
has not changed.
Warning: include() [function.include]: URL file-access is disabled in the server configuration in /home/content/91/8151691/html/HolidaySavers.ca/europe-destinations-canada.php on line 52
says it all. I believe this is called XXS. It appears you're attempting to include a URL based file which is denied in your server configuration which is either one of two things.
You're attempting to include the file on site B from site A which you would then use instead of include('WhateverFile'); file_get_contents('WhateverFile'); however this will only return the client side data as it is an HTTP request;
You've duplicated the file on site B and forgot to update the domain configuration. Be sure that the include path reflects the site you're running the script on ie.
include(dir($_SERVER['SCRIPT_FILENAME']) . DIRECTORY_SEPARATOR . 'WhateverFile.php');
In any case. I would have to actually examine the line 52 on the said file to see why PHP is complaining to you in detail lol

DreamWeaver with PHP

Greetings ! I have a project that has php index.php file in /htdocs. Also include files like dboperaitons.php, config.php and css file also in /htdocs/themes. Now I set up New site in dreamweaver opened the index.php file, it is running fine , but when I click on properties and ry to add or modify css property from dreamweaver, it gives me error saying unable to open file http://localhost/themes/en.css file because it is not found in the hard disk.
1. Why is it searching for file as http://localhost instead of c:/xampp/themes.
2. It says en.css file is remote file and cannot be edited.
How can I resolve this. Please guide.
you can fix this problem by browsing the file manually from its location.
When you define a site in Dreamweaver you need to make sure you set up both the local and remote locations in order for it to know where files are. It sounds like you have not defined the local site folders properly and DW is confused about where things go.

Categories