Hi,

Does this work if you try to decode simple strings (without punctuation)? If
so, perhaps you have your magic quotes setting interfering.

You should not be echoing HTML directly - use htmlspecialchars() around
$text_area1.

Jevon

On Wed, Dec 2, 2009 at 3:24 AM, newbie01 php <[email protected]> wrote:

> Hi,
>
> Need some help with the code below please.
>
> Am trying to have a PHP script similar to what is on
> http://www.tareeinternet.com/scripts/byterun.php.
>
> I can't seem to get the right decoding function to work correctly, can
> someone please advise what could be wrong? Thanks in advance.
>
> <?php
> $text_area1 = null;
> $text_area2 = null;
>
> if( isset($_POST['cutnpaste']) || isset($_POST['copynpaste']) || isset
> ($_POST['decode']) ){
>        $text_area1 = $_POST['text_area1'];
>        $text_area2 = $_POST['text_area2'];
>
>        if(isset($_POST['cutnpaste'])) {
>                cutnpaste($text_area1, $text_area2);
>        } else if (isset($_POST['copynpaste'])) {
>                copynpaste($text_area1, $text_area2);
>        } else if (isset($_POST['decode'])) {
>                decode($text_area1, $text_area2);
>        }
>        else {
>                //nothing to do
>        }
> }
> function copynpaste(&$text_area1, &$text_area2) {
>        $text_area2 = $text_area1;
> }
>
> function cutnpaste(&$text_area1, &$text_area2) {
>        $text_area2 = $text_area1;
>        $text_area1 = null;
> }
>
> //http://www.tareeinternet.com/scripts/byterun.php
> function decode(&$text_area1, &$text_area2) {
>        /* // $text_area2 = $text_area1; */
>        //$text_area2 = "TEXTAREA2 should now have the decoded text";
>    //
>        // TEST 01, 02 and 04 gives the same result
>        //
>    // TEST 01:
>        // This works - hardcoded - sort of - but some decoded text is not
> correct
>        //$text_area2=base64_decode
>
> ('Pz48P3BocCANCiAgIC8vIGMybm41Y3QgdDIgZDF0MWIxczUNCmYzbmN0NDJuIGc1dF9jMm5uNWN0NDJuKCQxLCAkYiwkcykgew0KLy8gICBQM3RFbnYoIk9SQUNMRV9TSUQ9IiAuICRjKTsNCi8vNWNoMiAnY3YxbCAnIC4gJHM7DQogICBQM3RFbnYoIlROU19BRE1JTj1EOlwycjFjbDVccHIyZDNjdFw2MC5hLjBcZGJfNlxORVRXT1JLIik7DQogICAkM24xbTUgPSAkMTsNCiAgICRwd2QgPSAkYjsNCiAgICRkYnMgPSAkczsNCi8vICAgJGM9MmM0X2Mybm41Y3QoJDNuMW01LCAkcHdkLCAkYyk7DQogICAgIDRmICghQCgkYz0yYzRfYzJubjVjdCgkM24xbTUsICRwd2QsICRkYnMpKSkgew0KICAgICAgNWNoMiAiRDF0MWIxczUgQzJubjVjdDQybiBFcnIyciEgUGw1MXM1IGNsNGNrIGg1cjUgdDIgbDJnNG4gMWcxNG4uLi4gIjsNCgkgIDVjaDIgJzwxIGhyNWY9ImwyZzRuLmh0bSI
>
> +PGYybnQgYzJsMnI9IiNGRjAwMDAiIGYxYzU9IkFyNDFsLCBINWx2NXQ0YzEsIHMxbnMtczVyNGYiPjxzdHIybmc
> +TE9HSU48L3N0cjJuZz48L2YybnQ
>
> +PC8xPic7DQoJICBkNDUoKTsNCiAgIH0NCiAgIDVsczV7DQogICAkYyA9IDJjNF9jMm5uNWN0KCQzbjFtNSwgJHB3ZCwkZGJzKTsNCiAgIHI1dDNybiAkYzsNCiAgIH0NCn0NCg0KZjNuY3Q0Mm4gNW5jMmQ1XzNybCAoJHN0cjRuZykgew0KICAgJHN0ciA9IHByNWdfcjVwbDFjNSgnL1xzLycsICclYTAnLCAkc3RyNG5nKTsNCiAgIHI1dDNybiAkc3RyOw0KfQ0KPz4NCg==');
>        //
>        // TEST 02:
>        // This works - sort of - but some decoded text is not correct
>    $text_area2=base64_decode($text_area1);
>    //
>        // TEST 03:
>        // This gives data error
>        // Warning: gzinflate() [function.gzinflate]: data error in
> I:\MyXAMPP
> \htdocs\sandbox\test.php on line 41
>        //
>    //$text_area2=eval(gzinflate(base64_decode($text_area1)));
>        //
>        // TEST 04:
>        // This works - sort of - but some decoded text is not correct
>    //$text_area2 = null;
>    //for ($i=0; $i < ceil(strlen($text_area1)/256); $i++)
>    //   $text_area2 = $text_area2 . base64_decode(substr
> ($text_area1,$i*256,256));
> }
> ?>
>
> <html>
>        <head><title>Test</title></head>
>        <body>
>                <form method="post" action="test.php">
>                        <textarea cols=100 rows=10 name="text_area1"><?php
> echo $text_area1?
> ></textarea><br>
>                        <input type="submit" name="copynpaste" paste"
> value="copynpaste"/>
>                        <input type="submit" name="cutnpaste"
> value="cutnpaste"/>
>                        <input type="submit" name="decode" value="decode"/>
>            <br>
>                        <textarea cols=100 rows=10 cols=20
> name="text_area2"><?php echo
> $text_area2?></textarea>
>                </form>
>        </body>
>
> </html>
>
> Expected decoded string/text should be as below, more or less. Thanks
> in advance.
>
> <?php
>   // connect to database
> function get_connection($a, $b,$s) {
> //   PutEnv("ORACLE_SID=" . $c);
> //echo 'cval ' . $s;
>   PutEnv("TNS_ADMIN=C:/oracle/product/10.2.0/db_1/NETWORK");
>   $uname = $a;
>   $pwd = $b;
>   $dbs = $s;
> echo $dbs;
> //   $c=oci_connect($uname, $pwd, $c);
>     if (!@($c=oci_connect($uname, $pwd, $dbs))) {
>      echo "Database Connection Error! Please click here to login
> again... ";
>          echo '<a href="login.htm"><font color="#FF0000" face="Arial,
> Helvetica, sans-serif"><strong>LOGIN</strong></font></a>';
>          die();
>   }
>   else{
>   $c = oci_connect($uname, $pwd,$dbs);
>   return $c;
>   }
> }
>
> function encode_url ($string) {
>   $str = preg_replace('/\s/', '%20', $string);
>   return $str;
> }
> ?>
>
> --
> NZ PHP Users Group: http://groups.google.com/group/nzphpug
> To post, send email to [email protected]
> To unsubscribe, send email to
> [email protected]<nzphpug%[email protected]>
>

-- 
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]

Reply via email to