d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Splitting Pages With Php And Getting Links To Work
Add Reply New Topic New Poll
Member
Posts: 9,412
Joined: Nov 18 2009
Gold: 20.00
Mar 29 2014 03:45pm
I am having trouble getting the links to work in my website.

The background story:

I have multiple files in separate folders.

For example, I have my register file in /register/index.php and I have my homepage at /index.php.

I split the pages using php in order to make editing easier. My header is at header.php, and my footer is at footer.php.

The problem:

I don't know how to setup my links in the header.php and footer.php so that they work in different directories!

Example Page:

Quote
<?php
$page_title = 'A Private Community for Wholesalers & Retailers';
include('header/header.php');
?>
  /* Content goes here */
<?php
include('footer/footer.php');
?>


A header.php page:

Quote
<!DOCTYPE html>
<html>
<head>
<LINK rel="stylesheet" HREF="style.css" TYPE="text/css" MEDIA=screen />
<script type="text/javascript" src="js/search-options.js"></script>
<script type="text/javascript" src="js/seller-buyer-info.js"></script>
</head>
<body>


Another way to do the same header.php page:

Quote
<!DOCTYPE html>
<html>
<head>
<LINK rel="stylesheet" HREF="../style.css" TYPE="text/css" MEDIA=screen />
<script type="text/javascript" src="../js/search-options.js"></script>
<script type="text/javascript" src="../js/seller-buyer-info.js"></script>
</head>
<body>



How do I get the links to css and javascript files in header.php to work with /register/index.php and /index.php without creating multiple header.php pages?

This post was edited by PixileDust on Mar 29 2014 04:03pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 29 2014 04:07pm
maybe i'm missing something obvious, but can't you just reference it like so?

/style.css

it would help if you told me where style.css is. i assume it's under the root folder. if it's under a subfolder (eg: css), then reference it as /css/style.css

This post was edited by carteblanche on Mar 29 2014 04:08pm
Member
Posts: 9,412
Joined: Nov 18 2009
Gold: 20.00
Mar 29 2014 04:19pm
Quote (carteblanche @ Mar 29 2014 04:07pm)
maybe i'm missing something obvious, but can't you just reference it like so?

/style.css

it would help if you told me where style.css is. i assume it's under the root folder. if it's under a subfolder (eg: css), then reference it as /css/style.css


That doesn't work (although I thought it would).

The problem is that I want to use the same header.php file for two different php pages in separate directories.

localhost/register/index.php and localhost/index.php

I can get register/index.php to work by referencing style.css like so: <link href="../style.css">

I can get /index.php to work by referencing style.css as <link href="style.css">

This post was edited by PixileDust on Mar 29 2014 04:34pm
Member
Posts: 9,412
Joined: Nov 18 2009
Gold: 20.00
Mar 29 2014 04:53pm
Quote (carteblanche @ Mar 29 2014 04:07pm)
maybe i'm missing something obvious, but can't you just reference it like so?

/style.css

it would help if you told me where style.css is. i assume it's under the root folder. if it's under a subfolder (eg: css), then reference it as /css/style.css


It took 3 hours, and I finally figured it out. The problem was that the folder after my root wasn't properly defined in my links. What you said helped me realize the issue, so thank you.
Member
Posts: 11,610
Joined: Oct 28 2008
Gold: 1,795.00
Mar 30 2014 10:28am
what a mess, look into using rewrite rules over anything like this
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll