Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post

    Making a Remote Script App

    Hi,

    I am trying (for the first time) to make a remote script that users can cut and paste onto their website. Whenever a page on their website is served the script refers back to my server and sends data back to their server.

    (The user would have already registered for an account on my site and the cut and pasted code from my site onto his/hers)

    How is this done? (I use JS, PHP and mySQL)

    I assume it would be done something like this?

    Code:
    <script type="text/javascript" src="http://www.myserver.com/yourscript.js"></script>
    So my PHP code for the specific user would be placed in yourscript.js ?

    where would I put the user's userid and other user specific information?

    -

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Bobafart View Post
    Hi,

    I am trying (for the first time) to make a remote script that users can cut and paste onto their website. Whenever a page on their website is served the script refers back to my server and sends data back to their server.
    I need detail, what data? One of the reason I avoid ads and trafic counters sites is that they use rich app to collect data and this make my site slower.
    I know that data can be collected in a better way for both parts but that depend on many things. In my opinion the site must supply a minimum set of data, all statistic processing must may be done on your server.
    An example of such a light way:

    on the external site on each page, somewhere where both parts are agreed that is not annoying:

    Code:
    <img href="http://yourserver/your-image.gif"/>
    on your server:

    - watch the logs for request your-image.gif from client ip
    - make statistics: count the pages from the referer, time, ..., what ever you have in any log lines.

    Of course that is not remote app and I'm sure that didn't collect all the data you have in mind but once you give details about what data you need, we find a way:
    - to be resonable for both parts, clients and you
    - avoid funcy, unsafe or complicated way to do this

    best regards

  • #3
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post
    Hi oesxyl,

    I am trying to make a simple,lightweight link exchange app (more for my own learning than anything else).

    1. user registers/logsinto my site
    2. user submits their site/blog RSS feed into a mySQL table on my server
    3. user cuts and pastes code from my server and puts it on their site/blog
    3. everytime the cut and pasted code from my site loads on their site the following happens:
    a) small RSS feed items from other sites are loaded onto their site (promoting the link exchange) via my cut and paste code
    b) a page impression increments and is stored on my server using the users id


    that's all


    so the data I need to start off with at this point is sending the userid back to my sever whenever the site loads via the cut and paste code...

    not sure how to do that

    does that answer your question? (googling for a tutorial hasn't helped either)

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Bobafart View Post
    Hi oesxyl,

    I am trying to make a simple,lightweight link exchange app (more for my own learning than anything else).

    1. user registers/logsinto my site
    2. user submits their site/blog RSS feed into a mySQL table on my server
    3. user cuts and pastes code from my server and puts it on their site/blog
    3. everytime the cut and pasted code from my site loads on their site the following happens:
    a) small RSS feed items from other sites are loaded onto their site (promoting the link exchange) via my cut and paste code
    b) a page impression increments and is stored on my server using the users id

    that's all

    so the data I need to start off with at this point is sending the userid back to my sever whenever the site loads via the cut and paste code...

    not sure how to do that

    does that answer your question? (googling for a tutorial hasn't helped either)
    wow, It's more then I imagine, I mean the task is bigger. I must put all this together, I think I have few idea,

    keywords for google: microformat, rdf, grddl

    you can make an idea looking to:

    http://2006.xmlconference.org/procee...27/slides.html


    best regards

  • Users who have thanked oesxyl for this post:

    Bobafart (02-24-2008)

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,492
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    I'm not sure if this will help you, but here's an example of how you
    would give them the code to insert into their site, and it calls
    a PHP script on your server.

    Example, insert this code into your website and see what happens ...
    <script type="text/javascript" src="http://www.catpin.com/bumper_sticker3.php">

    Here is the PHP script that is executed:
    PHP Code:
    <?php

    // Do all of your PHP stuff first ...
    $quote file("bumper_sticker.dat");
    shuffle($quote);

    // Create the header for sending back Javascript.
    // You need to return something ... even if it's just
    // a blank space...  In this case, it returns a random
    // "bumper sticker".
    Header("content-type: application/x-javascript");
    $string str_replace(array("\r\n""\r""\n"), ""$quote[0]);
    $quo str_replace("\"""`"$string);
    echo 
    "document.write(\"$quo\")";
    ?>

  • Users who have thanked mlseim for this post:

    Bobafart (02-24-2008)

  • #6
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post
    mlseim, that was the exact kind of thing I was looking for... thanks!

    why do you need to send a header? can you not just echo a string?

  • #7
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post
    mlseim,

    I have taken your code and I am playing around with it...
    Code:
    <?php 
    
    // Do all of your PHP stuff first ... 
    $quote = array();
    $quote[] = 'hello world';
    $quote[] = 'there are weapons of mass destruction in Iraq';
    $quote[] = 'Shock and Awe baby!';
    $quote[] = 'hail to the Chief';  
    shuffle($quote); 
    
    // Create the header for sending back Javascript. 
    // You need to return something ... even if it's just 
    // a blank space...  In this case, it returns a random 
    // "bumper sticker". 
    Header("content-type: application/x-javascript"); 
    $string = str_replace(array("\r\n", "\r", "\n"), "", $quote[0]); 
    $quo = str_replace("\"", "`", $string); 
    echo "document.write(\"$quo\")"; 
    ?>
    I have place it here (the direct link to the server side script):

    http://www.gabbr.com/promotion/linkexchange/ssi.php

    and I have posted the "cut and paste code" (<script type="text/javascript" src="http://www.gabbr.com/promotion/linkexchange/ssi.php">) here:

    http://www.gabbr.com/drdel/

    the entire site doesn't render.... I think it is because of the headers...

    if I wanted to send images/text to the users's site.. do I need to use headers?

  • #8
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,492
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    It looks like you're missing something (in red) ...

    <script type="text/javascript" src="http://www.gabbr.com/promotion/linkexchange/ssi.php"></script>

    And yes, you need to specify the content type in header. If you're
    calling it using Javascripting, it is expecting back "Javascripting".

    For images, you really don't need to use Javascripting ....
    You can do something like this:
    <img src="http://www.gabbr.com/promotion/linkexchange/image.php" alt="" />

    Your PHP script needs to send back a valid image "content-type".
    Like JPG or GIF. See this: http://us2.php.net/gd

    Super Basic example:
    PHP Code:
    <?php
    // Set the content-type
    header("Content-type: image/jpg");

    // Source image from your directory  
    $iSource imagecreatefromjpg("myimage.jpg");

    // Output image
    imagejpeg($iSourcenull100);
      
    // Clean-up Memory
    imagedestroy($iSource);
    ?>
    EDIT:
    To use Javascripting for images, do something like this example:

    theimages = new Array("image1.jpg", "image2.jpg", "image3.jpg");
    whichimage = Math.floor(Math.random()*theimages.length);
    document.write('<IMG SRC="' +theimages[whichimage]+ '">');

    To write BOTH text AND images, Javascripting is the method to use
    because you can't specify two different content-types using PHP.


    .
    Last edited by mlseim; 02-24-2008 at 09:17 PM.

  • Users who have thanked mlseim for this post:

    Bobafart (02-25-2008)

  • #9
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post
    I will be using text and images, so I will be using Javascript.

    the code you gave me in your example:

    Code:
    theimages = new Array("image1.jpg", "image2.jpg", "image3.jpg"); 
    whichimage = Math.floor(Math.random()*theimages.length); 
    document.write('<IMG SRC="' +theimages[whichimage]+ '">');
    that would go in my server side PHP file, correct? And I would put a JS header (Header("content-type: application/x-javascript"); ) before that code.. is that how it works?

  • #10
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,492
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    bob ...
    Yes, I didn't have time to make an example.

    You do all of your PHP first, then use Javascripting after the
    "Header" part to process and send back the Javascripting.

  • Users who have thanked mlseim for this post:

    Bobafart (02-25-2008)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •