...

View Full Version : Making a Remote Script App



Bobafart
02-24-2008, 02:24 AM
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?



<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?

-

oesxyl
02-24-2008, 02:53 PM
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:



<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

Bobafart
02-24-2008, 03:16 PM
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)

oesxyl
02-24-2008, 03:54 PM
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/proceedings/127/slides.html


best regards

mlseim
02-24-2008, 06:09 PM
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

// 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\")";
?>

Bobafart
02-24-2008, 06:47 PM
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?

Bobafart
02-24-2008, 07:01 PM
mlseim,

I have taken your code and I am playing around with it...


<?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?

mlseim
02-24-2008, 08:55 PM
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
// Set the content-type
header("Content-type: image/jpg");

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

// Output image
imagejpeg($iSource, null, 100);

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


.

Bobafart
02-25-2008, 11:04 AM
I will be using text and images, so I will be using Javascript.

the code you gave me in your example:



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?

mlseim
02-25-2008, 12:54 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum