#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    3
    Rep Power
    0

    Question 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.

    I've spent hours upon hours looking for other alternatives with no luck. I've tried things like javascript, cURL and a PHP file_get_contents function and while they work, these methods are unable to track the visitor's IP, instead it logs the IP of the servers for "website 1" or "website 2" (not sure which).

    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.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,984
    Rep Power
    9397
    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.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by requinix
    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.
    While I appreciate your help, I have no idea what you are talking about.
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,984
    Rep Power
    9397
    Which part?

    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.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    3
    Rep Power
    0
    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:
    PHP Code:
    <? include "./tracker/code.php"?>
    If the allow_url_include function was on I could use this (except I've read that this should never be done)
    PHP Code:
    <? include "http:// mysite1.com/tracker/code.php"?>
    I've tried using examples I've found such as this on website2:
    PHP Code:
    <?php 
    $ch 
    curl_init();
    curl_setopt ($chCURLOPT_URL"http:// mysite1.com/tracker/code.php");
    curl_setopt ($chCURLOPT_RETURNTRANSFER1);
    $contents curl_exec($ch);
    curl_close($ch);
    // display file
    echo $file_contents;
    ?>
    While this does work, instead of logging the visitor's IP address, it logs the server IP of website2.

    The following gives the same results:

    PHP Code:
    <?php
    echo file_get_contents("http:// mysite1.com/tracker/code.php");
    ?>
    This one doesn't work at all.
    PHP Code:
    <?php
    $file 
    fopen("http:// mysite1.com/tracker/code.php","r"); 
    ?>
    I'm at a loss as to what I should try or do.
  10. #6
  11. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,984
    Rep Power
    9397
    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.
  12. #7
  13. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,101
    Rep Power
    1990
    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.

IMN logo majestic logo threadwatch logo seochat tools logo