PHP - Remote Includes
Hey people!
I'm currently working on an free API that i will be sharing with the web community in the next few months and had a question that much of this project hinges upon: Is there a way to allow a remote include of one php file from my server? Case: I am allowing 2 ways for users to access the APi: 1. Using AJAX or cURL accessing a REST method over POST or GET (This part is already functional) 2. Allowing an include of the API Library I'm not sure if it will be completely opensource yet, only free, this is why I don't want to simply provide the source files to users. Example of what I would like to do: <?php include('http://mysite.com/myAPI/classLib.php'); ?> Anybody have a solution for that?? Thanks in advance, E Similar Tutorialshow to get the domain name of a website which includes my includes file. The code would need to be put within my includes file so when any site includes it the file will get the sites domain. to $currentDomain i have tried using: echo file_get_contents() instead of includes but i get the same issue I get back the includes domain. then code i have tried (in the includes file): Code: [Select] $curdomain1= $_SERVER['HTTP_HOST']; $pageUR1 = ereg_replace("/(.+)", "", $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]); $curdomain2 = str_replace("www.", "", $pageUR1); echo "<br> 1# Current Domain: ".$curdomain1; echo "<br> 2# Current Domain: ".$curdomain2; Sorry for the long message but I need HELP!!! I'm somewhat familiar with HTML but very little in PHP, and even less in CSS. My eCommerce program is PHP based so I've had to learn to work with it. I did have someone else initially setup and create my website but over the past few years have taken it further myself. I've fiddled with some of it and looked up how to do certain things, such as have only one header and/or sidebar I can use for all pages. I use Dreamweaver CS4 and FTP with FileZilla. But I'm still new at this and have run into a couple of issues.
My webhost is GoDaddy, my website is MikiCat Designs and after fiddling for months, in March finally got my site to where I liked it. Unfortunately, I haven't kept it up. Anyway, I went there a couple of weeks ago and found that the PHP includes I'd had in the HTML files were no longer working. I get the error [an error occurred while processing this directive]. Weird. Worked fine before, now it doesn't. Called GoDaddy who says they didn't do anything . Uh huh. Now I know I didn't do anything since I haven't updated the site in 4 months! So, what could have caused this problem? I've had no idea how to fix it other than to change the index.html to index.php and, of course, do a minor repair on the include. Works fine and my header.php and leftsidebar.php show up again. Yay! Herein lies another problem. My header and sidebar link to other files some of which were HTML files. But those HTML files had the same header and sidebar issues as my INDEX file. This had to be fixed so I changed them to PHP. Still working on the changes. I deleted most of the HTML files from the server. So the links in my header and lefsidebar files now point to PHP files. e.g., gallery.html to gallery.php. When called on it's own, gallery.php shows up perfectly. But, no matter what I do, the header file still tries to load the HTML file!!! It's driving me crazy. What have I done wrong? I've deleted them both, refreshed, cleared cache and uploaded them again but I still get the same error. If you click on Gallery in the header, it tries to link gallery.html not gallery.php! Funny thing is, the leftsidebar now works perfectly and points to the proper PHP files. I'm completely confused now. I don't know why my header is insisting on trying to load the HTML page instead of the PHP. But here's my header code. Lines 41 and 42 work, lines 43, 44 and 45 do not. * Quietly banging head against wall while awaiting help. <html> <body> <!-- begin #header --> <!-- begin Facebook script --> <div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script> <!-- end Facebook script --> <div id="container"> <div id="headerright"> <form method="post" action="search.php"> <input type="hidden" name="posted" value="1"/> <input type="text" name="stext" size="16"/> <input type="submit" name="Search" value="Search"/> </form> </div> <div id="headerright1"> <form method="post" action="cart.php"> <input type="hidden" name="posted" value="1"/> <input type="image" name="Submit" src="images/cartgrn.gif" /> </form></div> <div id="headerright2"> <form method="post" action="clientlogin.php"> <input type="hidden" name="posted" value="2"/> <input type="image" name="Submit" src="images/login2.gif" /> </form> </div> <div id="header"> <div id="PLHIMYFUFUJCDiv" style="position:absolute; left:567px; top:82px; width:490px; z-index:50; white-space:nowrap; direction:ltr;"> <div id="PLHIMYFUFUJCMain" style="width:490px;height:40px"> <ul style="margin:0px;padding:0px;font:italic normal bold 14px Georgia,Times New Roman,Times,serif;"> <li style="float:left;list-style:none;text-align:center;width:98px;height:40px;background-image:url(images/homenav.gif);"><a href="http://www.mikicatdesigns.com" target="_self" title="MikiCat Designs" style="display:block;height:28px;padding:12px 0px 0px 0px;color:#00008b;text-decoration:none;">Home</a></li> <li style="float:left;list-style:none;text-align:center;width:98px;height:40px;background-image:url(images/homenav.gif);"><a href="http://www.mikicatdesigns.com/categories.php" target="_parent" title="Handmade jewelry and accessories " style="display:block;height:28px;padding:12px 0px 0px 0px;color:#00008b;text-decoration:none;">Products</a></li> <li style="float:left;list-style:none;text-align:center;width:98px;height:40px;background-image:url(images/homenav.gif);"><a href="http://www.mikicatdesigns.com/gallery.php" target="_parent" title="Handmade jewelry gallery of past lives" style="display:block;height:28px;padding:12px 0px 0px 0px;color:#00008b;text-decoration:none;">Gallery</a></li> <li style="float:left;list-style:none;text-align:center;width:98px;height:40px;background-image:url(images/homenav.gif);"><a href="http://www.mikicatdesigns.com/aboutmikicatdesigns.php" target="_parent" title="Learn about MikiCat Designs" style="display:block;height:28px;padding:12px 0px 0px 0px;color:#00008b;text-decoration:none;">About Us</a></li> <li style="float:left;list-style:none;text-align:center;width:98px;height:40px;background-image:url(images/homenav.gif);"><a href="http://www.mikicatdesigns.com/contactmikicatdesigns.php" target="_parent" title="Contact MikiCat Designs" style="display:block;height:28px;padding:12px 0px 0px 0px;color:#00008b;text-decoration:none;">Contact Us</a></li> </ul></div><div id="PLHIMYFUFUJCLevel2" style="float:left;width:490px;height:40px;"></div> <script type="text/javascript" src="Pluginlab/Scripts/PLHIM.js">/* PLHIMMenu script ID:PLHIMYFUFUJC */</script> </div> <!-- end #header --> If one file includes another, do I need to start a session in each, or does the included file "inherit" the session? script_1.php // Initialize Session. session_start(); // Require Function require_once('script_2.php'); script_2.php // Initialize Session. session_start(); DO I NEED THIS HERE????????? if ($_SESSION['loggedIn'] == TRUE){ do something } Debbie Hi, Im pretty much self taught when it comes to php, never read any books just picked things up as i go, and im looking for some advice on how i build my pages as i believe im not approaching it correctly. Basically i build an index.php, this contains my header, footer, and any menus i may have, then for my content pages, in this case products, contact, about us i use use an include so these content pages just have content. Now by doing this my address bar looks like this index.php?location=contact.php for the sake of google and search results and so on, am i limiting my ability to be found by not using a differant file for each page? should i include a header, footer, menu etc within my content pages rather than the other way around? Thanks in advance for any advice. Hey everyone, I am trying to secure php includes and I wrote the following lines: Code: [Select] <?php $dir=scandir('.'); if (in_array('copyright.php',$dir)) { include('copyright.php'); } else { echo 'That page could not be found'; } ?> Is this code secure enough, can anyone help me improve it? Thanks in advance. hi This problem is the most strange thing that i seen in the last times. this code works Code: [Select] <?php function conecta () { $host = "localhost"; $senha = "vertrigo"; $login = "xxx"; $database = "emprego"; $conexao = mysql_connect($host,$login,$senha) or die(mysql_error()); mysql_select_db($database,$conexao)or die; } conecta (); //more ?> but this doesn't work Code: [Select] <?php require("includes/f_banco.php"); conecta (); ?> I never seen something like that. Any ideia? the paths are correct, the bd is correct and the query works when i put the function conecta() directly in the php file. Thanks Ok, I am sure this is really simple for all of you, but I have very little experience with php. I haven't sat down to learn php yet, but I will when I have more free time. In the meantime I have the following issue: The site is http://astoryaday.fromyay.com/ I have all the stories in the /stories/ directory, all named 20110504.html, 201105005.html, etc. Every day I write another story, I name it following that pattern, and drop it into the /stories/ folder. I only want the newest story displayed on the page. So I wrote a little script that is: Code: [Select] <?php $files = glob("stories/*.html"); sort($files); $newest = array_pop($files); include($newest); ?> Now, what I want to do, is in the footer, put an Archive that will look like this: -2012 --January ---03 ---02 ---01 -2011 --December ---31 ---30 And upon clicking on the dates, the story from that day will replace the story that is currently included. Any help of how to get this done would be appreciated! Thanks I did some googling and it seems you cannot include a file with an anchor: i.e include "hello.php#foo"; How do you guys go back to the middle of the page of an included file? Do you just not include files with anchors? I wanted to run my entire site inside index.php and just use includes to diplay the appropriate file, but I also need anchors to go to the middle of the page on some of those files. Hi all My site is build using php includes. the index.php file contains code like <?php if(@$_GET['page'] == "web-design"){ include("includes/web-design.php"); } else if(@$_GET['page'] == "hosting"){ include("includes/hosting.php"); } else { include("includes/home.php"); } ?> I have created a sub domain blog.maplewebdesign.co.uk and a sub dircetory named blog. The link to this part of my site doesn't use includes, I want it to link directly to that sub directories index.php page. This works fine, but then when I click on a different link anywhere on the site my url is as follows www.maplewebdesign.co.uk/blog/index.php?page=home For some reason it is keeping the blog/ in the URL If you want to see go to http://www.maplewebdesign.co.uk/blog/ then click on a differnt link and check out the URL What am I doing wrong? Thanks Adi Hi i am fairly new to php and seem to be having a problem using <php includes> This problem had boggled me for the last few hours now and finally came to try and seek help what i am trying to do is have a php index page that imports my header, footer, navbar and main content from other php files this is the code i am using: Code: [Select] <body> <div class="indexcontainer"> <?php include('header.php'); ?> <table width="900" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="26" background="images/index20.jpg" > </td> <td width="162"><?php include('lsidebar.php'); ?></td> <td><?php include('content.php'); ?></td> </tr> </table> <?php include('footer.php'); ?> </div> </body> this doesnt display the way i want instead of 'images/index20.jpg' 'lsidebar.php' and 'content.php' appearing in the table under the header, images/index20.jpg takes up more space that i set, i set it to 26, it really takes up 123, and it pushes my content.php of the page i guess(i dont know how to fix this) images/index20.jpg- is a border image that i need to extend down to the bottom of page but above the footer, i had this working before but i had the border image included in with the navbar.php file, but it wouldnt extend to bottom of page im probably doing this wrong way, i hope someone can point me in the right direction OK I'm 98% new to PHP. I'm trying to do my own website and my idea will work something like this: index.php ____________________ Header + Nav {PHP INCLUDE} Footer ____________________ The content will reside in another *.php page If you look at www.avlscotland.com/test 'temporary' It loads default.php when you go to the page which is perfect. I have it working in basic form although only the hyperlinks HOME - ABOUT AVL - DEAD LINK are active at this moment. So it works this way with everything in the same directory, but I want it to load the content from a subdirectory /test/pages/content.php This is the PHP code I am using <?php // Check if page has been requested if (!isset($_GET['content'])) { // Page has not been requested, show default page $content = 'default.php'; } else { // Page has been requested, validate page exists, show page $content = $_GET['content'].'.php'; } // End if page has been requested // Check to see if page exists if (file_exists($content)) { // Page exists // Show page include("$content"); } else { // Page doesn't exist echo '<br>'; echo '<br>'; echo '<br>'; echo 'Sorry, the page that you are trying to access does not exist.<br>'; echo 'Please return to <a href="http://www.avlscotland.com/test/index.php">AVL Scotland</a><br>'; echo '<br>'; echo 'Thank you.<br>'; } // End if page exists ?> I'm accessing the pages using links like <a class="menuactive" href="test/index.php?content=avl">Home</a> What I'm struggling to do is make the PHP look for the content files in a sub-directory. Look forward to any help you can offer. Thanks, Ross Sorry if this is a stupid question http://www.dinksoftware.com/fig/index.php looks as it should with the php includes working. However if you go to http://www.dinksoftware.com/fig or http://www.dinksoftware.com/fig/ the php includes don't work for some reason. index.php Code: [Select] <?php session_start(); ?> <?php include('header.php'); ?> <?php include('topMenu.php'); ?> <?php include('sidenav.php'); ?> <div id="content"> <h3>Introducing 'The Business Sim'!</h3> <?php $errorMessage1 = $_SESSION['errorMessage1']; echo("$errorMessage1 <p>"); $_SESSION['errorMessage1'] = ""; ?> The Business Sim is an online, free to play educational game currently under development. <strong>The first round of gameplay will commence in Q1, 2011. </strong><br /> <p>Have gameplay ideas/suggestions or any other comments? Want to help mould the game? </p> <br/> <?php include('footer.php'); ?> </div> </body> </html> header.php part (no other includes or anything in this) Code: [Select] <a href="index.php"><img src="header.png" alt="The Business Sim" width="550" height="100" border="0"/></a> How do I fix this? I want http://www.dinksoftware.com/fig and http://www.dinksoftware.com/fig/ to work like it does when you go/fig/index.php etc. Hi Guys, im really hoping one of you php guru's can shed some light on this as its being bugging me for months... Im trying you access a php include, in a page 1 directory deep into a site (say one down from the index.php) - with no luck. My includes are in a folder that is on the same level as the index.php file for the website. Iv tried using this way: <? include("../includes/footer.php"); ?> And this way: <?php include $_SERVER['DOCUMENT_ROOT'] . "includes/footer.php"; ?> It works locally (using MAMP), but not live on the net. Im getting this error: Warning: main() [function.main]: open_basedir restriction in effect. File(/ext/default/includes/footer.php) is not within the allowed path(s): (.:/tmp) in /ext/f/fo/fourthelement.com/html/sita/resources/members_area.php on line 53 Warning: main(/ext/default/includes/footer.php) [function.main]: failed to open stream: Operation not permitted in /ext/f/fo/fourthelement.com/html/sita/resources/members_area.php on line 53 Warning: main() [function.include]: Failed opening '/ext/default/includes/footer.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /ext/f/fo/fourthelement.com/html/sita/resources/members_area.php on line 53 Really appreciate anyone who has a few minutes to look at this. Cheers Guys Mike Which of these is the "best coding practice" for the proper order of "ob_start," "sessions," and "require?" (my "require" files are usually just mySQL login stuff):
a.)
b.) And also, instead of just plain "session_start()" isn't it more proper to ALWAYS use if(!isset($_SESSION)) { session_start(); } Thank you in advance.
I have a very simple page, where I use the include statement that includes my connection string. The connection string and a variables are not being passed to my test server - (WAMP). My include file is below $server = "servername"; $username = "username"; $password = ""; $database = "dbname"; $portNumber = 3308; $link = mysqli_connect($server,$username,$password,$database,$portNumber); if(!$link) { echo "cannot connet to the server"; } else { echo "This works"; } echo "Hi"; I am including this file with the following code:
include ("includes/connect.inc");
My site is not connecting to the database, and is not displaying "This works", or "Hi". Do you have any pointers on how to get this connect?
I have a folder with php includes files and one of them has the username and password of the database. Is there any way that i can lock the folder and unlock it with php. Or do it using the cpanel of my server? This sounds like what i want to do. I am using includes for header, footer, and contents which go into a table to keep them organized and a standard look. I can put it all together well, except i dont know how to change the contents.php. I could eventually have hundreds of content pages. Right now i just have one and named it contents.php. So if i add another and called it contents2.php for example, how do i call it or replace the original contents.php. If i used a plain page i could just link to the next page but i dont want to do that. Hello everybody, I have a question about changing variables. In a website template I've created, I would like to only include some code from another file into the page if the variable changes. Example: Code: [Select] <?php $load_page1 = 0; ?> <a href="index.php#!/page1" onClick="<?php $load_page1 = 1; ?>">Page 1</a> <?php if($load_page1 == 1) { include('pages/page1.php'); } ?> The problem I'm having is Code: [Select] onClick="<?php $load_page1 = 1; ?>" always sets the variable to "1" even if not clicked. So the question is, how would I make it so the default is "0" and only after clicking the link, the variable is set to "1" and then the new code from the other file is included into the page. Please let me know if I need to clarify anything and thanks for any help in advance. Hi.
I have an HTML template that I'm going to use for my CMS, and need some advice on the best way to split it up into common elements used across all pages.
I've identified the common HTML and have written functions to include each. I've used functions instead of directly including them on the page for flexibility in the future.(wise?)
/* functions.php */ function show_style() { include_once 'module-style.php'; } function show_header() { include_once 'module-header.php'; } function show_sidebar() { include_once 'module-sidebar.php'; } function show_footer() { include_once 'module-footer.php'; } function show_js() { include_once 'module-js.php'; }And then on the page itself... <?php include_once 'functions.php'; ?> <!DOCTYPE html> <html lang="en"> <head> <title>My CMS</title> <meta charset="utf-8"> <?show_style()?> </head> <body> <?show_header()?> <!-- start section content--> <section class="section-content"> <?show_sidebar()?> <!-- start content --> <div class="content"> // PAGE CONTENT </div><!--/ end content --> </section> <!-- /end section content--> <?show_footer()?> <?show_js()?> </body> </html>A few questions - are there any issues with using the <? tag as opposed to <?php.... I've seen it used in templating before and want this to be as clean and readable as possible. Also would it be better to use a class for this, and include all of my functions within that class? Any advice or alternatives on the method used above would be great Edited by paddy_fields, 16 October 2014 - 03:50 AM. My site has been working fine for years but, all of a sudden, is throwing server errors on the pages that call for PHP includes. My provider isn't saying whether there's been an update but the fact that the site has always worked fine and now isn't, well...
So, here's some sample code from a .html page that calls for the TPL file:
<?php include('/home/MyPath/public_html/MySite.com/tpl/footer.tpl'); ?>
A long time ago, I was told to put this in my htaccess file:
AddType application/x-httpd-php5 .html
AddHandler application/x-httpd-php5 .html
If I delete both of these lines from the htaccess file, the site will load without the internal server error but my includes don't work at all. There's just an empty space where the content from the tpl file is supposed to be. I know they installed php 5.4 but my site was automatically put on 5.2 as a default.
I submitted a ticket with my provider and this was the response.
This is the error message as it is being recorded from the server itself when the domain returns a 500 error: [root@provider /home1/MyPath/public_html/mysite.com]# grep mysite.com /usr/local/apache/logs/error_log |tail -6 [Sat Sep 20 15:42:16 2014] [error] [client 192.190.1.20] Cannot load the ionCube PHP Loader - it was built with configuration 2.2.0, whereas running engine is API220100525,NTS, referer: http://www.mysite.com/ [Sat Sep 20 15:42:16 2014] [error] [client 192.190.1.20] Zend Optimizer requires Zend Engine API version 220060519., referer: http://www.mysite.com/ [Sat Sep 20 15:42:16 2014] [error] [client 192.190.1.20] The Zend Engine API version 220100525 which is installed, is newer., referer: http://www.mysite.com/ [Sat Sep 20 15:42:16 2014] [error] [client 192.190.1.20] Contact Zend Technologies at http://www.zend.com/ for a later version of Zend Optimizer., referer: http://www.mysite.com/ [Sat Sep 20 15:42:16 2014] [error] [client 192.190.1.20] , referer: http://www.mysite.com/ [Sat Sep 20 15:42:16 2014] [error] [client 192.190.1.20] malformed header from script. Bad header=<br />: index.html, referer: http://www.mysite.com/ This will be because there is a mismatch between the php version being called and the php.ini that is being loaded for the domain. Reviewing the mod_rewrite statements that call the various php versions within the direct file path to your domain shows the following: [root@provider /home1/MyPath/public_html/mysite.com]# grep -H -A 3 -B 1 'AddHand' /home1/MyPath/.htaccess /home1/MyPath/public_html/.htaccess /home1/MyPath/public_html/mysite.com/.htaccess /home1/MyPath/.htaccess-# Use PHP52 as default /home1/MyPath/.htaccess:AddHandler application/x-httpd-php52 .php /home1/MyPath/.htaccess-<IfModule mod_suphp.c> /home1/MyPath/.htaccess- suPHP_ConfigPath /opt/php52/lib /home1/MyPath/.htaccess-</IfModule> -- /home1/MyPath/public_html/mysite.com/.htaccess-#AddType application/x-httpd-php5 .html /home1/MyPath/public_html/mysite.com/.htaccess:#AddHandler application/x-httpd-php5 .html /home1/MyPath/public_html/mysite.com/.htaccess- /home1/MyPath/public_html/mysite.com/.htaccess- /home1/MyPath/public_html/mysite.com/.htaccess-## You would need to also declare the suphp for the php.ini to be used and upload a version matching php.ini to that location.I am completely lost as to what this means. I don't even know where to begin. Can someone please help me so I can get my site back to normal? Thank you in advance! |