Jump to content

[SOLVED] including connection string file, not working on included pages with queries


jaxdevil

Recommended Posts

I have a site setup to work off of one single page, with the individual pages as included files called based on a variable. An example is I have the header and footer, and one index.php page that includes the header and footer. The index.php page then uses if statements to pull the other pages (about us, contact, etc.) as in if the page is index.php?page=AboutUs the index.php page pulls the aboutus.php page data and displays it. Now I have a page that pulls data from the database. It works fine when i put the connection string on the page that is pulled, but I have added the connection string via a require statement on the header and removed the connection string from the actual page. When I do that it no longer works. Below is how I include the connection settings into my header.php:

 

<?php require("configs/connection.php"); ?>

 

The header is pulled onto the index page with the following code:

 

<?php include "skins/1/header.php"; ?>

 

And here is the index.php page pulling the data from the sub-pages:

 

<?
include "skins/1/header.php";
if ( $medical == "")  {
include "pages/en/main.php";
}
if ( $medical == "AboutUs")  {
include "pages/en/aboutus.php";
}
if ( $medical == "PrivacyPolicy")  {
include "pages/en/privacy.php";
}
if ( $medical == "TermsofUse")  {
include "pages/en/termsofuse.php";
}
if ( $medical == "Disclaimer")  {
include "pages/en/disclaimer.php";
}
if ( $medical == "ContactUs")  {
include "pages/en/contactus.php";
}
if ( $medical == "ThankYou")  {
include "pages/en/thankyou.php";
}
if ( $medical == "ShowCat")  {
echo file_get_contents("http://".$_SERVER['HTTP_HOST']."/pages/en/showcat.php?cat=".$cat);
}
if ( $medical == "ShowSub")  {
echo file_get_contents("http://".$_SERVER['HTTP_HOST']."/pages/en/showsub.php?sub=".$sub."&page=".$page."&perpage=".$perpage."&orderby=".$orderby);
}
if ( $medical == "Shop")  {
echo file_get_contents("http://".$_SERVER['HTTP_HOST']."/pages/en/products.php");
}
if ( $medical == "Product")  {
echo file_get_contents("http://".$_SERVER['HTTP_HOST']."/pages/en/product.php?code=".$code."&region=".$region);
}
include "skins/1/footer.php";
?>

 

Now when I pull the ShowSub page the script doesn't connect to the database. If I add the connection string directly to the showsub.php file it works, but when i remove it (expecting the headers require statement pulling the connection.php script to do the connecting to the database) it doesn't connect. I want to have all the scripts use on single connection string so I can modify it if needed in one place instead of all over the site. Am I doing something wrong maybe with echo'ing file_get_contents instead of including those or requiring those pages?

I figured it out. I needed to use the full server path on the pages I was calling via get_file_contents. Ex. below...

 

<?php
require("/home/temp/public_html/configs/connection.php");
?>

 

;D ;D ;D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.