November 13th, 2013, 04:16 PM
Need workaround for remote code
I'm sort of a PHP newbie. I've used other people's free scripts on my personal website(s) over the years, but I don't have a good understanding of PHP. I can usually figure some stuff out by doing research, but this current problem I'm having is really kicking my butt.
Basically I have "website 1" and "website 2" on a free webhost. I have a tracking script in use on "website 1" that uses a code on each page I want to track. With my current project, I need to be able to put the tracking code from "website 1" onto a single page on "website 2" with all the tracking info being sent back to "website 1". The only way I know to do this is to use the include function, but both servers have the allow_url_include function turned off for security purposes.
Does anyone know how I can accomplish what I want to do? There must be a way and without causing a security problem. And, I could of sworn that I accomplished this in early 2011. If I did, I lost the code. Maybe the webhost was using an older version of PHP that allowed me to use remote code, I don't know (although I now know that's a huge security issue).
Can anyone help me, please? I'll settle for being pointed in the right direction if no one wants to go too in depth on this. If I know where or what I should be looking for to get this to work, it would be a lot easier. Right now I feel like I'm looking for a needle in a haystack.
November 13th, 2013, 05:45 PM
Short of moving those kinds of files into a "common" place that's accessible by both websites's code (and I'm talking about files here, not URLs), the best and safest solution would be to just copy/paste the files you need.
November 13th, 2013, 06:43 PM
While I appreciate your help, I have no idea what you are talking about.
Originally Posted by requinix
November 13th, 2013, 07:36 PM
First? If your websites are hosted on the same server and user account then they'll probably have filesystem paths like /home/lbb78/public_html/website1 and /home/lbb78/public_html/website2. You can make a third directory like /home/lbb78/common and put the files the sites have in common (eg, the tracking script) and include the files from there. If you'd like to hear more specifies I need to know more details about how the websites are set up: same server, same user, where the root directories are, stuff like that.
Second? Grab the file from website1 and copy it over to website2. Two copies of the file. Yes, that's two copies and copies are generally bad, but the alternatives are worse.
November 14th, 2013, 02:23 AM
I can't see how any of that will work, I don't even think that's anything like what I'm trying to accomplish.
Website1 and website2 are on two different servers and accounts.
On website1, I have a PHP tracker/counter script installed. I use a PHP code inserted onto Website 1's webpages I want to track, this code uses the include function.
I want to use that same code on one single web page on website2 to log visitor data and have that data transmitted back to Website1's tracking log. I can't do this because the allow_url_include function on the server is turned off, so I can't use a remote URL. I need a way around this. Nothing can be logged/written to website2 as it would defeat the purpose of what I'm trying to do.
The code for the web pages is this:
If the allow_url_include function was on I could use this (except I've read that this should never be done)
<? include "./tracker/code.php"; ?>
I've tried using examples I've found such as this on website2:
<? include "http:// mysite1.com/tracker/code.php"; ?>
While this does work, instead of logging the visitor's IP address, it logs the server IP of website2.
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, "http:// mysite1.com/tracker/code.php");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($ch);
// display file
The following gives the same results:
This one doesn't work at all.
echo file_get_contents("http:// mysite1.com/tracker/code.php");
I'm at a loss as to what I should try or do.
$file = fopen("http:// mysite1.com/tracker/code.php","r");
November 14th, 2013, 03:39 AM
Copy tracker/code.php from website 1 to website 2. As in make a copy of the file. A file with the same code on both sites.
November 14th, 2013, 05:35 PM
Unless you're passing the IP address from the script to whatever your reading it from on the second server, no you won't get it because the second server has no knowledge of the user that's accessing the first server.
You will need to include the users IP address in whatever data you'r passing into/reading from the first server, and only then will the second server know what it is.