PDA

View Full Version : Resolved Combine 4 textareas in 1



newbtophp
10-26-2009, 10:49 PM
I have the following javascript:


<script LANGUAGE="JavaScript">
<!--

hp_ok=true;

function hp_d01(s){
if(!hp_ok)return;var o="",ar=new Array(),os="",ic=0;

for(i=0;i<s.length;i++){
c=s.charCodeAt(i);

if(c<128)c=c^2;

os+=String.fromCharCode(c);

if(os.length>80){
ar[ic++]=os;os=""
}
}

o=ar.join("")+os;

document.write('<textarea rows=5 cols=100>');
document.write(o);
document.write('</textarea>');

}

//-->
</SCRIPT>

It currently outputs 4 different code within 4 textareas. How would i make all the code output in just 1 whole textarea :confused:

Thanks.

Nile
10-27-2009, 12:10 PM
Try this:


hp_ok=true;
var a = "";

function hp_d01(s){
if(!hp_ok)return;var o="",ar=new Array(),os="",ic=0;

for(i=0;i<s.length;i++){
c=s.charCodeAt(i);

if(c<128)c=c^2;

os+=String.fromCharCode(c);

if(os.length>80){
ar[ic++]=os;os=""
}
}

o=ar.join("")+os;
a += o;
}
documement.write("<textarea>"+a+"</textarea");

newbtophp
10-27-2009, 02:18 PM
Nile, it doesnt seem to work \:

ps: you missed the ending tag on the textarea:

</textarea>");

jscheuer1
10-27-2009, 06:25 PM
The function in your original code will only create one text area each time it runs. Each time it does that, it will overwrite the existing page, if any. There is nothing in your code that shows how or when the function is invoked. If you want more help:

Please post a link to the page on your site that contains the problematic code so we can check it out.

newbtophp
10-27-2009, 08:33 PM
The function in your original code will only create one text area each time it runs. Each time it does that, it will overwrite the existing page, if any. There is nothing in your code that shows how or when the function is invoked.

Maybe manipulate the function so the code always stay within 1 textarea, no matter how large the code.



If you want more help:

Please post a link to the page on your site that contains the problematic code so we can check it out.

Sorry,

here you go:

deleted, Possible Threat Detected

As you can see it displays the code within 4 textareas, im trying to combine all the code and only display in 1 textarea.

jscheuer1
10-28-2009, 12:32 AM
I'm getting a threat detection alert from that page from AVG antivirus. As a result, I'm not sure I can help you until that is cleared up. It was for Active X, an IE only threat, fortunately for me (if this is a real threat), I don't surf in IE. Anyways, to even raise that alert, at the very least there is something odd about your page. My advice to others would be to not access your page until this is cleared up. My advice to you would be (if this is an innocent mistake) a redesign based upon what you want to do. If it is intentional - get out of town, we know where you live.

newbtophp
10-28-2009, 12:36 AM
Hmm its definately unintentional, im using firefox and have norton running. I dont see any warning.

The page has no harmful code, all it is a javascript decrypting function which displays the decrypted code within textarea/s, (and im trying to make it display the code in 1 no matter how much code their is)

Plus, if you feel uncomftable you can view the pages source remotely. (Example:

http://www.tech-faq.com/view-page-source.shtml )

Also attached is a screenshot of the content.

I've adjusted the code so it decrypts other code then what i had up their before (Before it displayed code within 4 textareas, now since I've changed the code, it displays 12 textareas). Check now to see if you get the error or not, it should be fine now.

jscheuer1
10-28-2009, 07:55 AM
OK, glad we straightened that out. Hmm, there are actually more than 4 textareas on the page when I view it. What happens is that each time the hp_d01 function is run, and it is run several times, it creates a new textarea. This all happens while the page is loading so nothing is overwritten as can often happen with document.write.

Nile was actually on to something there, but he didn't get that the function was being called numerous times. Here's what I'd try:


hp_ok=true;

function hp_d01(s){
if(!hp_ok)return;var o="",ar=new Array(),os="",ic=0;

for(i=0;i<s.length;i++){
c=s.charCodeAt(i);

if(c<128)c=c^2;

os+=String.fromCharCode(c);

if(os.length>80){
ar[ic++]=os;os=""
}
}

o=ar.join("")+os;
document.getElementById('outputarea').value += '\n' + o;

}
document.write('<textarea id="outputarea" style="width:100%; height:100px;">');
document.write('</textarea>');
document.getElementById('outputarea').value = '';

This however will not combine 4 areas into one. It will produce only one area on the page, each time the hp_d01 function is run, this one area will have the output added to it.

newbtophp
10-28-2009, 08:19 AM
Thanks John, that worked perfect. :)

I know this is a javascript forum, but was wondering is theirs anyway I could grab the contents (code) of that textarea in to a php variable?

jscheuer1
10-28-2009, 08:31 AM
If you make it a part of a form (I'd recommend using the post method), give the textarea a name and the user submits the form, it will be available to PHP as part of the post data. You could even have the form submit via javascript and I believe there is a PHPSelf or something like that or others that can be used as the action of the form. Other than that, some type of AJAX in conjunction with javascript would likely be required.

It would depend upon why you want to get this data to PHP and what you want PHP to do with it. Could you clear those two points up?

newbtophp
10-28-2009, 08:39 AM
Well, i'ved created a form using PHP which writes to this function, and its currently working fine, but im wanting to get the contents of the textarea by using a variable so i could then use that variable to write a to text file, so visitors can download the decrypted code.

But the trouble is im not sure how to interact the js with the php.

jscheuer1
10-28-2009, 09:00 AM
You know, I'm not real clear on this still, and if we need to use AJAX, I'm not real clear on how that would work in this case. But if the data is in a form as I mentioned, the user can submit the form via post. The receiving page (or even PHP script) could then create the text file and (if it is a page) display a link to it. That's all pretty standard PHP. I could run you through the basics, but you would probably get more precise help in the PHP forum or researching this online with Google. I'm no expert at PHP. If it were not posted to a page, javascript could conceivably poll the server for the file's completion then generate a link to it. Naming the text file might be tricky though because multiple users could conceivably collide in writing to the file. If you could create a temporary directory based upon the user's name and/or ip, it might work out.

jscheuer1
10-28-2009, 03:07 PM
I was thinking about this a bit more. I'm still not clear on the filename bit, but you could post submit a form to a hidden frame or iframe, have the PHP on that page write the file and write the filename. Javascript on that page could write the link back to the sending page.

newbtophp
10-29-2009, 02:20 AM
Hmm, thanks, I've created some php code using explode() but still no luck.

The JS is sorted thanks to you and nile :).

I've moved my php question to:

http://www.dynamicdrive.com/forums/showthread.php?p=209070