Link to home
Start Free TrialLog in
Avatar of FirstBorn
FirstBornFlag for United States of America

asked on

How to extract and encrypt different page on My site to use with document.write(unescape( code or similar format

Hi,

Thanks for helping.

What I'm looking to do is extract an entire page of code from a different webserver of mine,
and take that code and encrypt it so that I can use the "document.write(unescape("
function and view it on the current page of the other webserver.

For instance,
I need a text box to put the URL of My webpage,
a submit button to have it extract the info from that specific page
typed into the text box,
then create the unescape code with that specific page's encrypted code included
in the unescape("Right HERE!") part of the document.write code.

Thank You VERY Much for Your Help!

FirstBorn

PS.  OR, if there is a way to do it in .php, that would be GREAT, Too!!!
Avatar of gops1
gops1
Flag of United States of America image

You can use Ajax for this
Avatar of b0lsc0tt
Is the web server yours or not?  Is the other page on the same domain or not?  If either is No then AJAX and Javascript won't help.  The object used for AJAX does not allow cross domain scripting.  Javascript on its own has no way to get the content from another server/site.

What do you mean by encrypt?  The unencode() function in javascript doesn't decrypt anything.  It reverses what is done by encode().  That function will basically just make text "html safe."  Nothing is encrypted though.

You probably need to stick to a PHP solution.  However please clarify what you want.  Let me know if you have a question about any of this.

bol
Avatar of FirstBorn

ASKER

Hi bol,

Thanks for the QUICK response.

"Is the web server yours or not?"
Actually, I have a Few web hosts for certain domain names,
including for some of My clients' web sites.
Also, some of the URLs that I need to do this with are for
affiliate links, as well.

So, the answer is Yes and No...

I DO have a script that does something similar to this,
but it is SLOPPY, FULL o' BUGS, and getting support from this guy
is like Pulling Teeth...
(yep, it was paid for and the guy doesn't seem to support it like he's supposed to.)

... anyway,  If, let's say My affiliate link is http://whatever.com/linkid1234
the Code will take the content from that page and encrypt it, then,
use the document.write function to display it.
So, the END Result would look similar to the code
in the Code Snippet included here.

Does that make sense?

It IS a bit confusing, eh?

:)

FirstBorn

PS.  The script that I paid for isn't exactly like what I want done here,
just so You know... I just figured out that what I want will work better.

---------------------------------------------
To gops1,

Hi!

Thanks for Your response.

The only Ajax that I know how to use is the cleaner... haha

Will it do what I just mentioned above?
If so, what code would I need to make it work?

Thanks.

FirstBorn

//----------------------------------------------------
<HTML><HEAD><SCRIPT LANGUAGE="javascript">
<!--
document.write(unescape("%3c%68%74%6d%6c%3e%0a%09%09%3c%66%72%61%6d%65%73%65%74%20%72%6f%77%73%3d%22%30%2c%2a%22%20%63%6f%6c%73%3d%22%2a%22%20%66%72%61%6d%65%62%6f%72%64%65%72%3d%30%20%66%72%61%6d%65%73%70%61%63%69%6e%67%3d%30%3e%20%0a%09%09%20%20%3c%66%72%61%6d%65%20%73%72%63%3d%22%22%3e%0a%09%09%20%20%3c%66%72%61%6d%65%20%73%72%63%3d%22%68%74%74%70%73%3a%2f%2f%70%61%79%64%6f%74%63%6f%6d%2e%63%6f%6d%2f%72%2f%31%31%38%33%34%2f%46%69%72%73%74%42%6f%72%6e%2f%36%38%33%33%33%39%2f%22%3e%0a%09%09%3c%2f%66%72%61%6d%65%73%65%74%3e%0a%09%09%3c%6e%6f%66%72%61%6d%65%73%3e%3c%62%6f%64%79%20%62%67%63%6f%6c%6f%72%3d%22%23%46%46%46%46%46%46%22%20%74%65%78%74%3d%22%23%30%30%30%30%30%30%22%3e%0a%09%09%3c%2f%62%6f%64%79%3e%3c%2f%6e%6f%66%72%61%6d%65%73%3e%0a%09%09%3c%2f%68%74%6d%6c%3e"));
//-->
</SCRIPT></HEAD></HTML>
//----------------------------------------------------

Open in new window

Thanks for the answers and info.  I am still a little confused about some stuff but let me respond a bit and I may ask a follow up question or two.

You should use PHP.  Look into PHP cURL (http://www.php.net/curl).  You need to make sure that your version of PHP is built to support it.  If you don't know then run phpinfo() (in a blank php script page) and see if CURL is listed.  It allows you to grab info from websites.

What do you mean by encrypt?  From what you describe it doesn't sound like you want to really encrypt the info but you want to convert it to be used on a web page.  In other words so the tags will print on the page and not be interpreted as tags.

If that is what you want then you should look at php's htmlentities() (http://us2.php.net/htmlentities) or htmlspecialchars() (http://us2.php.net/manual/en/function.htmlspecialchars.php).

Let me know if you have a question or need more info.

bol
I apologize, I misread your question. I was thinking that you need to extract the page.
Hi gops1,

Thanks.

FirstBorn

------------------------
Hi bol,

Thanks for the references.

Here is what is in My phpinfo(); display:
//==========================================
cURL support       enabled
cURL Information       libcurl/7.13.2 OpenSSL/0.9.7e zlib/1.2.2 libidn/0.5.13
//==========================================
So, it IS enable, BUT,
I've attached code to show what I'm testing with,
and it displays a Blank Page.

Am I doing something wrong here?

On another note,
IF You look at the code provided above (with the document.write code,)
You'll see a bunch of percent signs with numbers.
How do I get this code just mentioned (would that be encryption?)
from grabbing another site (such as, affiliate webpage) as previously mentioned.

I may have worded it wrong, such as, encryption may not be actually encrypted,
just need to get the code shown above to display as the actual site,
but not shown in the address bar...
That code is Java-Script, and I Know that it does what I want it to:
show the Affiliate web page (or whatever page You want shown,)
BUT
with Your URL instead of the Actual URL.

Any ideas?

Thanks!

FirstBorn

<?php
//
// A very simple example that gets a HTTP page.
//
 
$ch = curl_init();
 
curl_setopt ($ch, CURLOPT_URL, "https://foobar.com/mypage1234");
curl_setopt ($ch, CURLOPT_HEADER, 0);
 
curl_exec ($ch);
 
curl_close ($ch);
?>

Open in new window

Hi bol,

I'm adding some more code here for You to show what is happening.

I've tested the code in the example below,
and I'm getting the "buffer is empty" message.

Any Ideas?

Thanks.

FirstBorn
<?php
 
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'https://myexample.com');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
 
if (empty($buffer))
{
    print "Sorry, buffer is empty.<p>";
}
else
{
    print $buffer;
}
?>

Open in new window

Hi,

Thanks for sticking with this.

OK, the cURL works WITH http:// NOT https://
Well, kind of, sort of...

Even if I use tinyurl.com on an https:// original page,
then it won't work...
However, IF the URL starts with http:// it will grab the
text and format of the page that You're looking for
EXCEPT, when that page has pics on it,
it won't display the graphics / background pics, either...

I've included the Sample Code in this posting.

Ah ha!
I've found something in the scripts that shows the makings of
the Javascript Code above in the URL masking scripts.

It uses bintohex such as:
$escaped .= "%" . bin2hex($data[$count]);
Where $data is as follows:
"<html>
            <frameset rows=\"0,*\" cols=\"*\" frameborder=0 framespacing=0>
              <frame src=\"\">
              <frame src=\"$url\">
            </frameset>
            <noframes><body bgcolor=\"#FFFFFF\" text=\"#000000\">
            </body></noframes>
            </html>";
and $count is as follows:
for($count = 0; $count < strlen($data); $count++)

Here is where it generates the code for the page:
$code = "<HTML><HEAD><SCRIPT LANGUAGE=\"javascript\">\n<!--\ndocument.write(unescape(\"$escaped\"));\n//-->\n</SCRIPT></HEAD></HTML>";

I think that I'm getting there, but not quite yet...

Any Ideas?

Thanks Again for Your Help!

FirstBorn

<?php
 
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://tinyurl.com/ys5h2n');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
 
if (empty($buffer))
{
    print "Sorry, Buffer is Empty!<p>";
}
else
{
    print $buffer;
}
?>

Open in new window

FirstBorn,

Thanks for another post and the info.  I am glad my general help is getting you going.

I have made a note to look at this but just haven't had the time yet.  I hope to have it tomorrow and some point.  Let me know if anything else changes.

A quick comment or two though since I am posting this.  What you had above (using unescape) is just URL encoded text, not encrypted at all.  Just want to clarify terms.  If you want the text to print "correctly" on a web page the URL encoding isn't the answer either.  It needs to be HTML encoded.  If the text should go to a URL then url encoding is the answer.  Basically what you use depends on how or where you will use it.

Also, do you need to grab any content from https pages?

I'll take a look and hope to help more with the code.  Thanks again for posting it and the info.

bol
Hi bol,

Thanks for staying with Me on this.

I need to grab the entire page.

I've found out recently that there are a few things not allowed on My Webserver.
Here is one of the wiki articles for My Web Host:
http://wiki.dreamhost.com/CURL#Alternative_for_file_get_contents.28.29
But,
It seems that I'm already using that code mentioned in the wiki and
still not getting results.

Any ideas?

Christopher
Is the page an http or https page?  Are you using a tinyurl or someother redirect/transfer or will the url be the actual page's?  If the page is https, do you have info on certificates, etc that are needed for a "connection"?  

Will you try to display the whole page?  Earlier you mentioned displaying images from the page.  This complicates things quite a bit.  It is one thing to get the page and use info on it but quite another to actually display some other webpage from another domain.  Which are you doing?  If displaying the whole page then please explain why and your relation to their site.  I could see situations where this could be misused and I wouldn't be comfortable helping to someone do this (i.e. spoofing webpages).

Try adding a line to show the error.  See the example in the code below.  Let me know if you get the message and tell me what the error is.

<?php
 
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://tinyurl.com/ys5h2n');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
if (curl_error() !== "") die ("There was a problem.<br />" . curl_error());
curl_close($curl_handle);
 
if (empty($buffer))
{
    print "Sorry, Buffer is Empty!<p>";
}
else
{
    print $buffer;
}
?>

What do you want to do with the page when you get it?

Let me know if you have a question about any of this.  Sorry for the delay and maybe having you repeat stuff but this should get us going again. :)

bol
Hi bol,

Thanks for continuing to help Me.

Here are the errors generated by Your code:

Warning: Wrong parameter count for curl_error() in /home/account/test.php on line 8

Warning: Wrong parameter count for curl_error() in /home/account/test.php on line 8
There was a problem.

The current page that is in the tinyurl URL in the code is an https page,
but it shouldn't really matter because I want to use the scripts regardless of the http(s).

Yep, I'm attempting to grab the entire page as if it is actually on My site...
example:
http://mysite.com/ 
would appear as:
http://yoursite.com/
in the browser.

That's why the javascript code (with the document.write(unescape( code)
seems to be the best bet so far...

Any Ideas?

Thanks.

FirstBorn

Sorry.  I left out part of what curl_error needs.  The line should be ...

if (curl_errno($curl_handle)) die ("There was a problem.<br />" . curl_error($curl_handle));

Notice I also improved what you use to trigger it.  The rest of the code was actually yours.

It seems like my explanation earlier wasn't clear enough but Javascript won't work and is a poor option to use for what you want.  It can't get info from other servers/domains and depends on the browser to do all the work.  A server solution is so much better.

Are these your domains/servers?  I noticed you said that earlier.  If that is the case and since you want to show the complete page from another domain/server then you should look for an option using the web server.  This is getting out of my expertise but the server can be set to "send" one page even if two different URLs (even domains) are used.  This would be the most efficient way to do this it seems.

The details are still real vague and general though so maybe there is something I am missing.  However I can say that Javascript won't work and would be a poor option.

Could you respond to the questions in the first paragraph in my last comment?  Thanks!

Let me know the result with the correction.  Sorry for the mistake. :)

bol
Hi bol,

Thanks for responding.

k... I'll include the current code with the results.
Still a 'No Go'...

With Your Error Code, I get the following result displayed:


When I don't comment out the curl_error() line, I get the following:
Warning: Wrong parameter count for curl_error() in /home/account/testmask.php on line 9

Warning: Wrong parameter count for curl_error() in /home/account/testmask.php on line 9
There was a problem.

In response to:
"It seems like my explanation earlier wasn't clear enough but Javascript won't work and is a poor option to use for what you want."
The reason why I am suggesting JavaScript is because it is how the scripts of "WebmasterInABox" produces it.  Of which USED to work, but no longer work after a few years of non-use and server changes, etc...

When it USED to work, it Worked Great!

In response to this:
"Is the page an http or https page?  Are you using a tinyurl or someother redirect/transfer or will the url be the actual page's?  If the page is https, do you have info on certificates, etc that are needed for a "connection"?  "
Both http and https (will be used for multiple pages.)
I was using tinyurl currently as to not 'SPAM' this Q with My real page as an example...
No info on Certs for the servers, as well...

Thanks!

FirstBorn

<?php
 
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://tinyurl.com/ys5h2n');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
if (curl_errno($curl_handle)) die ("There was a problem.<br />" . curl_error($curl_handle));
// if (curl_error() !== "") die ("There was a problem.<br />" . curl_error());
curl_close($curl_handle);
 
if (empty($buffer))
{
    print "Sorry, Buffer is Empty!<p>";
}
else
{
    print $buffer;
}
?>

Open in new window

Thanks for the reply, especially for the answers and info.

I am not sure what is causing the error but I have an idea of how to get better info.  First, I am not sure what you meant when you were talking about commenting out and not but the line I provided in my last post was meant to replace and correct the old line.  Don't use both or try the old.  It was definitely wrong.

So that block should now be ...

(see snippet)

Notice I did make some other changes to that "line."  It is now more than one line and doesn't use die.  I am curious to see if you get other errors that may help.  Let me know what happens.  Although I used the tinyurl still please make sure you use a good, live URL that won't need a redirect.

Is that tinyurl actually good?  I haven't actually tried this code but may if you still have a problem and if the URL is good.

I don't know WebmasterInABox but the reason they don't work anymore could certainly be the improved security of browsers.  That is just a guess though.  Did the paragraph below (from my previous comment) make sense or what is your respose to it?

"Are these your domains/servers?  I noticed you said that earlier.  If that is the case and since you want to show the complete page from another domain/server then you should look for an option using the web server.  This is getting out of my expertise but the server can be set to "send" one page even if two different URLs (even domains) are used.  This would be the most efficient way to do this it seems."

Let me know how this works.

bol
<?php
 
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://tinyurl.com/ys5h2n');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
if (curl_errno($curl_handle)) {
    echo "There was a problem.<br />" . curl_error($curl_handle);
}
curl_close($curl_handle);
 
if (empty($buffer))
{
    print "Sorry, Buffer is Empty!<p>";
}
else
{
    print $buffer;
}
?>

Open in new window

Hi bol,

Thanks for the edited code.

I get the following displayed after testing it:
"Sorry, Buffer is Empty!"

Here is where to get the script that creates the  
Javascript code mentioned in the original post of this Q:
http://www.mywebmasterinabox.com/freescripts.php

It is an affiliate link cloaker script that used to work like
a dream, but hasn't worked in quite a while for some reason.

Any ideas?

Thanks.

FirstBorn
Hi bol,

Thanks for staying awake ... :)

k... I tested the code included in this post and got it to somewhat work.

Here's what the results are:
********************************************
The tinyurl.com URL didn't work.
A Direct PayDotCom.com Affiliate URL didn't work.
A Direct Affiliate URL DID work, but with one problem,
no graphics taken from the site.
********************************************
So, it appears the Main Issue with the cURL code is as follows:
1.  It will NOT allow https?
2.  It will NOT grab the graphics when displaying an URL.

Now, I attempted to run the 'Affiliate Link Cloaker' scripts and here are the results:
Since discovering the "https://" and the "tinyurl.com" issue mentioned above,
I attempted to make the scripts create the page with My Direct Affiliate URL.
It STILL comes out Blank when it's SUPPOSED to extract the ENTIRE Page.

I attempted the 'Affiliate Link Cloaker' Scripts on a different web host's server and
it Works!!!

So... I KNOW that it isn't the scripts completely...

Any Ideas on how to get it to work on the web host's server (that it ISN'T working on) and what may be causing it to NOT Work?

Thanks again!

FirstBorn

<?php
$site_url = 'http://mysite.com';
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $site_url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
 
ob_start();
curl_exec($ch);
curl_close($ch);
$file_contents = ob_get_contents();
ob_end_clean();
 
echo $file_contents;
?>

Open in new window

Hi bol,

Oh, one more thing.

I took the page that I created (that worked) on the one webserver where the scripts work and put the page on the one webserver that it Doesn't work.

The page that was created on the other server works on the webserver that the scripts DON'T work.

Is that confusing enough?

Here's an example.
Webserver 1:
(http://mysite1.com/)
Affiliate Link Cloaker Script works.
page1.html was created on Webserver 1 for testing on Webserver 2.

Webserver 2:
(http://mysite2.com/)
Affiliate Link Cloaker Script Does NOT Work.

I repeat:  page1.html was created on Webserver 1.
page1.html was placed on Webserver 2.
Went to http://mysite2.com/page1.html and it WORKED!

So, it has something to do with the scripts extracting the page(s) that
are typed in to the URL area to Cloak.

Any Ideas?

Thanks!

FirstBorn
Hello b0lsc0tt,

No solution has been posted as of Yet...

STILL having this issue and NEED a resolution.

Any Ideas?

Can Ya bring in the BIG GUNS to see if they can help?!?

Thanks.

FirstBorn
Moderator,

Please hold off on clean up.  I will mark this as "Neglected" and see if that attracts some new experts to this since FirstBorn is still interested in getting help.

FirstBorn,

This will bring it to the attention of some new experts.  I ran out of ideas and just haven't had time to really look into this to find a solution.  It would be nice to see this completed though; we have definitely put some effort in and there is some good info here.  Let me know if you have a question about this.  If you wish to delete and start again then that is still an option and you would get your points back.

b0lsc0tt
Hi bol,

Thanks!

Not a problem...

Whatever it takes to resolve this...

Thanks again for Your help!

FirstBorn
Hi bol,

I've got the Answer:

I had to create a CUSTOM php.ini file to make it work...
It was a bit more in depth,
but the sum and substance points to the Custom php.ini
that had to be placed in a cgi-bin folder to make it work.

Here are the MAIN Settings that I had to change to make
the scripts work:

allow_url_fopen = On
allow_url_include = On
register_globals = On

I wanna give You the points for helping,
but the answers given weren't correct.
So, if You want to post:
"Create a Custom php.ini file and put it in the cgi-bin directory)
and change the following settings as follows:
allow_url_fopen = On
allow_url_include = On
register_globals = On"
as the answer,
I will choose that and award You the points.
(with an "A" Grade, of course!)

Thanks.

FirstBorn
ASKER CERTIFIED SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi bol,

Thanks!

Just what I needed and was the answer that I was looking for!

FirstBorn

PS.  Not sure if I'm worried about getting the points back.
I've been a paying member since 2003, so, am I mistaken
in thinking that it's accumulated quite a lot of points by now?
(not sure how to tell how many points I actually have...)
Your welcome!  I'm glad I could help.

You can see your question points by viewing your member profile.  It sounds like you are a premium member so your profile probably says Unlimited Question Points.

Thanks for the grade, the points and the fun question.

bol

p.s.  Since other posters can't see the grading comments (just Asker and those with Assists or Answers) I will post them below to explain my comment.  In the future EE is suppose to make them visible to all but right now that is limited.

<grading comment>
Hi bol,

Thanks!

Just what I needed and was the answer that I was looking for!

FirstBorn

PS. Not sure if I'm worried about getting the points back.
I've been a paying member since 2003, so, am I mistaken
in thinking that it's accumulated quite a lot of points by now?
(not sure how to tell how many points I actually have...)
<end>