Forum Moderators: coopster

Message Too Old, No Replies

Making all links have a base url

         

Jacob or JaF

2:55 am on Sep 6, 2006 (gmt 0)

10+ Year Member



Here are my files and directories:

folder1
-index.php
folder2
-styles.css
-index.php

Here is folder1's index.php:
<?php
$file_to_include='./folder2/index.php'
include $file_to_include;
?>

Here is folder2's index.php:
<?php
include 'styles.css';
<div class=divs>Some Text</div>
?>

The problem is that when you run folder1's index.php, the styles in the included file don't work (loading folder2's index.php from folder1's index.php makes folder2's index.php load the css file from folder1).
And I'm assuming I can't change the contents of folder2.

Thank you,
Jacob

nazlfrag

8:39 am on Sep 6, 2006 (gmt 0)

10+ Year Member



The './' points to the current directory, try '../' for the previous directory.

Jacob or JaF

12:37 pm on Sep 6, 2006 (gmt 0)

10+ Year Member



Yeah, your right. But that still doesn't solve my problem. :)

[edited by: Jacob_or_JaF at 12:38 pm (utc) on Sep. 6, 2006]

henry0

2:05 pm on Sep 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Isn't it because the style runs from 2
so when included in 1 the CSS link becomes wrong

Could you simply locate your css outside of any dir
or paste a CSS in each dir?

whoisgregg

3:36 pm on Sep 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I find this form of including to be the easiest to maintain, so long as the files fall within your web directory:

// Assuming that http://example.com/folder2/index.php is valid:
include( $_SERVER['DOCUMENT_ROOT']. '/folder2/index.php' );

Though, I'm not sure why you are including your stylesheet file with php into the document instead of just calling the external stylesheet with something like this in the <head> of each page:

<link href="http://example.com/folder2/styles.css" rel="stylesheet" type="text/css" />

Jacob or JaF

4:38 pm on Sep 6, 2006 (gmt 0)

10+ Year Member



I said that I'm assuming I can't edit folder2.
And you don't have to set $file_to_include to '../folder2/index.php'.
What if I set $file_to_include to 'http://www.webmasterworld.com/php/3072971.htm'?
I wouldn't work.

whoisgregg

7:27 pm on Sep 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If I now understand your issue correctly, then you want to take a look at the include_path directive and the ini_set function.

[us3.php.net...]
[us3.php.net...]

You'll probably be able to sort it out with those. Assumptions aside, editing the files would be much simpler. ;)

Jacob or JaF

8:07 pm on Sep 6, 2006 (gmt 0)

10+ Year Member



What I'm simply trying to do is include a website (that I don't have access to change) in my website.
And when you do that the styles and stuff don't work.

I need some command that will add the other website path to every href in the other website.

[edited by: Jacob_or_JaF at 8:15 pm (utc) on Sep. 6, 2006]

whoisgregg

2:18 pm on Sep 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Two ways to go here:

1. <iframe src="http://someoneelsessite.com/somepage.html" style="width: 600px; height: 400px;"></iframe>

2. file_get_contents [php.net], then preg_replace [php.net] every relative path to add the http:/someoneelsessite.com/. I don't have any regular expression handy that would do what you want, but I know it's possible.

iframe is easy for just displaying another site in your site, but I'm not sure if it will meet your needs. (I'm afraid I'm still a bit unsure about what the end goal is here.)

Jacob or JaF

5:32 pm on Sep 8, 2006 (gmt 0)

10+ Year Member



I tried the iframe, but the trouble was that it would make a scrollbar instead of sizing to its contents.

I'll try your second way...

Jacob or JaF

5:53 pm on Sep 8, 2006 (gmt 0)

10+ Year Member



An iframe is exactly what I want, just not in a frame!

StupidScript

7:26 pm on Sep 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I see these types of requests from time to time, and I'm sure there's a valid reason for wanting to do it ... but I can't figure out what that reason is.

Why would you want to include someone else's website within your own page? Why not just link to the site and pop it open in a new window or something?

whoisgregg

7:35 pm on Sep 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can adjust the size manually to accomodate larger webpages and there is probably a way with javascript to adjust the size of the iframe automatically, but I don't know how offhand.

<iframe src="..." style="width: 800px; height: 1200px;"></iframe>