php-general Digest 8 Sep 2007 05:10:22 -0000 Issue 5006

Topics (messages 261816 through 261831):

looking for the right mcrypt ciphers
        261816 by: Samuel Vogel
        261817 by: Samuel Vogel

Re: Opening a file
        261818 by: Sanjeev N

Creating a File in Memory
        261819 by: John Schattel
        261821 by: Graham Cossey
        261822 by: Michael Preslar

html2png
        261820 by: timothy johnson

Re: Reg.Photo Upload Tool
        261823 by: Kevin Waterson
        261831 by: Ramesh.b

'application' variables not available? Alternatives?
        261824 by: david
        261828 by: Vidyut Luther

Re: cant mail
        261825 by: Manuel Lemos

Php script for mail in a xhtml page
        261826 by: Mauro Sacchetto
        261829 by: brian

Re: Converting PHP code to C#?
        261827 by: Symbian
        261830 by: mike

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
Hey guys,

I'm wondering which mcrypt cipher will provide me with an encryted string, that can afterwards be encrypted again and is transverable without problems through an link in an e-mail. I would like to encrypt some piece of information (up to 25 characters) and send it to the user in an e-mail via a link like kilu.de?enc=... ! This doesn't work with |MCRYPT_XTEA or |MCRYPT_TWOFISH256, since they create pretty special ASCII characters, that are not interpreted right!

What cipher would you suggest? Or would you suggest a whole different method?

Regards,
Samy

--- End Message ---
--- Begin Message ---
I solved the problem using bin2hex()!

Regards,
Samy

Samuel Vogel schrieb:
Hey guys,

I'm wondering which mcrypt cipher will provide me with an encryted string, that can afterwards be encrypted again and is transverable without problems through an link in an e-mail. I would like to encrypt some piece of information (up to 25 characters) and send it to the user in an e-mail via a link like kilu.de?enc=... ! This doesn't work with |MCRYPT_XTEA or |MCRYPT_TWOFISH256, since they create pretty special ASCII characters, that are not interpreted right!

What cipher would you suggest? Or would you suggest a whole different method?

Regards,
Samy


--- End Message ---
--- Begin Message ---
<?php
$fruit = "apple";
$lines = file("fruits.txt");
if (in_array($fruit,$lines))
  {
  $a = "Y";
  }
?>

Here there may be 2 cases.
1st either file() is not returning any values, that is why array empty and
wrong datatype error, are you able to read the file.

2nd try to use implode function to consider each word as different value in
an array
$lines = implode('', file("fruits.txt"));

Warm Regards,
Sanjeev
http://www.sanchanworld.com/
http://webdirectory.sanchanworld.com - Submit your website URL
http://webhosting.sanchanworld.com - Choose your best web hosting plan

-----Original Message-----
From: Dan Shirah [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, September 05, 2007 7:55 PM
To: php-general
Subject: [PHP] Opening a file

Good Morning!

Opening this file is proving to be a pain. I have a folder that contains a
PHP page and a text file. I am trying to open the contents of the txt file
using file() but it keeps erroring out. Below is the code I'm using to try
and open it:

<?php
$fruit = "apple");
$lines = file("fruits.txt");
if (in_array($fruit,$lines))
  {
  $a = "Y";
  }
?>

So, I'm setting my variable, opening my file as an array in $lines, then
checking to see if my variable is in the array, and if it is, assign a value
ot a new variable.  However, I am getting the following error:

PHP Warning: in_array()
[function.in-array<http://develop1/credit%20card%20processing/function.in-ar
ray>]:
Wrong datatype for second argument

Any ideas?

--- End Message ---
--- Begin Message ---
Hello All,

I am trying to zip data in a PHP program using the following code. The resulting file (ndfdViaPipe.kmz) is zip'ed but the data in the archive lacks a file name. So when a program like Google Earth tries to process the file, it fails. When I bring ndfdViaPipe.kmz into WinZip, the file has no name but can otherwise be extracted just fine. Once extracted, Google Earth can process the file. Does anyone know how I might add the "file name" information to the ndfdViaPipe.kmz? The reason I'm trying to use pipes is to avoid creating a file with the dynamically created data in $kml_string. The plan is to send $kmz_content out in a SOAP service message with the payload as base64 encoded file. If there is a better way to accomplish this I am certainly open to suggestions.

In advance, thanks for any help you care to offer.

John

<?php

$kml_string = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$kml_string = $kml_string . "<kml xmlns=\"http://earth.google.com/kml/2.1\";>";
$kml_string = $kml_string . "<Document>";
$kml_string = $kml_string . " <name>National Digital Forecast Database Data</name>";
$kml_string = $kml_string . "   <open>1</open>";
$kml_string = $kml_string . " <Schema parent=\"Placemark\" name=\"NdfdData\">"; $kml_string = $kml_string . " <SimpleField type=\"wstring\" name=\"UOM\"></SimpleField>"; $kml_string = $kml_string . " <SimpleField type=\"wstring\" name=\"ValidTime\"></SimpleField>"; $kml_string = $kml_string . " <SimpleField type=\"int\" name=\"MaxTemp\"></SimpleField>";
$kml_string = $kml_string . "  </Schema>";
$kml_string = $kml_string . "  <NdfdData>";
$kml_string = $kml_string . "    <name>Maximum Temperature</name>";
$kml_string = $kml_string . " <description>90F valid at 2007-06-26T00:00:00-04:00</description>";
$kml_string = $kml_string . "    <Point>";
$kml_string = $kml_string . "      <coordinates>-77.37,37.82</coordinates>";
$kml_string = $kml_string . "    </Point>";
$kml_string = $kml_string . "    <UOM>F</UOM>";
$kml_string = $kml_string . " <ValidTime>2007-06-26T00:00:00-04:00</ValidTime>";
$kml_string = $kml_string . "    <MaxTemp>95</MaxTemp>";
$kml_string = $kml_string . "  </NdfdData>";
$kml_string = $kml_string . "  <NdfdData>";
$kml_string = $kml_string . "    <name>Maximum Temperature</name>";
$kml_string = $kml_string . " <description>89F valid at 2007-06-26T00:00:00-04:00</description>";
$kml_string = $kml_string . "    <Point>";
$kml_string = $kml_string . "      <coordinates>-77.5,38.00</coordinates>";
$kml_string = $kml_string . "    </Point>";
$kml_string = $kml_string . "    <UOM>F</UOM>";
$kml_string = $kml_string . " <ValidTime>2007-06-26T00:00:00-04:00</ValidTime>";
$kml_string = $kml_string . "    <MaxTemp>89</MaxTemp>";
$kml_string = $kml_string . "  </NdfdData>";
$kml_string = $kml_string . "</Document>";
$kml_string = $kml_string . "</kml>";

$descriptorAssignments = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file to write to
);

$kmz_process = proc_open('zip',$descriptorAssignments,$pipes);

if (is_resource($kmz_process))
{
  fwrite($pipes[0],$kml_string);
  fclose($pipes[0]);

  $kmz_content = stream_get_contents($pipes[1]);

  fclose($pipes[1]);

  $return_value = proc_close($kmz_process);

  //  Only outputting data to ensure it is a properly formatted zip file
// Normally, a SOAP service will sent the data as a base64 encoded payload
  $output_file = fopen('ndfdViaPipe.kmz','w');
  fwrite($output_file,$kmz_content);
  fclose($output_file);
}

?>

--- End Message ---
--- Begin Message ---
Can't help with your main problem, however I find it easier to write
the likes of :

$kml_string = $kml_string . "<Document>";

as:

 $kml_string .= "<Document>";

;-)

On 9/7/07, John Schattel <[EMAIL PROTECTED]> wrote:
> Hello All,
>
> I am trying to zip data in a PHP program using the following code.  The
> resulting file (ndfdViaPipe.kmz) is zip'ed but the data in the archive
> lacks a file name.  So when a program like Google Earth tries to process
> the file, it fails.  When I bring ndfdViaPipe.kmz into WinZip, the file
> has no name but can otherwise be extracted just fine.  Once extracted,
> Google Earth can process the file.  Does anyone know how I might add the
> "file name" information to the ndfdViaPipe.kmz?  The reason I'm trying
> to use pipes is to avoid creating a file with the dynamically created
> data in $kml_string.  The plan is to send $kmz_content out in a SOAP
> service message with the payload as base64 encoded file.  If there is a
> better way to accomplish this I am certainly open to suggestions.
>
> In advance, thanks for any help you care to offer.
>
> John
>
> <?php
>
> $kml_string = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
> $kml_string = $kml_string . "<kml
> xmlns=\"http://earth.google.com/kml/2.1\";>";
> $kml_string = $kml_string . "<Document>";
> $kml_string = $kml_string . "   <name>National Digital Forecast Database
> Data</name>";
> $kml_string = $kml_string . "   <open>1</open>";
> $kml_string = $kml_string . "  <Schema parent=\"Placemark\"
> name=\"NdfdData\">";
> $kml_string = $kml_string . "    <SimpleField type=\"wstring\"
> name=\"UOM\"></SimpleField>";
> $kml_string = $kml_string . "    <SimpleField type=\"wstring\"
> name=\"ValidTime\"></SimpleField>";
> $kml_string = $kml_string . "    <SimpleField type=\"int\"
> name=\"MaxTemp\"></SimpleField>";
> $kml_string = $kml_string . "  </Schema>";
> $kml_string = $kml_string . "  <NdfdData>";
> $kml_string = $kml_string . "    <name>Maximum Temperature</name>";
> $kml_string = $kml_string . "    <description>90F valid at
> 2007-06-26T00:00:00-04:00</description>";
> $kml_string = $kml_string . "    <Point>";
> $kml_string = $kml_string . "      <coordinates>-77.37,37.82</coordinates>";
> $kml_string = $kml_string . "    </Point>";
> $kml_string = $kml_string . "    <UOM>F</UOM>";
> $kml_string = $kml_string . "
> <ValidTime>2007-06-26T00:00:00-04:00</ValidTime>";
> $kml_string = $kml_string . "    <MaxTemp>95</MaxTemp>";
> $kml_string = $kml_string . "  </NdfdData>";
> $kml_string = $kml_string . "  <NdfdData>";
> $kml_string = $kml_string . "    <name>Maximum Temperature</name>";
> $kml_string = $kml_string . "    <description>89F valid at
> 2007-06-26T00:00:00-04:00</description>";
> $kml_string = $kml_string . "    <Point>";
> $kml_string = $kml_string . "      <coordinates>-77.5,38.00</coordinates>";
> $kml_string = $kml_string . "    </Point>";
> $kml_string = $kml_string . "    <UOM>F</UOM>";
> $kml_string = $kml_string . "
> <ValidTime>2007-06-26T00:00:00-04:00</ValidTime>";
> $kml_string = $kml_string . "    <MaxTemp>89</MaxTemp>";
> $kml_string = $kml_string . "  </NdfdData>";
> $kml_string = $kml_string . "</Document>";
> $kml_string = $kml_string . "</kml>";
>
> $descriptorAssignments = array(
>    0 => array("pipe", "r"),  // stdin is a pipe that the child will read
> from
>    1 => array("pipe", "w"),  // stdout is a pipe that the child will
> write to
>    2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file
> to write to
> );
>
> $kmz_process = proc_open('zip',$descriptorAssignments,$pipes);
>
> if (is_resource($kmz_process))
> {
>    fwrite($pipes[0],$kml_string);
>    fclose($pipes[0]);
>
>    $kmz_content = stream_get_contents($pipes[1]);
>
>    fclose($pipes[1]);
>
>    $return_value = proc_close($kmz_process);
>
>    //  Only outputting data to ensure it is a properly formatted zip file
>    //  Normally, a SOAP service will sent the data as a base64 encoded
> payload
>    $output_file = fopen('ndfdViaPipe.kmz','w');
>    fwrite($output_file,$kmz_content);
>    fclose($output_file);
> }
>
> ?>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Graham

--- End Message ---
--- Begin Message ---
Can't help with your main problem, however I find it easier to write
the likes of :

$kml_string = <<<STOP
all of
the soap
maybe some water
some chips if you have them
STOP

On 9/7/07, John Schattel <[EMAIL PROTECTED]> wrote:
> Hello All,
>
> I am trying to zip data in a PHP program using the following code.  The
> resulting file (ndfdViaPipe.kmz) is zip'ed but the data in the archive
> lacks a file name.  So when a program like Google Earth tries to process
> the file, it fails.  When I bring ndfdViaPipe.kmz into WinZip, the file
> has no name but can otherwise be extracted just fine.  Once extracted,
> Google Earth can process the file.  Does anyone know how I might add the
> "file name" information to the ndfdViaPipe.kmz?  The reason I'm trying
> to use pipes is to avoid creating a file with the dynamically created
> data in $kml_string.  The plan is to send $kmz_content out in a SOAP
> service message with the payload as base64 encoded file.  If there is a
> better way to accomplish this I am certainly open to suggestions.
>
> In advance, thanks for any help you care to offer.
>
> John
>
> <?php
>
> $kml_string = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
> $kml_string = $kml_string . "<kml
> xmlns=\"http://earth.google.com/kml/2.1\";>";
> $kml_string = $kml_string . "<Document>";
> $kml_string = $kml_string . "   <name>National Digital Forecast Database
> Data</name>";
> $kml_string = $kml_string . "   <open>1</open>";
> $kml_string = $kml_string . "  <Schema parent=\"Placemark\"
> name=\"NdfdData\">";
> $kml_string = $kml_string . "    <SimpleField type=\"wstring\"
> name=\"UOM\"></SimpleField>";
> $kml_string = $kml_string . "    <SimpleField type=\"wstring\"
> name=\"ValidTime\"></SimpleField>";
> $kml_string = $kml_string . "    <SimpleField type=\"int\"
> name=\"MaxTemp\"></SimpleField>";
> $kml_string = $kml_string . "  </Schema>";
> $kml_string = $kml_string . "  <NdfdData>";
> $kml_string = $kml_string . "    <name>Maximum Temperature</name>";
> $kml_string = $kml_string . "    <description>90F valid at
> 2007-06-26T00:00:00-04:00</description>";
> $kml_string = $kml_string . "    <Point>";
> $kml_string = $kml_string . "      <coordinates>-77.37,37.82</coordinates>";
> $kml_string = $kml_string . "    </Point>";
> $kml_string = $kml_string . "    <UOM>F</UOM>";
> $kml_string = $kml_string . "
> <ValidTime>2007-06-26T00:00:00-04:00</ValidTime>";
> $kml_string = $kml_string . "    <MaxTemp>95</MaxTemp>";
> $kml_string = $kml_string . "  </NdfdData>";
> $kml_string = $kml_string . "  <NdfdData>";
> $kml_string = $kml_string . "    <name>Maximum Temperature</name>";
> $kml_string = $kml_string . "    <description>89F valid at
> 2007-06-26T00:00:00-04:00</description>";
> $kml_string = $kml_string . "    <Point>";
> $kml_string = $kml_string . "      <coordinates>-77.5,38.00</coordinates>";
> $kml_string = $kml_string . "    </Point>";
> $kml_string = $kml_string . "    <UOM>F</UOM>";
> $kml_string = $kml_string . "
> <ValidTime>2007-06-26T00:00:00-04:00</ValidTime>";
> $kml_string = $kml_string . "    <MaxTemp>89</MaxTemp>";
> $kml_string = $kml_string . "  </NdfdData>";
> $kml_string = $kml_string . "</Document>";
> $kml_string = $kml_string . "</kml>";
>
> $descriptorAssignments = array(
>    0 => array("pipe", "r"),  // stdin is a pipe that the child will read
> from
>    1 => array("pipe", "w"),  // stdout is a pipe that the child will
> write to
>    2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file
> to write to
> );
>
> $kmz_process = proc_open('zip',$descriptorAssignments,$pipes);
>
> if (is_resource($kmz_process))
> {
>    fwrite($pipes[0],$kml_string);
>    fclose($pipes[0]);
>
>    $kmz_content = stream_get_contents($pipes[1]);
>
>    fclose($pipes[1]);
>
>    $return_value = proc_close($kmz_process);
>
>    //  Only outputting data to ensure it is a properly formatted zip file
>    //  Normally, a SOAP service will sent the data as a base64 encoded
> payload
>    $output_file = fopen('ndfdViaPipe.kmz','w');
>    fwrite($output_file,$kmz_content);
>    fclose($output_file);
> }
>
> ?>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
I was wondering if anyone knew of some php code that I could use to create
thumbnails of webpages.

--- End Message ---
--- Begin Message ---
This one time, at band camp, "Ramesh.b" <[EMAIL PROTECTED]> wrote:

> Hello,
> 
> Any opensource or PHP applicaiton is available for Photo upload tool?.

http://phpro.org/examples/Multiple-file-upload.html

Kevin


-- 
"Democracy is two wolves and a lamb voting on what to have for lunch. 
Liberty is a well-armed lamb contesting the vote."

--- End Message ---
--- Begin Message ---
Thanks Jay,

I want a client side tool , something similar to Yahoo photos or flickr,
where it will shrink the size of the image and upload.

Thanks
Ramesh
""Jay Blanchard"" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
[snip]
Any opensource or PHP applicaiton is available for Photo upload tool?.
[/snip]

Easy to do yourself....
http://us2.php.net/manual/en/features.file-upload.php

--- End Message ---
--- Begin Message ---
Hi

I am looking at converting a large project from ASP to PHP, and have read 
that there is no equivalent of global.asa in PHP. It is probably easiest if 
I describe the problem starting with how the ASP does it:

Project uses global.asa to load a lot of 'global' constants and variables 
into memory. This includes translations for the web site in a number of 
different languages. These are loaded from text files so that changing them 
is easy. These items when loaded in global.asa are as if they are in an 
associative array which is available to the whole application - it is not 
destroyed when the page is destroyed!

Any ideas how I could handle this in PHP? The ASP method seems sensible, as 
the data is much too big to load for every page, and too common to load only 
when required. Holding it in memory and it having application wide scope 
like this is fast. Loading only parts required at execution from, say, a 
database would surely be too costly in db calls?

Anyone have any ideas about what I could do?

Many thanks, David

--- End Message ---
--- Begin Message ---
Hi David,
 I'd say your best bet is to use memcached. This will allow the
variables you specified to stay in memory, and be accessible to all
other applications.

http://www.danga.com/memcached/

Keep in mind though, just because ASP does it in one way, you don't want
to do a bit for bit copy. You could also look into options like the
auto_prepend feature in php.ini, and the define() function.

http://us2.php.net/define

I personally don't like using the auto_prepend feature, but it's there
and you could use it if you like, I'm a fan of implicitly requiring
files if I need to.

If your associative array, is really that large that it's going to slow
things down, you may also want to consider whether all your scripts need
all of the data, and then possibly define things that are only necessary
for certain classes, in the file for that class.

You can also serialize your associative array, and store it in the
database.. but it's really all dependant on what you need, and what the
app needs.



david wrote:
> Hi
>
> I am looking at converting a large project from ASP to PHP, and have read 
> that there is no equivalent of global.asa in PHP. It is probably easiest if 
> I describe the problem starting with how the ASP does it:
>
> Project uses global.asa to load a lot of 'global' constants and variables 
> into memory. This includes translations for the web site in a number of 
> different languages. These are loaded from text files so that changing them 
> is easy. These items when loaded in global.asa are as if they are in an 
> associative array which is available to the whole application - it is not 
> destroyed when the page is destroyed!
>
> Any ideas how I could handle this in PHP? The ASP method seems sensible, as 
> the data is much too big to load for every page, and too common to load only 
> when required. Holding it in memory and it having application wide scope 
> like this is fast. Loading only parts required at execution from, say, a 
> database would surely be too costly in db calls?
>
> Anyone have any ideas about what I could do?
>
> Many thanks, David
>
>   

--- End Message ---
--- Begin Message ---
Hello,

on 09/06/2007 07:42 AM Diana Castillo said the following:
> 
> 
>     when I try to send mail using this code:
> 
>     mail("[EMAIL PROTECTED]","TEST MAIL","TESTING MAIL");
> 
>     I get this error:
> 
> 
>     Warning: mail() [function.mail]: SMTP server response: 554 
>     <[EMAIL PROTECTED]>: Recipient address rejected: Access denied in 
>     C:\Inetpub\wwwroot\intranet\test.php on line 4
> 
>     my settings in php.ini are
>     SMTP = "smtp.tsanalytics.com"
>     smtp_port = 25 

That means you need to authenticate to relay messages through that SMTP
server.

PHP mail() function does not support SMTP authentication.

You can try using the smtp_mail() function from this package that
emulates the mail function and supports authentication. Take a look at
the test_smtp_mail.php script:

http://www.phpclasses.org/mimemessage

You also need these other classes to perform authentication through SMTP:

http://www.phpclasses.org/smtpclass

http://www.phpclasses.org/sasl

-- 

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

--- End Message ---
--- Begin Message ---
I've to implement a php script in a web page to send mail.
If I use a .html form and a separate .php script, all works fine.
In the contrary, if I try to put the script into the .html file,
I've some troubles... Here's the code:

======================================================================
<?php
?>
<xml version="1.0" encoding="utf-8">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";><html
xmlns="http://www.w3.org/1999/xhtml";>

<head>
<meta name="generator" content="Quanta Plus" >
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>B#038;B #171;LA LOCANDA DI RE MANFREDI#187; - PALAZZO SAN
GERVASIO (PZ)</title>
<meta name="description" content="Ora c'#232; un Bed#038;Breakfast
anche
a Palazzo San Gervasio (PZ)" >
<meta name="keywords" content="b#038;b,bed#038;breakfast, Palazzo San
Gervasio, Potenza, Basilicata, Lucania" >
<link rel="stylesheet" type="text/css" href="layout.css" >
</head>
<body>

<ul class="navbar">
<li><a href="index.html">Home Page</a></li>
<li><a href="bed.html">Il nostro Bed#038;Breakfast</a></li>
<li><a href="paese.html">Il paese</a></li>
<li><a href="storia.html">La storia</a></li>
<li><a href="tradizioni.html">Le tradizioni</a></li>
<li><a href="indirizzi.html">Indirizzi utili</a></li>
</ul>

<h2>#200; possibile inviarci una comunicazione direttamente da questo
form</h1>
<h2>Riempire i campi richiesti e premere il pulsante "Invia"</h2>
<br /><br />

<?
if (isset($_POST['action']) && ($_POST['action']=='invia')) {
$receiverMail = "[EMAIL PROTECTED]";
$name = ltrim(rtrim(strip_tags(stripslashes($_POST['name']))));
$email = ltrim(rtrim(strip_tags(stripslashes($_POST['email']))));
$subject = ltrim(rtrim(strip_tags(stripslashes($_POST['subject']))));
$msg = ltrim(rtrim(strip_tags($_POST['msg'])));
$ip = getenv("REMOTE_ADDR");
$msgformat = "Messaggio da: $name ($ip)\nEmail: $email\n\n$msg";
if(empty($name) || empty($email) || empty($subject) || empty($msg)) {
echo "<h3>Il messaggio non e' stato inviato</h3>
<h3>Si prega di compilare tutti i campi</h3";
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Nome:<br ><br >
<input name="name" size="50" maxlength="40" >
<br ><br/><br >
Indirizzo e-mail:<br /><br />
<input name="email" size="50" maxlength="40" >
<br ><br ><br >
Oggetto:<br ><br >
<input name="subject" size="50" maxlength="40" >
<br ><br ><br >
Messaggio:<br ><br >
<textarea name="msg" cols="50" rows="8"></textarea>
<br ><br ><br >
<input type="submit" value="Invia" >
#160; #160; #160; #160; #160; #160;
<input type="reset" value="Cancella" >
</form>
<?
}

elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)[EMAIL PROTECTED](\.[a-z0-9-]+)*(\.[a-z
{2,3})$", $email)) {
echo "<h3>Il messaggio non e' stato inviato</h3>
<h3>L'indirizzo e-mail indicato non e' valido</h3>";
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Nome:<br /><br />
<input name="name" size="50" maxlength="40" value=?> echo $name. <?">
<br /><br /><br />
Indirizzo e-mail:<br /><br />
<input name="email" size="50" maxlength="40" value="wrong!" >
<br /><br /><br />
Oggetto:<br /><br />
<input name="subject" size="50" maxlength="40" value="?>echo $subject;<?>
<br /><br /><br />
Messaggio:<br /><br />
<textarea name="msg" cols="50" rows="8">?> echo $message;<?</textarea>
<br /><br /><br />
<input type="submit" value="Invia" >> #160; #160; #160; #160;
#160; #160;
<input type="reset" value="Cancella" >
</form>
<?
}
else {
mail($receiverMail, $subject, $msgformat, "From: $name <$email>");
echo "<h3>Il messaggio e' stato inviato correttamente<h3>
<h3>Risponderemo il piu' presto possibile</h3>
<h3>Grazie di averci scritto</h3>"; }

}
?>
</body>
</html>
======================================================================

When I try to open the page, I receive this error:

Parse error: syntax error, unexpected T_STRING 
in /var/www/netsons.org/samiel/form2.php on line 79

Do u see my error?
Thanx!
MS



-- 
linux user no.: 353546
public key at http://keyserver.linux.it

--- End Message ---
--- Begin Message ---
Mauro Sacchetto wrote:
I've to implement a php script in a web page to send mail.
If I use a .html form and a separate .php script, all works fine.
In the contrary, if I try to put the script into the .html file,
I've some troubles... Here's the code:

...

When I try to open the page, I receive this error:

Parse error: syntax error, unexpected T_STRING in /var/www/netsons.org/samiel/form2.php on line 79

Do u see my error?

{Copies, pastes into editor that will number the lines ...}

Well, looking in the vicinity of line 79, i'd say the problem lies with your reversed PHP tags:

<input name="name" size="50" maxlength="40" value=?> echo $name. <?">

You've got another right below that:

<input name="subject" size="50" maxlength="40" value="?>echo $subject;<?>

And another:

<textarea name="msg" cols="50" rows="8">?> echo $message;<?</textarea>

Some other points:

- You can do without the "echo" by using, eg. <?= $message ?>

- Because this is an XHTML page, you should be closing your input tags and properly quoting the attributes: value="<?= $name ?>" />

- That your script's purpose is to send mail has nothing to do with how it displays in a browser.

Anyway, that should do it. Be sure to validate the page.

brian

--- End Message ---
--- Begin Message ---
Mike,

Thanks for the reply and your very useful notes.

I'm unable to workout how to get the same IV as the one generated by the PHP
script is random. The thing is that we cant change the PHP script as its
readily being used now. Maybe I should look at the encryption routine and
reverse that first?

Thanks,
Sym


mike-22 wrote:
> 
> I've done it in reverse - something encrypted in .NET and then decrypted
> in PHP
> 
> these were my notes...
> 
> 
> To get .NET and PHP to play friendly with two-way encryption, you need
> to make sure some things happen in both:
> In .NET:
> 1) You need to set the Padding to PaddingMode.Zeros, i.e.:
>  Rijndael alg = Rijndael.Create();
>  alg.Padding = PaddingMode.Zeros;
> 2) You also need to make sure to use System.Text.Encoding.ASCII or
> System.Text.Encoding.UTF8; System.Text.Encoding.Unicode will *not*
> work (perhaps in PHP6 this might be possible.)
> 3) Need to make sure the IV and key are the same as defined in PHP.
> 
> In PHP:
> 1) You need the mcrypt extension installed.
> 2) Need to make sure the IV and key are the same as defined in .NET.
> 3) You can issue this single line of code to decrypt:
>  mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $encrypted_text, "cbc", $iv);
> 
> Notes:
> 1) By default .NET uses a 128-bit cipher in CBC mode when you
> initialize Rijndael. That might not be common knowledge.
> 2) If you're sending this data via a URL or cookie or something else,
> be sure to base64 encode on the .NET side, and base64_decode() the
> data on the PHP side.
> 
> 
> below i would say that:
> 
> a) you need to make sure the IV is the same. right now it looks like
> you are creating a random one in PHP and a different one in .NET. that
> would be my first thing to check.
> 
> b) not sure if ECB vs. CBC is any different; i know CBC will work though.
> 
> hope that helps some. it took some debugging for us, and it didn't
> help that our .NET guy created the IV using low and high ascii
> character codes that I had to reproduce in PHP for the IV and the
> key... I would get different sizes as well, but once the stars aligned
> it worked perfectly. Be sure that any base64 encoding/decoding or
> anything like that is done in the proper order (typically start out
> with no encoding, get it to work, then add on encoding and decoding on
> both ends properly, etc.)
> 
> good luck :)
> 

-- 
View this message in context: 
http://www.nabble.com/Converting-PHP-code-to-C---tf4397727.html#a12565713
Sent from the PHP - General mailing list archive at Nabble.com.

--- End Message ---
--- Begin Message ---
On 9/7/07, Symbian <[EMAIL PROTECTED]> wrote:
>
> I'm unable to workout how to get the same IV as the one generated by the PHP
> script is random. The thing is that we cant change the PHP script as its
> readily being used now. Maybe I should look at the encryption routine and
> reverse that first?

just hard code the IV in both places.

to make it difficult you can do something like this (basically our
.NET guy took it from
http://www.codeproject.com/dotnet/DotNetCrypto.asp)

public static string Encrypt(string clearText, string Password)
    {
        // First we need to turn the input string into a byte array.
        byte[] clearBytes =
          System.Text.Encoding.UTF8.GetBytes(clearText);

PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password,
            new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
            0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});

 byte[] encryptedData = Encrypt(clearBytes,
                 pdb.GetBytes(32), pdb.GetBytes(16));

   return Convert.ToBase64String(encryptedData);

}

(make sure to copy that first Encrypt method and set alg.Padding =
PaddingMode.Zeros)

and on PHP side (the IV/key numbers have been changed to protect the
innocent :))

i believe the numbers are the decimal values of the .NET 0x49 etc. you
need 32 of them for the key, and 16 for the IV (to match the
parameters above) - these numbers do not match right now i just
jumbled them up. i would first see if you can use my code to properly
encrypt in .NET and decrypt in PHP. then hopefully you can just
reverse it.

what i should do is actually publish an example with working
instructions + numbers. i'll keep this email around and publish an
article on my blog or something hopefully soon.

function decrypt($text, $key) {
        $enc_key_array = Array(24,91,81,138,122,etc);
        $chrs = "";
        foreach(array_values($enc_key_array) as $chr) {
                $chrs .= chr($chr);
        }
        $enc_key = $chrs;
        $enc_iv_array = Array(35,56,103,81,77,etc);
        $chrs = "";
        foreach(array_values($enc_iv_array) as $chr) {
                $chrs .= chr($chr);
        }
        $enc_iv = $chrs;
        $text = base64_decode($text);
        $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $enc_key,
$text, "cbc", $enc_iv);
        return $decrypted."\n";
}

remember to base64 encode/decode at the proper times. we use this to
encrypt information in a cookie so it needs to be encoded for transit.
it also helps when you are copy/pasting it back and forth to test
encrypt/decrypt :)

--- End Message ---

Reply via email to