PDA

View Full Version : A PHP script that does not want to work


marlborolights
03-24-2002, 10:44 AM
Hi all,

I am very new to this forum and to PHP, but I need your help.

I am on a paied host that supports php.

I found a script, but it does not want to work.

Basically the script has a form where the user need to paste the html code, and the script crypt it.

I managed to make the form working, but after pressing the submit button, I get a 404 error.

The form is here:
http://www.diludovico.it/prova.php

The script is this:

<?php
if (isset($Crypt)){
$enc_string = "";
$html = str_replace("\r\n", "",$html);
//$html = str_replace("\"", "", $html);
$length = strlen($html);

for ($i=0;$i<$length;$i++)
{
$current_chr = substr($html, $i, 1);
$inter = ord($current_chr)+3;
$enc_string .= chr($inter);
}
echo "Please cut and paste the following code into your HTML editor";
//$enc_string = $enc_string;
$script="<script>
var a, s, n;
function UnCrypt(s) {r='';for(i=0;i<s.length;i++){n=s.charCodeAt(i); if (n>=8364) {n = 128;} r += String.fromCharCode( n - 3 ); }return r;}
a =\"".str_replace('_', '', $enc_string)."\";
document.write (UnCrypt(a));
</script>";
}
else {
echo "Paste your HTML into the box below and click Crypt";
}
?>
<form action="index2.php" method="post">
<input type="hidden" name="id" value="36">
<textarea cols="75" rows="20" name="html"><?php echo $script?></textarea><br>

<input type="submit" name="Crypt" value="Crypt">
</form>

Can anyone tell me how to make it work?

Thanks a lot in advance

ML

torrent
03-24-2002, 11:45 AM
The problem is that you are posting to a file called index2.php and that file doesn't exist.

marlborolights
03-24-2002, 12:09 PM
Could you please post how the index2.php shoul look like, in order to include the output of the form?

Thanks a lot in advance.

ML

torrent
03-24-2002, 01:14 PM
Looking at your page I think you need only change the <form> tag to read this:

<form action="<?=$PHP_SELF?>" method="post">

and copy the php crypt code into the prova.php file (at the top somewhere just after the <HTML> tag would do).

marlborolights
03-24-2002, 01:29 PM
But it does not work :(

The file prova.php, is just the PHP script, without anything else.

I modified the form action, but I got this error:

Paste your HTML into the box below and click Crypt<form action="
Parse error: parse error in /home/sites/site2/web/prova.php on line 27


I will try to paste the script into a HTML document...
But if you have any better solution, it will help me, as I do not know anything about PHP.

Thanks a lot in advance.

ML

scoutt
03-24-2002, 01:32 PM
ok I think I am lost on this. what do you want to do with the html that is entered in the textbox? save it to a file? save it to a database?

marlborolights
03-24-2002, 01:44 PM
You can see the script working here:
http://www.blueroot.net/index2.php?id=36

You do not have to enter any text, just hit crypt
The source of the script is here:
http://www.blueroot.net/index2.php?id=38

The problem is that there is no read-me or instructions...

If anyone has an idea...

Thanks.

ML

marlborolights
03-24-2002, 01:46 PM
Originally posted by scoutt
ok I think I am lost on this. what do you want to do with the html that is entered in the textbox? save it to a file? save it to a database?

The user should input some html code. The script should cript it, and display it back to the visitor.

If it could be saved, it would be nice, but it's not necessary.

Thanks a lot.

ML

scoutt
03-24-2002, 02:18 PM
Ok I can tell you what I think it does and those links are dead. also this will not stop anybody from stealing your code. and Torrnet was right, you need to use the $PHP_SELF in the form tag. the reason it uses index2.php is because that is what the file is called this code sits in.

when you first start the page, it checks to see if $Crypt is set. $crypt is the variable that is in the form. the name of the button. this is the code in blue

<?php
if (isset($Crypt)){ //checks for variable is set
$enc_string = "";
$html = str_replace("\r\n", "",$html); //replaces enters and line breaks with nothing
//$html = str_replace("\"", "", $html); //replaces \ with nothing

$length = strlen($html); //counts how long the string is


for ($i=0;$i<$length;$i++)
{
$current_chr = substr($html, $i, 1); //starts at the beginning of the code entered in the text box

$inter = ord($current_chr)+3; //replaces characters with there known ascii value

$enc_string .= chr($inter); //returns the ascci value

}
echo "Please cut and paste the following code into your HTML editor";
//$enc_string = $enc_string;
$script="<script>//this script is suppose to write it out to the screen as encrypted
var a, s, n;
function UnCrypt(s) {r='';for(i=0;i<s.length;i++){n=s.charCodeAt(i); if (n>=8364) {n = 128;} r += String.fromCharCode( n - 3 ); }return r;}
a =\"".str_replace('_', '', $enc_string)."\";
document.write (UnCrypt(a));
</script>";
}
now if the variable is not set it will read the code below. which is the form to enter the html.
else {
echo "Paste your HTML into the box below and click Crypt";
}
?>
<form action="index2.php" method="post">
<input type="hidden" name="id" value="36">
<textarea cols="75" rows="20" name="html"><?php echo $script?></textarea><br>

<input type="submit" name="Crypt" value="Crypt">
</form>

marlborolights
03-24-2002, 05:27 PM
I really appreciate that, but I still do not know how to make it work.

I copied and pasted the code into a new file called, once again, prova.php (it means example.php in Italian)
uploaded and run form the browser.

I get the form, and that's fine.

I press encrypt, and nothing happens, besides the fact that the script now creates a file index2.php, but it's a blank file.

I know that for you it's very easy, but I do not know how to make it work...

Any very easy-to-follow steps would be really appreciated.

I can offer you a cold beer, or a good pizza.

Thanks a lot in advance.

ML

scoutt
03-24-2002, 05:55 PM
if you can send that beeer and pizza though the mail I will take it :D

anyway..... change this.

<form action="index2.php" method="post">

to this

<form action="prova.php" method="post">

scoutt
03-24-2002, 06:07 PM
boy I am an idiot.

do you get this after you push the button.

<script>
var a, s, n;
function UnCrypt(s) {r='';for(i=0;i<s.length;i++){n=s.charCodeAt(i); if (n>=8364) {n = 128;} r += String.fromCharCode( n - 3 ); }return r;}
a ="?kwpoA?khdgA?2khdgA?erg|Awhvwlqj?2erg|A?2kwpoA";
document.write (UnCrypt(a));
</script>

if so that is correct. just insert that whole thing in an empty html file.


<html>
<head>
</head>
<body>
<script>
var a, s, n;
function UnCrypt(s) {r='';for(i=0;i<s.length;i++){n=s.charCodeAt(i); if (n>=8364) {n = 128;} r += String.fromCharCode( n - 3 ); }return r;}
a ="?kwpoA?khdgA?2khdgA?erg|Awhvwlqj?2erg|A?2kwpoA";
document.write (UnCrypt(a));
</script>
</body>
</html>

run that and you will see what it does.

what it does is that it encrypts the html you enter in the text box. then after you push the button it will encrypt the code and give it to you in the form of a script. thenyou need to do what I told you above.

try this if you want to see it work.

link removed.

kevin
03-24-2002, 11:16 PM
ignore this post, just testing something

marlborolights
03-25-2002, 02:03 AM
Originally posted by scoutt
boy I am an idiot.

do you get this after you push the button.

<script>
var a, s, n;
function UnCrypt(s) {r='';for(i=0;i<s.length;i++){n=s.charCodeAt(i); if (n>=8364) {n = 128;} r += String.fromCharCode( n - 3 ); }return r;}
a ="?kwpoA?khdgA?2khdgA?erg|Awhvwlqj?2erg|A?2kwpoA";
document.write (UnCrypt(a));
</script>

if so that is correct. just insert that whole thing in an empty html file.


that's exactly what the script is supposed to do. It takes the html code, and encrypt it, so that it's impossible to view the source of the page.



<html>
<head>
</head>
<body>
<script>
var a, s, n;
function UnCrypt(s) {r='';for(i=0;i<s.length;i++){n=s.charCodeAt(i); if (n>=8364) {n = 128;} r += String.fromCharCode( n - 3 ); }return r;}
a ="?kwpoA?khdgA?2khdgA?erg|Awhvwlqj?2erg|A?2kwpoA";
document.write (UnCrypt(a));
</script>
</body>
</html>

run that and you will see what it does.



you get a page with testing. Try to view the source: it's impossible, unless you change document.write with alert!!!


what it does is that it encrypts the html you enter in the text box. then after you push the button it will encrypt the code and give it to you in the form of a script. thenyou need to do what I told you above.


That's right... As I told you, it's not 100% safe, but it will work mostly.


try this if you want to see it work.

link removed

It works fine.
The problem is how to make it work on my webpage.

Could you please send me the crypt.php or post the code of the page?

Thanks a lot in advance.

ML

P.S.: I will zip the pizza and beer, and send it to you as soon as possible ;-)

marlborolights
03-25-2002, 05:42 AM
the previous reply does not seem to be registered...

ML

scoutt
03-25-2002, 07:53 AM
marlborolights, we are experiencing technical difficulties witht he forums is why you are having problems posting.
so mine works because I have the form action the name of the page. that is what you need to do. take this code I have and name it crypt.php and I bet it works ;)



<?php
if (isset($Crypt)){ //checks for variable is set
$enc_string = "";
$html = str_replace("\r\n", "",$html); //replaces enters and line breaks with nothing
//$html = str_replace("\"", "", $html); //replaces \ with nothing

$length = strlen($html); //counts how long the string is


for ($i=0;$i<$length;$i++)
{
$current_chr = substr($html, $i, 1); //starts at the beginning of the code entered in the text box

$inter = ord($current_chr)+3; //replaces characters with there known ascii value

$enc_string .= chr($inter); //returns the ascci value

}
echo "Please cut and paste the following code into your HTML editor";
//$enc_string = $enc_string;
$script="<script>
var a, s, n;
function UnCrypt(s) {r='';for(i=0;i<s.length;i++){n=s.charCodeAt(i); if (n>=8364) {n = 128;} r += String.fromCharCode( n - 3 ); }return r;}
a =\"".str_replace('_', '', $enc_string)."\";
document.write (UnCrypt(a));
</script>";
}

else {
echo "Paste your HTML into the box below and click Crypt";
}
?>
<form action="crypt.php" method="post">
<input type="hidden" name="id" value="36">
<textarea cols="75" rows="20" name="html"><?php echo $script?></textarea><br>

<input type="submit" name="Crypt" value="Crypt">
</form>
?>

marlborolights
03-25-2002, 08:53 AM
It finally works.

I really appreciate your help.

And of course, as I promised you, here is your pizza and your beer ;-)

Have a great day.

ML

scoutt
03-25-2002, 09:05 AM
haha that's great :rofl:

just remember the name of the form action has to be the name of the file. so if you used what torrent showed you

<form action="<? $PHP_SELF ?>" >

you won't have to worry about it anymore.