Newsgroup: it.comp.www.php
Titolo: asp.net to PHP

Hello,
I have a small web app in C# (Default.aspx, Default.aspx.cs)
and one of my clients demands a PHP version.
I have no prior experience in PHP coding
so if anyone could help translate this two
small files, I would be very gratefull.
Kind regards,
Ivan
aspx file and the code behind are here:
---------------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" 
CodeBehind="Default.aspx.cs" Inherits="WebPages.Default" %>
<!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 runat="server">
    <title>0001</title>
</head>
<body>
    <form id="form1" runat="server">
        &nbsp;<table border="0" style="position: static; width: 385px; 
height: 403px;" align="center">
            <tr>
                <td style="width: 484px; height: 555px;">
 
        <asp:Label ID="lblBegin" runat="server" Style="position: 
static;" Text="0006" Font-Bold="True" Font-Italic="True" Font-
Names="Arial" Font-Size="10pt" Font-Strikeout="False" Font-
Underline="False" ForeColor="#C0C000" Width="340px"></asp:Label><br />
                    <br />
        <asp:Label ID="lblName" runat="server" Height="3px" 
Style="position: static;" Text="Your Name:" Font-Bold="True" Font-
Italic="True" Font-Names="Arial" Font-Size="10pt" Font-Strikeout="False" 
Font-Underline="False" ForeColor="#C0C000"></asp:Label>
        <asp:TextBox ID="txtName" runat="server" Style="position: 
static;" Width="166px"></asp:TextBox><br />
                    <br />
        <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-
Names="Arial" Font-Size="10pt"
            ForeColor="#C0C000" Style="position: static" Text="Your 
Email:"></asp:Label>&nbsp;
                    <asp:TextBox ID="TextBox20" runat="server" 
Style="position: static" Width="164px" TabIndex="1"></asp:TextBox><br />
                    <br />
        <asp:Label ID="lblMessage" runat="server" Style="position: 
static;" Text="Message:" Font-Bold="True" Font-Italic="True" Font-
Names="Arial" Font-Size="10pt" Font-Strikeout="False" Font-
Underline="False" ForeColor="#C0C000"></asp:Label><br />
                    <br />
                    <asp:TextBox ID="txtBody" runat="server" 
Style="position: static;" TabIndex="2" Width="337px" Enabled="False">0007
</asp:TextBox><br />
                    <br />
 
        <asp:Label ID="lblPleaseEnter" runat="server" Style="position: 
static;" Font-Bold="True" Font-Italic="True" Font-Names="Arial" Font-
Size="10pt" Font-Strikeout="False" Font-Underline="False" 
ForeColor="#C0C000" Width="308px"></asp:Label><br />
                    <br />
                    <asp:Label ID="Label2" runat="server" Font-
Bold="True" Font-Names="Arial" Font-Size="10pt"
            ForeColor="#C0C000" Style="position: static" Text="Friend's 
Name:"></asp:Label>
                    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                    <asp:Label ID="Label3" runat="server" Font-
Bold="True" Font-Names="Arial" Font-Size="10pt"
            ForeColor="#C0C000" Style="position: static" Text="Friend's 
Email address:"></asp:Label><br />
                    <asp:TextBox ID="TextBox10" runat="server" 
Style="position: static" Visible="False" TabIndex="3" Width="148px">
</asp:TextBox>
                    <asp:TextBox ID="TextBox0" runat="server" 
Style="position: static;" Width="180px" TabIndex="3" Visible="False">
</asp:TextBox><br />
                    <asp:TextBox ID="TextBox11" runat="server" 
Style="position: static" Visible="False" TabIndex="3" Width="148px">
</asp:TextBox>
                    <asp:TextBox ID="TextBox1" runat="server" 
Style="position: static;" TabIndex="3" Width="180px" Visible="False">
</asp:TextBox><br />
                    <asp:TextBox ID="TextBox12" runat="server" 
Style="position: static" Visible="False" TabIndex="3" Width="148px">
</asp:TextBox>
                    <asp:TextBox ID="TextBox2" runat="server" 
Style="position: static;" TabIndex="3" Width="180px" Visible="False">
</asp:TextBox><br />
                    <asp:TextBox ID="TextBox13" runat="server" 
Style="position: static" Visible="False" TabIndex="3" Width="148px">
</asp:TextBox>
                    <asp:TextBox ID="TextBox3" runat="server" 
Style="position: static;" TabIndex="3" Width="180px" Visible="False">
</asp:TextBox><br />
                    <asp:TextBox ID="TextBox14" runat="server" 
Style="position: static" Visible="False" TabIndex="3" Width="148px">
</asp:TextBox>
                    <asp:TextBox ID="TextBox4" runat="server" 
Style="position: static;" TabIndex="3" Width="180px" Visible="False">
</asp:TextBox><br />
                    <asp:TextBox ID="TextBox15" runat="server" 
Style="position: static" Visible="False" TabIndex="3" Width="148px">
</asp:TextBox>
                    <asp:TextBox ID="TextBox5" runat="server" 
Style="position: static;" TabIndex="3" Width="180px" Visible="False">
</asp:TextBox><br />
                    <asp:TextBox ID="TextBox16" runat="server" 
Style="position: static" Visible="False" TabIndex="3" Width="148px">
</asp:TextBox>
                    <asp:TextBox ID="TextBox6" runat="server" 
Style="position: static;" TabIndex="3" Width="180px" Visible="False">
</asp:TextBox><br />
                    <asp:TextBox ID="TextBox17" runat="server" 
Style="position: static" Visible="False" TabIndex="3" Width="148px">
</asp:TextBox>
                    <asp:TextBox ID="TextBox7" runat="server" 
Style="position: static;" TabIndex="3" Width="180px" Visible="False">
</asp:TextBox><br />
        <asp:TextBox ID="TextBox18" runat="server" Style="position: 
static" Visible="False" TabIndex="3" Width="148px"></asp:TextBox>
                    <asp:TextBox ID="TextBox8" runat="server" 
Style="position: static;" TabIndex="3" Width="180px" Visible="False">
</asp:TextBox><br />
        <asp:TextBox ID="TextBox19" runat="server" Style="position: 
static" Visible="False" TabIndex="3" Width="148px"></asp:TextBox>
                    <asp:TextBox ID="TextBox9" runat="server" 
Style="position: static;" TabIndex="3" Width="180px" Visible="False">
</asp:TextBox><br />
                    <br />
 
        <asp:Label ID="lblEnd" runat="server" Style="position: static;" 
Text="0008" Width="344px" Font-Bold="True" Font-Italic="True" Font-
Names="Arial" Font-Size="10pt" Font-Strikeout="False" Font-
Underline="False" ForeColor="#C0C000"></asp:Label><br />
                    <br />
                    <asp:CheckBox Visible="true" ID="chkSpam" 
runat="server" Height="19px" Style="position: static;" Text="0009" 
TabIndex="4" Width="344px" Font-Bold="True" Font-Italic="True" Font-
Names="Arial" Font-Size="10pt" Font-Strikeout="False" Font-
Underline="False" ForeColor="#C0C000" /><br />
                    <br />
 
                    <asp:Button ID="Button1" runat="server" 
OnClick="Button1_Click" Style="position: static;" Text="Send" 
Width="116px" TabIndex="5" />&nbsp;
                    <asp:Button ID="btnClear" runat="server" 
OnClick="btnClear_Click" Style="position: static;" Text="Clear" 
TabIndex="6" Width="51px" /></td>
            </tr>
        </table>
        <asp:HiddenField ID="txtCodedString2" runat="server" 
Value="0003" />
 
        <asp:Label ID="lblMin" runat="server" Style="left: 190px; 
position: static; top: -37px" Text="0004" Visible="False"></asp:Label>
                <asp:Label ID="lblMax" runat="server" Style="left: 190px; 
position: static; top: -37px" Text="0005" Visible="False"></asp:Label>
        <asp:HiddenField ID="txtCodedString" runat="server" 
Value="0002" />
        <br />
 
 
    </form>
</body>
</html>
---------------------------------------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Net.Mail;
namespace WebPages
{
    public partial class Default : 
System.Web.UI.Page
    {
        ArrayList lstEmails = new ArrayList();
        ArrayList lstNames = new ArrayList();
        protected void Page_Load(object sender, EventArgs e)
        {
            txtName.Focus();
            lblPleaseEnter.Text = "Please enter at least " + lblMin.Text 
+ " friend's Email addresses:";
            lstEmails.Add(TextBox0);
            lstEmails.Add(TextBox1);
            lstEmails.Add(TextBox2);
            lstEmails.Add(TextBox3);
            lstEmails.Add(TextBox4);
            lstEmails.Add(TextBox5);
            lstEmails.Add(TextBox6);
            lstEmails.Add(TextBox7);
            lstEmails.Add(TextBox8);
            lstEmails.Add(TextBox9);
            lstNames.Add(TextBox10);
            lstNames.Add(TextBox11);
            lstNames.Add(TextBox12);
            lstNames.Add(TextBox13);
            lstNames.Add(TextBox14);
            lstNames.Add(TextBox15);
            lstNames.Add(TextBox16);
            lstNames.Add(TextBox17);
            lstNames.Add(TextBox18);
            lstNames.Add(TextBox19);
            for (int i = 0; i < int.Parse(lblMax.Text); i++)
            {
                ((TextBox)lstEmails[i]).Visible = true;
                ((TextBox)lstNames[i]).Visible = true;
            }
            lblPleaseEnter.Text = "Please invite at least " + lblMin.Text 
+ " of your friends";
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            if ((txtName.Text.Trim() == "") || (TextBox20.Text.Trim() == 
""))
            {
                Response.Write("<script>alert('Please enter your name and 
email address!');</script>");
                txtName.Focus();
            }
            else
            {
                ArrayList enteredEmails = new ArrayList();
                for (int i = 0; i < int.Parse(lblMax.Text); i++)
                {
                    if (((TextBox)lstEmails[i]).Text.Trim() != "")
                    {
                        if (!enteredEmails.Contains(((TextBox)lstEmails
[i]).Text.Trim()))
                        {
                            if (((TextBox)lstNames[i]).Text.Trim() == "")
                            {
                                Response.Write("<script>alert('Please add 
names with email addresses!');</script>");
                                return;
                            }
                            else
                                enteredEmails.Add(((TextBox)lstEmails
[i]).Text.Trim());
                        }
                        else
                        {
                            if (lblMin.Text == "1")
                            {
                                Response.Write("<script>alert('Please add 
at least 1 email address without repeating!');</script>");
                                return;
                            }
                            else
                            {
                                Response.Write("<script>alert('Please add 
at least " + lblMin.Text + " different email addresses!');</script>");
                                return;
                            }
                        }
                    }
                }
                if (enteredEmails.Count < int.Parse(lblMin.Text))
                {
                    if (lblMin.Text == "1")
                    {
                        Response.Write("<script>alert('Please add at 
least one name and email address without repeating!');</script>");
                        return;
                    }
                    else
                    {
                        Response.Write("<script>alert('Please add at 
least " + lblMin.Text + " different names and email addresses!');
</script>");
                        return;
                    }
                }
                else
                {
                    string[] txtEmails = new string[enteredEmails.Count];
                    for (int i = 0; i < enteredEmails.Count; i++)
                        txtEmails[i] = enteredEmails[i].ToString();
                    if (chkSpam.Visible)
                    {
                        if (chkSpam.Checked)
                        {
                            string strReturn = SendInvitations
(txtName.Text, txtBody.Text, txtEmails, txtCodedString.Value, lstNames);
                            if (strReturn == "")
                                if (decodeThankYou(txtCodedString2.Value)
[enteredEmails.Count - int.Parse(lblMin.Text)].ToString().Substring(0,4) 
== "http")
                                    Response.Redirect(decodeThankYou
(txtCodedString2.Value)[enteredEmails.Count - int.Parse
(lblMin.Text)].ToString());
                                else
                                    try
                                    {
                                        Server.Transfer(decodeThankYou
(txtCodedString2.Value)[enteredEmails.Count - int.Parse
(lblMin.Text)].ToString());
                                    }
                                    catch
                                    { }
                            else
                                Response.Write("<script>alert
('"+strReturn+"');</script>");
                        }
                        else
                        {
                            Response.Write("<script>alert('Please confirm 
that you are not using this for spam!');</script>");
                        }
                    }
                    else
                    {
                        string strReturn = SendInvitations(txtName.Text, 
txtBody.Text, txtEmails, txtCodedString.Value, lstNames);
                        if (strReturn == "")
                            if (decodeThankYou(txtCodedString2.Value)
[enteredEmails.Count - int.Parse(lblMin.Text)].ToString().Substring(0, 4) 
== "http")
                                Response.Redirect(decodeThankYou
(txtCodedString2.Value)[enteredEmails.Count - int.Parse
(lblMin.Text)].ToString());
                            else
                                Server.Transfer(decodeThankYou
(txtCodedString2.Value)[enteredEmails.Count - int.Parse
(lblMin.Text)].ToString());
                        else
                            Response.Write("<script>alert('" + strReturn 
+ "');</script>");
                    }
                }
            }
        }
        protected void btnClear_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < int.Parse(lblMax.Text); i++)
                ((TextBox)lstEmails[i]).Text = "";
        }
        private string SendInvitations(string name, string body, string[] 
emails, string codedString, ArrayList friend)
        {
            try
            {
                DecodeData dd = decode(codedString);
                SmtpClient sc;
                if (dd.smtp == "default")
                    sc = new SmtpClient();
                else
                    sc = new SmtpClient(dd.smtp, dd.port);
                if (dd.authUser != "")
                {
                    sc.UseDefaultCredentials = false;
                    sc.Credentials = new NetworkCredential(dd.authUser, 
dd.authPass);
                }
                try
                {
                    for (int i = 0; i < emails.Length; i++)
                    {
                        if (dd.sender == "Visitor")
                            dd.sender = TextBox20.Text;
                        sc.Send(dd.sender, emails[i], dd.subject.Replace
("#VISITORNAME", name).Replace("#FRIENDNAME", ((TextBox)friend[i]).Text), 
body);
                        if (dd.referral)
                            sc.Send(dd.sender, dd.email, "Tell A Friend 
referral report", "Email sent form " + name +" ("+ TextBox20.Text+") to 
" + ((TextBox)friend[i]).Text +" (" + emails[i] + ")\n\nSubject:\r\n" + 
dd.subject.Replace("#VISITORNAME", name).Replace("#FRIENDNAME", 
((TextBox)friend[i]).Text) + "\r\n\r\n" + "Body:\r\n" + body);
                    }
                    return "";
                }
                catch
                {
                    return "Server error. Please check if all the 
addresses really exist.";
                }
            }
            catch
            {
                return "Server error. Please try again later.";
            }
        }
        private DecodeData decode(string codedString)
        {
            DecodeData dd = new DecodeData();
            dd.sender = codedString.Substring(0, codedString.IndexOf
("###"));
            codedString = codedString.Substring(codedString.IndexOf
("###") + 3);
            dd.subject = codedString.Substring(0, codedString.IndexOf
("###"));
            codedString = codedString.Substring(codedString.IndexOf
("###") + 3);
            if (codedString.Substring(0, codedString.IndexOf("###")) == 
"true")
                dd.referral = true;
            else
                dd.referral = false;
            codedString = codedString.Substring(codedString.IndexOf
("###") + 3);
            dd.smtp = codedString.Substring(0, codedString.IndexOf
("###"));
            codedString = codedString.Substring(codedString.IndexOf
("###") + 3);
            dd.port = int.Parse(codedString.Substring(0, 
codedString.IndexOf("###")));
            codedString = codedString.Substring(codedString.IndexOf
("###") + 3);
            if (codedString.IndexOf("###") == -1)
            {
                dd.email = codedString.Substring(0);
                dd.authUser = "";
                dd.authPass = "";
            }
            else
            {
                dd.email = codedString.Substring(0, codedString.IndexOf
("###"));
                codedString = codedString.Substring(codedString.IndexOf
("###") + 3);
                dd.authUser = codedString.Substring(0, 
codedString.IndexOf("###"));
                codedString = codedString.Substring(codedString.IndexOf
("###") + 3);
                dd.authPass = codedString.Substring(0);
            }
            return dd;
        }
        private ArrayList decodeThankYou(string codedString)
        {
            ArrayList al = new ArrayList(int.Parse(lblMax.Text) - 
int.Parse(lblMin.Text) + 1);
            for (int i = 0; i < int.Parse(lblMax.Text) - int.Parse
(lblMin.Text) + 1; i++)
            {
                al.Add(codedString.Substring(0, codedString.IndexOf
("###")));
                codedString = codedString.Substring(codedString.IndexOf
("###") + 3);
            }
            return al;
        }
        protected void txtName_TextChanged(object sender, EventArgs e)
        {
        }
    }
    class DecodeData
    {
        private string _sender;
        private string _subject;
        private bool _referral;
        private string _smtp;
        private int _port;
        private string _email;
        private string _authUser;
        private string _authPass;
        public string sender
        {
            get { return _sender; }
            set { _sender = value; }
        }
        public string subject
        {
            get { return _subject; }
            set { _subject = value; }
        }
        public bool referral
        {
            get { return _referral; }
            set { _referral = value; }
        }
        public string smtp
        {
            get { return _smtp; }
            set { _smtp = value; }
        }
        public int port
        {
            get { return _port; }
            set { _port = value; }
        }
        public string email
        {
            get { return _email; }
            set { _email = value; }
        }
        public string authUser
        {
            get { return _authUser; }
            set { _authUser = value; }
        }
        public string authPass
        {
            get { return _authPass; }
            set { _authPass = value; }
        }
    }
}

 small files, I would be very gratefull.
If you have it as visiaulbasic, then you can use asp2php, it will do the 
  starter work, then you have to do some adjustments as the tool ain't 
100% fool proof.
-- 
   //Aho

 100% fool proof.
I am avare of asp2php.
Maybe I will translate it to VB and then to PHP.