Xampp not supporting php Include - php

I know this has been discussed a lot throughout the Stackoverflow.
But still I can't make it work for me, I've been searching for hours, no joke.
I always make my index.php page like this:
<? include ("header.php");?>
<? if($_REQUEST['p']==''){ include('home.php') }
if($_REQUEST['p']=='atelier'){ include('atelier.php'); }
if($_REQUEST['p']=='quem_somos'){ include('quem_somos.php'); }
if($_REQUEST['p']=='que_criamos'){ include('que_criamos.php'); }
if($_REQUEST['p']=='projetos3d'){ include('projetos3d.php'); }
if($_REQUEST['p']=='noticias'){ include('noticias.php'); }
if($_REQUEST['p']=='localizacao'){ include('localizacao.php'); }
if($_REQUEST['p']=='contactos'){ include('contactos.php'); } ?>
<? include ("footer.php");?>
It is supposed to always loads the header and footer.
On page opening it is supposed to load the home.php because there's no request and the menu of the website has links that are requests to other pages.
This always worked for me, I used to work on a ftp server but now I'm using XAMPP for this and it seems like the includes are not working at all.
Is there any file I could go and change some permissions or even better change the way I include the files to be supported on XAMPP?
EDIT: For those asking about how REQUEST works, I have a sample here, it might be easier to understand if you see the menu working: link
EDIT 2: By not supporting I mean: it displays a blank page, it doesn't load neither the header/footer nor the pages themselves
EDIT 3: I've enabled short_open_tag and allow_url_include in php.ini, still not working.
EDIT 4: I went to try easyphp and I still got the same problem... I'd rather not move from where I am and keep the XAMPP to find a solution for this.

Related

Got 404 when redirect every url to index

So, I've been trying to do the Wikipedia url thing! Like making the url readable. Tried every .htaccess code out thire and contacted the Hostinger customer services to help, and nothing works! I don't know why.
So, i move to use the PHP, and i got work great on test.php page that i use the test on, but when i move the code to index.php it doesn't.
So, the why i did it is having a page with php simple code: if url[2] has s include s.php, else include x.php. and it works great when i go to www.website.com/test.php/s it will open s.php
However, when after i move the code to index.php and then i go to website.com/s i got an error as this page is not in the srver, but if i go to website.com/index.php/s it works.
So what do think i could fix it with? Or if there is any other why to do it. Thanks in advance ☺

How do I stop user being able to see website code

the dilemma I have is my website index.php calls to a template php file on a button press like this:
case 'main':
$page = getTemplate('main.php', array('user'=>$user));
echo $page;
break;
This main.php template file is in a folder in "/var/www/template/" How do I stop people going to: domain.com/template/main.php and viewing the code for that page. I think the solution would be to make the localhost be able to pull the it and display it rather than the user or something along those lines. Any help would be appreciated thank you.
Like a comment said, the PHP file will not be printed, it will print the HTML result that the php file produce.
Maybe it produces some errors indicating vulnerabilities to a potential attacker ? If that's your case, you should handle this directly into the php code or use a .htaccess at the root of your site. You can't find some help there.
How to deny access to a file in .htaccess
Managed to fix this by putting this at the top of the php page I wanted to render:
<?php
if (!isset($_GET['page'])) {
header('Location: /main');
exit();
}
?>
This means if someone goes "domain.com/template/main.php" to attempt to view the source code, it will redirect them back to the main webpage for my site. Thanks for your suggestions however.

Wordpress "insert-php": php code from file not executing

I have a WP site, I installed Insert-PHP plugin. (I am really new to WP).
On a new page I wrote in the "text" tab:
[insert_php]
require_once(realpath($_SERVER["DOCUMENT_ROOT"]) ."/firstfolder/nextfolder/test-1.php");
[/insert_php]
Then, in "/firstfolder/nextfolder/test-1_1.php" I have:
<?php
print 'something';
?>
At first I had problems w/ require_once because the path wasn't good. Then I managed and the page was working fine, displaying the word "something" as content.
A few hours later it's not working anymore. If I write PHP code between [insert_php] tags it's doing fine, but if I do the same thing in "test-1.php" nothing happens. No errors or warnings, nothing, just a blank page.
I even tried to write code to force an error and nothing happened. I cleared the cache, I tried created another file w/ that code ... nothing. I intentionally misspelled the path in require_once and that did produce an error.
The only thing happened between the time the code was executing and now is that I installed a "Yoast SEO" plugin.
What could have possibly happen? :(
So, thank you very much for support :| that was great.
I must say that I did not solve the mystery. Maybe I did something wrong somewhere or there is an issue with the "Insert PHP" plugin.
I'll write here what solution I came up with, maybe someone in the future will find a similar problem.
I installed another plugin called "Include Me". I used that to enter the path to the needed php file and after that everything was fine.

PHP include seems to make page interpret itself as a directory

I have a page, index.php, like this (simplified):
<img src="content/banner.png"/>
The image loads fine. But when I include a certain (WordPress) script, like so,
<img src="content/banner.png"/>
<?php
include('template-loader.php');
?>
the image no longer loads! I also notice the URL in the browser becomes index.php/.
How is this possible? The image of course won't load because I'm using relative paths and it's looking for index.php/content/banner.jpg. True, I can use absolute paths to fix this issue, but I'd like to know what could be happening and how the problem might be fixed in PHP.
I'm testing on a local wamp installation and have disabled all mod_rewrites and such, to be sure it's not something external causing the problem.
D'oh. Minutes after posting, I found the culprit, right in the script:
/**
* Loads the correct template based on the visitor's url
* #package WordPress
*/
if ( defined('WP_USE_THEMES') && WP_USE_THEMES )
do_action('template_redirect');
It's doing some kind of a redirect; commenting this out makes everything work as expected.
I still don't really understand how this script can magically redirect to index.php/ as if it were a directory (and have the document actually load) but...
I will delete this question in the future if it doesn't seem to be helping anyone (based on views and votes).

Get Page URL In Order To Use It To Include

So I made a script so that I can just use includes to get my header, pages, and then footer. And if a file doesnt exist a 404. That all works. Now my issue is how I'm supposed to get the end of the url being the page. For example,
I want to make it so that when someone goes to example.com/home/test, it will automatically just include test.php for example.
Moral of the story. How to some how get the page name. And then use it to "mask" the end of the page so that I don't need to have every URL being something.com/home/?p=home
Heres my code so far.
<?php
include($_SERVER['DOCUMENT_ROOT'].'/home/lib/php/_dc.php');
include($_SERVER['DOCUMENT_ROOT'].'/home/lib/php/_home_fns.php');
$script = $_SERVER['SCRIPT_NAME']; //This returns /home/index.php for example =/
error_reporting(E_ALL);
include($_SERVER['DOCUMENT_ROOT'].'/home/default/header.php');
if($_GET["p"] == 'home' || !isset($_GET["p"])) {
include($_SERVER['DOCUMENT_ROOT'].'/home/pages/home.php');
} else if(file_exists($_SERVER['DOCUMENT_ROOT'].'/home/pages/'.$_GET["p"].'.php')) {
include($_SERVER['DOCUMENT_ROOT'].'/home/pages/'.$_GET["p"].'.php');
} else {
include($_SERVER['DOCUMENT_ROOT'].'/home/default/404.php');
}
include($_SERVER['DOCUMENT_ROOT'].'/home/default/footer.php');
?>
PHP by itself wouldn't be the best choice here unless you want your website littered with empty "redirect" PHP files. I would recommend looking into the Apache server's mod_rewrite module. Here are a couple of guides to get you started. Hope this helps!
The simplest way would be to have an index.php file inside the /home/whatever folder. Then use something like $_SERVER['PHP_SELF'] and extract the name if you want to automate it, or since you are already writing the file yourself, hardcode it into it.
That however looks plain wrong, you should probably look into mod-rewrite if you are up to creating a more complex/serious app.
I would also recommend cakePHP framework that has the whole path-to-controller thing worked out.

Categories