Using an absolute URL in PHP "require" and "include"

9 posts by 2 authors in: Forums > CMS Builder
Last Post: August 12, 2010   (RSS)

By gkornbluth - August 11, 2010 - edited: August 11, 2010

Hi all,

The question came up about how to specify an absolute URL in a PHP require instead of a relative path. (Important in this case since my client wants to email their page as a web page and all links must be absolute URLs)

Here’s something I found which looks promising, but I admit I don’t really have a clue how to implement it on their site or on their web page.

Any takers?

Best,

Jerry Kornbluth

_____________________________________

Here’s the real URL: http://www.artistsofpalmnbeachcounty.org

And the relative require path is:
<?php
require 'emailcode.class.php';
$emailcode = new ClassEmailcode();?>


______________________________________

Here’s article that I found on webmaster world at http://www.webmasterworld.com/forum88/5504.htm#msg1300723 near the bottom of the post.

Control your included files

Wouldn't it be nice to just include() [php.net] your files and never have to worry about the path? You set it once when you setup a new site and be done with it. A lot of programmers use this technique, you'll often see it called the "config.php" script or something similar. Here's a sample to get you started (replace the bold (not bold in the article) path with the path to your includes directory):
ini_set [php.net]('include_path [php.net]',
realpath [php.net]($_SERVER [php.net]['DOCUMENT_ROOT'] . '/../includes/')
. PATH_SEPARATOR [php.net]
. ini_get [php.net]('include_path'));


The poster goes on to say:

"Some pretty neat stuff going on in here.

First, notice the use of the realpath() function to put the canonicalized absolute pathname together from a relative link (/../includes/), which by the way, resides below the public document root ;) -- tidies it up quite nicely.

Second, we concatenate the current server configuration include_path to the end of our include_path. Why? In case you want to use any existing paths, such as PEAR classes.

Lastly, notice the use of the PATH_SEPARATOR predefined constant? That way you can use it on a Windows server or a *nix server without having to modify anything."
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Using an absolute URL in PHP "require" and "include"

By Chris - August 11, 2010

Hi Jerry,

A require statement is PHP code and not a link. The require will be evalutated by PHP and will never make it into any web pages. I'm not sure how your client will be emailing their web pages, but as long as they're not emailing the PHP source code, no one will ever see the require path.

Does this help?
All the best,
Chris

Re: [chris] Using an absolute URL in PHP "require" and "include"

Followup:

I just purchased your Spambot Email Protector hoping that would be a plugin and eliminate the issue (at least for now). But it also seems to rely on an "include", and so the issue remains.

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Using an absolute URL in PHP "require" and "include"

By Chris - August 11, 2010

Hi Jerry,

IE 7/8 doesn't get to see the require path either. Nor does the mail client.

I have IE 8 here and tried the Send Page by Email option. It seems to work fine except for two things:

1. The flash apps don't show up. This is expected.

2. The CSS is slightly off. I see some JavaScript in the source code which does something with CSS, maybe that's the culprit.

Are you getting different results? What makes you think that the "require path is broken?"
All the best,
Chris

Re: [chris] Using an absolute URL in PHP "require" and "include"

Chris,

Sorry for so much confusion.

I've put together a test page at http://thecmsbcookbook.com/include_test.php to demonstrate the problem.

I have been encrypting the e-mail addresses that are included on any of my client's web pages. The encryption schemes are called by a PHP "include".

I'm using both an older scheme as well as your "Spambot Protector".

One client has been e-mailing some pre-formatted web pages to their membership, and some of those pages have encrypted email addresses embedded in them.

When emailed, the encrypted emails either do not show at all in the e-mail messages, or in the case of spambot protector, do not resolve correctly.

Hope that make this simpler to understand.

Best,

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Using an absolute URL in PHP "require" and "include"

By Chris - August 12, 2010

Hi Jerry,

While you're calling the encryption scripts via PHP includes, the problem only exists because the included PHP generates JavaScript, and JavaScript doesn't run in emails.

Basically, it won't be possible to send encrypted email addresses in emails. Alternately, you could have the email address links act like regular links in emails which would take readers to pages where the email address would be available. I can imagine three options:

1. A single static link to a contact page (obviously this is only useful if there are a small number of email addresses.)

2. A link to the web version of the page (where the email link would work correctly, but the user would need to find it again.)

3. A link to a small custom script which simply asks you to click a link to email the email address you've selected. The encrypted code would be sent in the query string.

An example of (1) above would be:

<a
href="http://mywebsite.com/contact"
onclick="window.location='mailto:&#106;&#x65;&#x72;\u0072&#x79;\u0040%6a%6b\u0077&#x65;\u0062\u0064%65%73&#105;\u0067&#x6e;%73%2e&#x63;&#111;&#109;';return false;"
>EMAIL JERRY</a>


Does this help at all?
All the best,
Chris

Re: [chris] Using an absolute URL in PHP "require" and "include"

By Chris - August 12, 2010

Correction:

There are lots of ways to send encrypted emails WITHOUT JavaScript. I believe there's a JavaScript option you can turn off in Spambot Protector. That should work!

Does that help more? :)
All the best,
Chris

Re: [chris] Using an absolute URL in PHP "require" and "include"

Wow. Seems to be a perfect, easy solution.

Thanks to your explanation, it seems that all I needed to do in the spambot email protector was to change the encoding option on the line $GLOBALS['SEP_ENCODING_METHODS']['jsLocation'] = true; to$GLOBALS['SEP_ENCODING_METHODS']['jsLocation'] = false; and it works perfectly, at least when I use Outlook 2010 as the mail client. The Email addresses are still encoded on the web page in both Firefox and IE, but they work in the received email.

I don't know if it will make any difference, but I'm going to run a few more tests with web mail, a few other email clients, and AOL, before releasing this to my client.

But I think you've done it again.

Thank you for solving this one.

Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php