Archive for February, 2008
Java Software Development Services
Palak Bhatt asked:
Java is a programming language and this language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to byte code that can run on any Java virtual machine (JVM) regardless of computer architecture whereas Radix is not lagged behind for this language implementation to the related fields. Services of Radix in Java consulting and software development are outstanding to suffice multipurpose needs of its clients. Radix provides outsourcing service with full support at every stage of projects from architecture to implementation. Java technology has been developed at Radix in an outstanding fashion where the expert professionals can produce concerned development system of problem free coding.
Java Feature at Radix
Java software has been developed at Radix for heterogeneous purpose of using active web applications. Java has been used for various application servers and web-containers.
All kinds of Java applications are developed here at Radix based on Struts/JSTL and Velocity. The usage of this kind of technological extravaganza enables avoiding excessive reliance on java-code in JSP pages and to separate business logic from the presentation level. J2ME is being used in a striking way to meet expected orientation in its development however; this platform provides a convenient and flexible environment for applications running on hand held devices such as mobile phones or PDAs.
In addition, some of extra-ordinary features in this regards are to be quoted herewith
WDSL, UDDI, SOAP, ebXML, development on J2EE-compliant application servers, including BEA WebLogic and IBM WebSphere, B2B Integration (ebXML, SOAP), Expert knowledge on Entity, Session and Message Beans, JSP & Servlets, JMS, Web services.
Key Notes of Java at Radix
Accuracy comes from matured experience and it impacts on the future technological might. Certain hazards of Java often pull back to have any forward steps. Source code of experienced professionals in Java Applications can reduce often occurred speed problem. Radix maintains the deployment issues in the final stage of project delivery that can reduce certain hurdles. Radix is in the development of all Java web applications on advanced technology of Struts/JSTL and Velocity. The usage of this technology can avoid excessive reliance on java-code in JSP pages and it can simply separate business logic from the presentation level.
If you would like to know more about Radix then visit their website: http://rndinfo.com/java-software-application-development.html You can also contact by Email – SalesATradixweb.com or Call on +1(405) 796-4103, +1(775) 890-1396.
Sue
Java is a programming language and this language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to byte code that can run on any Java virtual machine (JVM) regardless of computer architecture whereas Radix is not lagged behind for this language implementation to the related fields. Services of Radix in Java consulting and software development are outstanding to suffice multipurpose needs of its clients. Radix provides outsourcing service with full support at every stage of projects from architecture to implementation. Java technology has been developed at Radix in an outstanding fashion where the expert professionals can produce concerned development system of problem free coding.
Java Feature at Radix
Java software has been developed at Radix for heterogeneous purpose of using active web applications. Java has been used for various application servers and web-containers.
All kinds of Java applications are developed here at Radix based on Struts/JSTL and Velocity. The usage of this kind of technological extravaganza enables avoiding excessive reliance on java-code in JSP pages and to separate business logic from the presentation level. J2ME is being used in a striking way to meet expected orientation in its development however; this platform provides a convenient and flexible environment for applications running on hand held devices such as mobile phones or PDAs.
In addition, some of extra-ordinary features in this regards are to be quoted herewith
WDSL, UDDI, SOAP, ebXML, development on J2EE-compliant application servers, including BEA WebLogic and IBM WebSphere, B2B Integration (ebXML, SOAP), Expert knowledge on Entity, Session and Message Beans, JSP & Servlets, JMS, Web services.
Key Notes of Java at Radix
Accuracy comes from matured experience and it impacts on the future technological might. Certain hazards of Java often pull back to have any forward steps. Source code of experienced professionals in Java Applications can reduce often occurred speed problem. Radix maintains the deployment issues in the final stage of project delivery that can reduce certain hurdles. Radix is in the development of all Java web applications on advanced technology of Struts/JSTL and Velocity. The usage of this technology can avoid excessive reliance on java-code in JSP pages and it can simply separate business logic from the presentation level.
If you would like to know more about Radix then visit their website: http://rndinfo.com/java-software-application-development.html You can also contact by Email – SalesATradixweb.com or Call on +1(405) 796-4103, +1(775) 890-1396.
Sue
Symmetric Cryptography in Java
Debadatta Mishra asked:
Symmetric cryptography in Java
Introduction
As you know data security is a significant aspect of any enterprise application. Starting from password encryption to any data exchange, cryptography has been in use for all kinds of purpose. However there are two kinds of cryptography, one is symmetric and another is asymmetric. In case of symmetric cryptography, a secret key is used for all kinds of encryption and decryption. This secret key is shared by all the members who want to participate in the encryption and decryption process. There are several algorithms for the symmetric cryptography. DES( Data Encryption Standard) is one of them. In case of normal login screen of web based application, implementation of DES algorithm is used for password encryption.
Technicalities
Java cryptography provides suitable and flexible framework for the use of symmetric cryptography. DES algorithm is commonly known as symmetric algorithm. In case of symmetric cryptography, the secret key is used in a plain text file and this file is shared between the members. This file is used to retrieve the secret key for all kinds of encryption and decryption. In this regards I can provide you an example that think of a situation where the two lovers receive their love letters in encrypted format so that no body can read it. They have a common key called the DES secret key. They use the secret key to decrypt the contents of the encrypted love letters at their end. It means that the secret key is generated once and shared between the members. For more details of DES algorithm please refer to the java docs and JCE framework provided by Sun. In this article I will provide an example of how to use the implementation of DES algorithm.
Complete example
The following is the utility class for the cryptography management. The class name is
“KeyUtil.java”.
package com.dds.core;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
/**This is a utility class for all kinds
* of useful methods related to symmetric
* cryptography. This class only provides
* the use of DES algorithm.You can use any
* other symmetric algorithm similarly.
* @author Debadatta Mishra( PIKU )
*
*/
public class KeyUtil {
/**
* Name of the algorithm
*/
private static String algorithm = “DES”;
/**This method is used to obtain the
* Secret key as a String. It is useful
* you can store the String in a file
* for all kinds of encryption and
* decryption.
* @return the SecretKey as String
*/
public static String generateSecretKey() {
String secretKeyString = null;
try {
KeyGenerator keyGen = KeyGenerator.getInstance(algorithm);
SecretKey secretKey = keyGen.generateKey();
byte[] secretKeyBytes = secretKey.getEncoded();
secretKeyString = new sun.misc.BASE64Encoder()
.encode(secretKeyBytes);
} catch (Exception e) {
e.printStackTrace();
}
return secretKeyString;
}
/**This method is used to obtain the SecretKey
* object by passing the secret key as string.
* @param secretKeyString of type String
* @return object of {@link SecretKey}
*/
private static SecretKey getKeyInstance(String secretKeyString) {
SecretKey secretKey = null;
try {
byte[] b2 = new sun.misc.BASE64Decoder()
.decodeBuffer(secretKeyString);
secretKey = new SecretKeySpec(b2, algorithm);
} catch (Exception e) {
e.printStackTrace();
}
return secretKey;
}
/**This method is used to encrypt the same file.
* This method is useful when you are encrypting
* the contents of a file. There is no need to
* create another file with the encrypted contents.
* @param filePath of type String indicating the path of the file
* @param keyString of type String indicating the secret key
*/
public static void encryptFile(String filePath, String keyString) {
try {
SecretKey key = getKeyInstance(keyString);
Cipher ecipher = Cipher.getInstance(algorithm);
ecipher.init(Cipher.ENCRYPT_MODE, key);
InputStream in = new FileInputStream(filePath);
byte[] fileBytes = new byte[in.available()];
in.read(fileBytes);
in.close();
OutputStream out = new FileOutputStream(filePath);
out = new CipherOutputStream(out, ecipher);
out.write(fileBytes);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**This method is used to decrypt the same file.
* This method is useful when you are decrypting
* the contents of a file. There is no need to
* create another file with the decrypted contents.
* @param filePath of type String indicating the path of the file
* @param keyString of type String indicating the secret key
*/
public static void decryptFile(String filePath, String keyString) {
try {
SecretKey key = getKeyInstance(keyString);
Cipher ecipher = Cipher.getInstance(algorithm);
ecipher.init(Cipher.DECRYPT_MODE, key);
InputStream in = new FileInputStream(filePath);
byte[] fileBytes = new byte[in.available()];
in.read(fileBytes);
in.close();
OutputStream out = new FileOutputStream(filePath);
out = new CipherOutputStream(out, ecipher);
out.write(fileBytes);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**This method is used to encrypt the contents
* of a file and writing to another file. This
* method is useful when you want to maintain the
* original contents and encrypting the contents
* and giving to another person.
* @param in of type {@link InputStream}
* @param out of type {@link OutputStream}
* @param keyString of type String indicating the SecretKey
*/
public static void encryptFile(InputStream in, OutputStream out,
String keyString) {
byte[] buf = new byte[1024];
try {
SecretKey key = getKeyInstance(keyString);
Cipher ecipher = Cipher.getInstance(algorithm);
ecipher.init(Cipher.ENCRYPT_MODE, key);
// Bytes written to out will be encrypted
out = new CipherOutputStream(out, ecipher);
// Read in the cleartext bytes and write to out to encrypt
int numRead = 0;
while ((numRead = in.read(buf)) >= 0) {
out.write(buf, 0, numRead);
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**This method is used to decrypt the contents
* of a file and writing to another file. This
* method is useful when you want to decrypt
* the contents and writing to a another file.
* @param in of type {@link InputStream}
* @param out of type {@link OutputStream}
* @param keyString of type String indicating the SecretKey
*/
public static void decryptFile(InputStream in, OutputStream out,
String keyString) {
byte[] buf = new byte[1024];
try {
SecretKey key = getKeyInstance(keyString);
Cipher dcipher = Cipher.getInstance(algorithm);
dcipher.init(Cipher.DECRYPT_MODE, key);
in = new CipherInputStream(in, dcipher);
int numRead = 0;
while ((numRead = in.read(buf)) >= 0) {
out.write(buf, 0, numRead);
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**This method is used to encrypt the String.
* @param contents of type String
* @param keyString of type String indicating the Secret key as String
* @return a String encrypted contents
*/
public static String getEncryptedContents(String contents, String keyString) {
String encryptedString = null;
try {
byte[] contentBytes = contents.getBytes();
SecretKey key = getKeyInstance(keyString);
Cipher ecipher = Cipher.getInstance(algorithm);
ecipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encryptedBytes = ecipher.doFinal(contentBytes);
encryptedString = new sun.misc.BASE64Encoder()
.encode(encryptedBytes);
} catch (Exception e) {
e.printStackTrace();
}
return encryptedString;
}
/**This method is used to decrypt the String.
* @param contents of type String
* @param keyString of type String indicating the Secret key as String
* @return a String encrypted contents
*/
public static String getDecryptedContents(String contents, String keyString) {
String decryptedString = null;
try {
byte[] contentBytes = new sun.misc.BASE64Decoder()
.decodeBuffer(contents);
SecretKey key = getKeyInstance(keyString);
Cipher ecipher = Cipher.getInstance(algorithm);
ecipher.init(Cipher.DECRYPT_MODE, key);
byte[] encryptedBytes = ecipher.doFinal(contentBytes);
decryptedString = new String(encryptedBytes);
} catch (Exception e) {
e.printStackTrace();
}
return decryptedString;
}
}
The above class provides several useful methods for encryption and decryption. Please refer the java docs provided for each method. Generally in many applications, you may have to use either for a file or for a String. In the above class , I have provided two methods for file encryption and decryption. In certain situation, it is required that you have to encrypt the contents of the file. More specifically I can provide you an example, think about a file called “sample.txt”. You have to encrypt the contents of the file “Sample.txt” so that after encryption when you are opening the file, it becomes unreadable. It may also be required to transfer the file to network. Sometime a requirement comes that there is file called “Sample.txt”, you have to encrypt the contents of the file and to create a new file called “Sample_en.txt”. In this case you have two files, one is the original one as well as the encrypted file. Now refer to the following subordinate classes for the use.
Class name: KeyGenerator.java
package com.dds.core;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Properties;
/**
* This class is used to generate the secrete key and
* stores the secret key in a file called secret.key.
* @author Debadatta Mishra(PIKU)
*
*/
public class KeyGenerator {
/**This method is used to obtain the
* path of the file secret.key.
* @return path of Key
*/
private static String getKeyFilePath() {
String keyPath = null;
try {
String keyDirPath = System.getProperty(”user.dir”) + File.separator
+ “key”;
File keyDir = new File(keyDirPath);
if (!keyDir.exists())
keyDir.mkdirs();
keyPath = keyDirPath + File.separator + “secretkey.key”;
} catch (Exception e) {
e.printStackTrace();
}
return keyPath;
}
/**
* This method is used to store the
* secret key in a file.
*/
public static void storeKey() {
try {
Properties keyProp = new Properties();
OutputStream out = new FileOutputStream(getKeyFilePath());
keyProp.put(”key”, KeyUtil.generateSecretKey());
keyProp
.store(out,
“Secret key information, do not modify the key.”);
} catch (Exception e) {
e.printStackTrace();
}
}
}
This class is used to generate the Secret key and to store in a file so that the secret key can be retrieved as and when required. Let us see another class where you can read the secret key file to get the secret key.
Class name: KeyReader.java
package com.dds.core;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
/**This is a utility class to read the
* contents of the secret.key file.
* @author Debadatta Mishra(PIKU)
*
*/
public class KeyReader {
/**This method is used to obtain the
* key String which is stored in the
* file secret.key.
* @return the key String
*/
public static String getSecretKey() {
String secretKeyString = null;
try {
String keyDirPath = System.getProperty(”user.dir”) + File.separator
+ “key”;
String keyPath = keyDirPath + File.separator + “secretkey.key”;
Properties keyProp = new Properties();
InputStream in = new FileInputStream(keyPath);
keyProp.load(in);
secretKeyString = keyProp.getProperty(”key”);
} catch (Exception e) {
e.printStackTrace();
}
return secretKeyString;
}
}
The above class is used to read the secret key.
I provide below all the test harness classes for the above classes. The first test harness class is “KeyGeneratorTest.java”.
import com.dds.core.KeyGenerator;
/**This is a test harness class to generate
* the secret key and store in a file.
* @author Debadatta Mishra(PIKU)
*
*/
public class KeyGeneratorTest {
public static void main(String[] args) {
KeyGenerator.storeKey();
}
}
This class is used to generate the secret key.
The next test harness class is “StringEncryptionTest.java”.
import com.dds.core.KeyReader;
import com.dds.core.KeyUtil;
/**This test harness class is used to
* encrypt and decrypt the String.
* @author Debadatta Mishra(PIKU)
*
*/
public class StringEncryptionTest {
public static void main(String[] args) {
String originalString = “Hello World”;
String secretKeyString = KeyReader.getSecretKey();
String encryptedStringContents = KeyUtil.getEncryptedContents(
originalString, secretKeyString);
System.out.println(”Original String——” + originalString);
System.out.println(”Encrypted String—–” + encryptedStringContents);
/*
* Now get back to your originalString by decryption
*/
String decryptedString = KeyUtil.getDecryptedContents(
encryptedStringContents, secretKeyString);
System.out.println(”Decrypted String—–” + decryptedString);
}
}
The above class is used to encrypt and decrypt a String. It may be useful for for your password and some other String of characters. Let us see the class for file encryption.
Class Name : FileEncryptionTest.java
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import com.dds.core.KeyReader;
import com.dds.core.KeyUtil;
/**This is the test harness class for the
* encryption and decryption of the file.
* @author Debadatta Mishra(PIKU)
*
*/
public class FileEncryptionTest {
public static void main(String[] args) throws Exception {
String filePath = “C:/output.txt”;
String secretKeyString = KeyReader.getSecretKey();
/*
* Encrypt the fileContents and write to the same file
*/
KeyUtil.encryptFile(filePath, secretKeyString);
/*
* Decrypt the file contents and write to the same file
*/
KeyUtil.decryptFile(filePath, secretKeyString);
/*
* Encrypt the file contents and write to another
* file which contains the encrypted contents.
*/
String encryptedFilePath = “C:/en.txt”;
InputStream in = new FileInputStream(filePath);
OutputStream out = new FileOutputStream(encryptedFilePath);
KeyUtil.encryptFile(in, out, secretKeyString);
/*
* Decrypt the file contents and write to an another file.
*/
in = new FileInputStream(encryptedFilePath);
out = new FileOutputStream(filePath);
KeyUtil.decryptFile(in, out, secretKeyString);
}
}
The above class provides several ways you can encrypt and decrypt the file.
Please follow the following sequence to execute the above classes.
Please create the appropriate package structure and copy the corresponding classes inside the package.
First run the class “KeyGeneratorTest.java” . You will find a file called “secret.key” where the secret key is tored.
Next run the class “StringEncryptionTest.java”.
Create a text file with some contents and place in a directory. Then run the class “FileEncryptionTest.java” to encrypt or decrypt the file.
Conclusion
I hope that you will enjoy my article for the symmetric cryptography. For asymmetric cryptography please refer to the link http://www.articlesbase.com/information-technology-articles/asymmetric-cryptography-in-java-438155.html. If you find any problems or errors, please feel free to send me a mail in the address debadattamishra@aol.com . This article is only meant for those who are new to java development. This article does not bear any commercial significance. Please provide me the feedback about this article.
Mike
Symmetric cryptography in Java
Introduction
As you know data security is a significant aspect of any enterprise application. Starting from password encryption to any data exchange, cryptography has been in use for all kinds of purpose. However there are two kinds of cryptography, one is symmetric and another is asymmetric. In case of symmetric cryptography, a secret key is used for all kinds of encryption and decryption. This secret key is shared by all the members who want to participate in the encryption and decryption process. There are several algorithms for the symmetric cryptography. DES( Data Encryption Standard) is one of them. In case of normal login screen of web based application, implementation of DES algorithm is used for password encryption.
Technicalities
Java cryptography provides suitable and flexible framework for the use of symmetric cryptography. DES algorithm is commonly known as symmetric algorithm. In case of symmetric cryptography, the secret key is used in a plain text file and this file is shared between the members. This file is used to retrieve the secret key for all kinds of encryption and decryption. In this regards I can provide you an example that think of a situation where the two lovers receive their love letters in encrypted format so that no body can read it. They have a common key called the DES secret key. They use the secret key to decrypt the contents of the encrypted love letters at their end. It means that the secret key is generated once and shared between the members. For more details of DES algorithm please refer to the java docs and JCE framework provided by Sun. In this article I will provide an example of how to use the implementation of DES algorithm.
Complete example
The following is the utility class for the cryptography management. The class name is
“KeyUtil.java”.
package com.dds.core;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
/**This is a utility class for all kinds
* of useful methods related to symmetric
* cryptography. This class only provides
* the use of DES algorithm.You can use any
* other symmetric algorithm similarly.
* @author Debadatta Mishra( PIKU )
*
*/
public class KeyUtil {
/**
* Name of the algorithm
*/
private static String algorithm = “DES”;
/**This method is used to obtain the
* Secret key as a String. It is useful
* you can store the String in a file
* for all kinds of encryption and
* decryption.
* @return the SecretKey as String
*/
public static String generateSecretKey() {
String secretKeyString = null;
try {
KeyGenerator keyGen = KeyGenerator.getInstance(algorithm);
SecretKey secretKey = keyGen.generateKey();
byte[] secretKeyBytes = secretKey.getEncoded();
secretKeyString = new sun.misc.BASE64Encoder()
.encode(secretKeyBytes);
} catch (Exception e) {
e.printStackTrace();
}
return secretKeyString;
}
/**This method is used to obtain the SecretKey
* object by passing the secret key as string.
* @param secretKeyString of type String
* @return object of {@link SecretKey}
*/
private static SecretKey getKeyInstance(String secretKeyString) {
SecretKey secretKey = null;
try {
byte[] b2 = new sun.misc.BASE64Decoder()
.decodeBuffer(secretKeyString);
secretKey = new SecretKeySpec(b2, algorithm);
} catch (Exception e) {
e.printStackTrace();
}
return secretKey;
}
/**This method is used to encrypt the same file.
* This method is useful when you are encrypting
* the contents of a file. There is no need to
* create another file with the encrypted contents.
* @param filePath of type String indicating the path of the file
* @param keyString of type String indicating the secret key
*/
public static void encryptFile(String filePath, String keyString) {
try {
SecretKey key = getKeyInstance(keyString);
Cipher ecipher = Cipher.getInstance(algorithm);
ecipher.init(Cipher.ENCRYPT_MODE, key);
InputStream in = new FileInputStream(filePath);
byte[] fileBytes = new byte[in.available()];
in.read(fileBytes);
in.close();
OutputStream out = new FileOutputStream(filePath);
out = new CipherOutputStream(out, ecipher);
out.write(fileBytes);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**This method is used to decrypt the same file.
* This method is useful when you are decrypting
* the contents of a file. There is no need to
* create another file with the decrypted contents.
* @param filePath of type String indicating the path of the file
* @param keyString of type String indicating the secret key
*/
public static void decryptFile(String filePath, String keyString) {
try {
SecretKey key = getKeyInstance(keyString);
Cipher ecipher = Cipher.getInstance(algorithm);
ecipher.init(Cipher.DECRYPT_MODE, key);
InputStream in = new FileInputStream(filePath);
byte[] fileBytes = new byte[in.available()];
in.read(fileBytes);
in.close();
OutputStream out = new FileOutputStream(filePath);
out = new CipherOutputStream(out, ecipher);
out.write(fileBytes);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**This method is used to encrypt the contents
* of a file and writing to another file. This
* method is useful when you want to maintain the
* original contents and encrypting the contents
* and giving to another person.
* @param in of type {@link InputStream}
* @param out of type {@link OutputStream}
* @param keyString of type String indicating the SecretKey
*/
public static void encryptFile(InputStream in, OutputStream out,
String keyString) {
byte[] buf = new byte[1024];
try {
SecretKey key = getKeyInstance(keyString);
Cipher ecipher = Cipher.getInstance(algorithm);
ecipher.init(Cipher.ENCRYPT_MODE, key);
// Bytes written to out will be encrypted
out = new CipherOutputStream(out, ecipher);
// Read in the cleartext bytes and write to out to encrypt
int numRead = 0;
while ((numRead = in.read(buf)) >= 0) {
out.write(buf, 0, numRead);
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**This method is used to decrypt the contents
* of a file and writing to another file. This
* method is useful when you want to decrypt
* the contents and writing to a another file.
* @param in of type {@link InputStream}
* @param out of type {@link OutputStream}
* @param keyString of type String indicating the SecretKey
*/
public static void decryptFile(InputStream in, OutputStream out,
String keyString) {
byte[] buf = new byte[1024];
try {
SecretKey key = getKeyInstance(keyString);
Cipher dcipher = Cipher.getInstance(algorithm);
dcipher.init(Cipher.DECRYPT_MODE, key);
in = new CipherInputStream(in, dcipher);
int numRead = 0;
while ((numRead = in.read(buf)) >= 0) {
out.write(buf, 0, numRead);
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**This method is used to encrypt the String.
* @param contents of type String
* @param keyString of type String indicating the Secret key as String
* @return a String encrypted contents
*/
public static String getEncryptedContents(String contents, String keyString) {
String encryptedString = null;
try {
byte[] contentBytes = contents.getBytes();
SecretKey key = getKeyInstance(keyString);
Cipher ecipher = Cipher.getInstance(algorithm);
ecipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encryptedBytes = ecipher.doFinal(contentBytes);
encryptedString = new sun.misc.BASE64Encoder()
.encode(encryptedBytes);
} catch (Exception e) {
e.printStackTrace();
}
return encryptedString;
}
/**This method is used to decrypt the String.
* @param contents of type String
* @param keyString of type String indicating the Secret key as String
* @return a String encrypted contents
*/
public static String getDecryptedContents(String contents, String keyString) {
String decryptedString = null;
try {
byte[] contentBytes = new sun.misc.BASE64Decoder()
.decodeBuffer(contents);
SecretKey key = getKeyInstance(keyString);
Cipher ecipher = Cipher.getInstance(algorithm);
ecipher.init(Cipher.DECRYPT_MODE, key);
byte[] encryptedBytes = ecipher.doFinal(contentBytes);
decryptedString = new String(encryptedBytes);
} catch (Exception e) {
e.printStackTrace();
}
return decryptedString;
}
}
The above class provides several useful methods for encryption and decryption. Please refer the java docs provided for each method. Generally in many applications, you may have to use either for a file or for a String. In the above class , I have provided two methods for file encryption and decryption. In certain situation, it is required that you have to encrypt the contents of the file. More specifically I can provide you an example, think about a file called “sample.txt”. You have to encrypt the contents of the file “Sample.txt” so that after encryption when you are opening the file, it becomes unreadable. It may also be required to transfer the file to network. Sometime a requirement comes that there is file called “Sample.txt”, you have to encrypt the contents of the file and to create a new file called “Sample_en.txt”. In this case you have two files, one is the original one as well as the encrypted file. Now refer to the following subordinate classes for the use.
Class name: KeyGenerator.java
package com.dds.core;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Properties;
/**
* This class is used to generate the secrete key and
* stores the secret key in a file called secret.key.
* @author Debadatta Mishra(PIKU)
*
*/
public class KeyGenerator {
/**This method is used to obtain the
* path of the file secret.key.
* @return path of Key
*/
private static String getKeyFilePath() {
String keyPath = null;
try {
String keyDirPath = System.getProperty(”user.dir”) + File.separator
+ “key”;
File keyDir = new File(keyDirPath);
if (!keyDir.exists())
keyDir.mkdirs();
keyPath = keyDirPath + File.separator + “secretkey.key”;
} catch (Exception e) {
e.printStackTrace();
}
return keyPath;
}
/**
* This method is used to store the
* secret key in a file.
*/
public static void storeKey() {
try {
Properties keyProp = new Properties();
OutputStream out = new FileOutputStream(getKeyFilePath());
keyProp.put(”key”, KeyUtil.generateSecretKey());
keyProp
.store(out,
“Secret key information, do not modify the key.”);
} catch (Exception e) {
e.printStackTrace();
}
}
}
This class is used to generate the Secret key and to store in a file so that the secret key can be retrieved as and when required. Let us see another class where you can read the secret key file to get the secret key.
Class name: KeyReader.java
package com.dds.core;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
/**This is a utility class to read the
* contents of the secret.key file.
* @author Debadatta Mishra(PIKU)
*
*/
public class KeyReader {
/**This method is used to obtain the
* key String which is stored in the
* file secret.key.
* @return the key String
*/
public static String getSecretKey() {
String secretKeyString = null;
try {
String keyDirPath = System.getProperty(”user.dir”) + File.separator
+ “key”;
String keyPath = keyDirPath + File.separator + “secretkey.key”;
Properties keyProp = new Properties();
InputStream in = new FileInputStream(keyPath);
keyProp.load(in);
secretKeyString = keyProp.getProperty(”key”);
} catch (Exception e) {
e.printStackTrace();
}
return secretKeyString;
}
}
The above class is used to read the secret key.
I provide below all the test harness classes for the above classes. The first test harness class is “KeyGeneratorTest.java”.
import com.dds.core.KeyGenerator;
/**This is a test harness class to generate
* the secret key and store in a file.
* @author Debadatta Mishra(PIKU)
*
*/
public class KeyGeneratorTest {
public static void main(String[] args) {
KeyGenerator.storeKey();
}
}
This class is used to generate the secret key.
The next test harness class is “StringEncryptionTest.java”.
import com.dds.core.KeyReader;
import com.dds.core.KeyUtil;
/**This test harness class is used to
* encrypt and decrypt the String.
* @author Debadatta Mishra(PIKU)
*
*/
public class StringEncryptionTest {
public static void main(String[] args) {
String originalString = “Hello World”;
String secretKeyString = KeyReader.getSecretKey();
String encryptedStringContents = KeyUtil.getEncryptedContents(
originalString, secretKeyString);
System.out.println(”Original String——” + originalString);
System.out.println(”Encrypted String—–” + encryptedStringContents);
/*
* Now get back to your originalString by decryption
*/
String decryptedString = KeyUtil.getDecryptedContents(
encryptedStringContents, secretKeyString);
System.out.println(”Decrypted String—–” + decryptedString);
}
}
The above class is used to encrypt and decrypt a String. It may be useful for for your password and some other String of characters. Let us see the class for file encryption.
Class Name : FileEncryptionTest.java
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import com.dds.core.KeyReader;
import com.dds.core.KeyUtil;
/**This is the test harness class for the
* encryption and decryption of the file.
* @author Debadatta Mishra(PIKU)
*
*/
public class FileEncryptionTest {
public static void main(String[] args) throws Exception {
String filePath = “C:/output.txt”;
String secretKeyString = KeyReader.getSecretKey();
/*
* Encrypt the fileContents and write to the same file
*/
KeyUtil.encryptFile(filePath, secretKeyString);
/*
* Decrypt the file contents and write to the same file
*/
KeyUtil.decryptFile(filePath, secretKeyString);
/*
* Encrypt the file contents and write to another
* file which contains the encrypted contents.
*/
String encryptedFilePath = “C:/en.txt”;
InputStream in = new FileInputStream(filePath);
OutputStream out = new FileOutputStream(encryptedFilePath);
KeyUtil.encryptFile(in, out, secretKeyString);
/*
* Decrypt the file contents and write to an another file.
*/
in = new FileInputStream(encryptedFilePath);
out = new FileOutputStream(filePath);
KeyUtil.decryptFile(in, out, secretKeyString);
}
}
The above class provides several ways you can encrypt and decrypt the file.
Please follow the following sequence to execute the above classes.
Please create the appropriate package structure and copy the corresponding classes inside the package.
First run the class “KeyGeneratorTest.java” . You will find a file called “secret.key” where the secret key is tored.
Next run the class “StringEncryptionTest.java”.
Create a text file with some contents and place in a directory. Then run the class “FileEncryptionTest.java” to encrypt or decrypt the file.
Conclusion
I hope that you will enjoy my article for the symmetric cryptography. For asymmetric cryptography please refer to the link http://www.articlesbase.com/information-technology-articles/asymmetric-cryptography-in-java-438155.html. If you find any problems or errors, please feel free to send me a mail in the address debadattamishra@aol.com . This article is only meant for those who are new to java development. This article does not bear any commercial significance. Please provide me the feedback about this article.
Mike
Php Frameworks
Pranav Bhat asked:
PHP Frameworks:
PHP is finally getting the attention that i deserves, yes I have always believed that PHP is one of those neglected languages, neglected because they are used in abundance but there isn’t enough programs or as we call them frameworks to work on PHP. But that was until the release of PHP 5. After the release of PHP, there is a range of Frameworks available.
Today we review and understand closely the various frameworks available for PHP. Some of the most popular frameworks for PHP are:
The Zend Framework.
The Prado Framework.
CakePHP Framework.
Symphony Framework.
These frameworks are ofcourse the most popular ones and there are more than 40 frameworks for PHP and it is very difficult to know which framework suits you the best and will be the most productive for your web development and enterprise goals.
Ofcourse all these frameworks are free and provide a host of services to satisfy almost all of the web development needs of a web designer or a website owner. Some of the most common features of all these PHP Framework are as follows:
PHP 5: Thats obvious! All the frameworks support both PHP 5 version of the PHP.Only “The Prado Framework” support the PHP 4.x version of the PHP as well as the PHP 5 version of the PHP.
Multiple DBs: All the above mentioned frameworks support multiple databases to be used without making any setup and configuration changes.
Validation: All the four frameworks have an inbult validation and a filtering component which can be used.
MVC: All the four frameworks have the MVC that is the Model View Controller setup.
So, these are the few components and controllers that are common in most of the PHP based frameworks and therefore one should look out for these components when downloading or using a PHP framework.
Now let us see a brief introduction about each of these PHP based frameworks and their salient features:
Zend Framework:Zend Framework is a component based framework with components for almost all of the programming needs of a PHP programmer or PHP developer.
Some of the components in the Zend Framework are:
zend_acl
zend_auth
zend_cache
zend_config
zend_consolegetop and many more.
Prado Framework: The Prado framework provides the following benefits for web application developers.
reusablility
Ease of use
Robustness
Performance
Team Integration
CakePHP:
Some of the important features of CakePHP are as follows:
Model, View, Controller Architecture
View Helpers for AJAX, Javascript, HTML Forms and more
Built-in Validation
Application Scaffolding
Application and CRUD code generation via Bake
Access Control Lists
Data Sanitization
Security, Session, and Request Handling Components
Flexible View Caching
Like all other frameworks cakePHP is also component based framework.
The Symphony Framework:
Some of the features of the symphony framework are as follows:
simple templating and helpers
cache management
smart URLs
scaffolding
multilingualism and I18N support
object model and MVC separation
Ajax support
enterprise ready
Thus these are the best options available for frameworks relating to PHP and one should review all these features of all these frameworks against his needs and choose the appropriate framework to work on!
Any suggestions and comments as always are welcome.
Jean
PHP Frameworks:
PHP is finally getting the attention that i deserves, yes I have always believed that PHP is one of those neglected languages, neglected because they are used in abundance but there isn’t enough programs or as we call them frameworks to work on PHP. But that was until the release of PHP 5. After the release of PHP, there is a range of Frameworks available.
Today we review and understand closely the various frameworks available for PHP. Some of the most popular frameworks for PHP are:
The Zend Framework.
The Prado Framework.
CakePHP Framework.
Symphony Framework.
These frameworks are ofcourse the most popular ones and there are more than 40 frameworks for PHP and it is very difficult to know which framework suits you the best and will be the most productive for your web development and enterprise goals.
Ofcourse all these frameworks are free and provide a host of services to satisfy almost all of the web development needs of a web designer or a website owner. Some of the most common features of all these PHP Framework are as follows:
PHP 5: Thats obvious! All the frameworks support both PHP 5 version of the PHP.Only “The Prado Framework” support the PHP 4.x version of the PHP as well as the PHP 5 version of the PHP.
Multiple DBs: All the above mentioned frameworks support multiple databases to be used without making any setup and configuration changes.
Validation: All the four frameworks have an inbult validation and a filtering component which can be used.
MVC: All the four frameworks have the MVC that is the Model View Controller setup.
So, these are the few components and controllers that are common in most of the PHP based frameworks and therefore one should look out for these components when downloading or using a PHP framework.
Now let us see a brief introduction about each of these PHP based frameworks and their salient features:
Zend Framework:Zend Framework is a component based framework with components for almost all of the programming needs of a PHP programmer or PHP developer.
Some of the components in the Zend Framework are:
zend_acl
zend_auth
zend_cache
zend_config
zend_consolegetop and many more.
Prado Framework: The Prado framework provides the following benefits for web application developers.
reusablility
Ease of use
Robustness
Performance
Team Integration
CakePHP:
Some of the important features of CakePHP are as follows:
Model, View, Controller Architecture
View Helpers for AJAX, Javascript, HTML Forms and more
Built-in Validation
Application Scaffolding
Application and CRUD code generation via Bake
Access Control Lists
Data Sanitization
Security, Session, and Request Handling Components
Flexible View Caching
Like all other frameworks cakePHP is also component based framework.
The Symphony Framework:
Some of the features of the symphony framework are as follows:
simple templating and helpers
cache management
smart URLs
scaffolding
multilingualism and I18N support
object model and MVC separation
Ajax support
enterprise ready
Thus these are the best options available for frameworks relating to PHP and one should review all these features of all these frameworks against his needs and choose the appropriate framework to work on!
Any suggestions and comments as always are welcome.
Jean
Self-taught Php/mysql: a Simple Page Counter Tutorial
Bill Hamilton asked:
Self-Taught PHP/MYSQL: a simple Page Counter
This article is a short introduction to PHP and MySQL using the example of a simple page counter. I will illustrate creating the database in MySQL, connecting to the database from the PHP script, querying the database for information, displaying the information in a web page, and writing the information back to the database. As always, the fastest way to master the process is to jump right in with the code, look it over and use it. We’ll make a MySQL database to store the page names and the number of page views, and use PHP to increment and display the count on a web page. First here is all of the code, and then I’ll go over it in detail:
This goes into a file called “pagecounter.php”
You’ll no doubt have noticed that the script “includes” another, so without further delay here is the “connect.php” file:
The pagecounter.php script needs a database to operate on. Just briefly, here’s how to create it.
Creating the database:
Log in to MySQL at your Unix prompt (which might be #):
# mysql –uYourUserName –pYourPassword
At the MySQL prompt enter these commands:
mysql> create database pages;
mysql> use pages;
mysql> create table counter (pagename varchar(60),hits int, stamp timestamp);
mysql> quit;
Naturally you can create the database and table with utilities or web-based interfaces, but doesn’t it seem simpler to just enter three commands?
If you just wanted some code for a simple counter, this is all you need. Put this text into an SHTML web page, or this text into a php web page, copy the above two files into the same directory, and you’re done.
The first thing you’ll have noticed about the scripts are the dollar signs ($). All variables in PHP scripts start with a $. Anything starting with a $ is a variable. Instructions - statements and functions – end with a semicolon (;). starts the script and it ends with . When your script is hosed, look at these first.
Details about the pagecounter.php script
Line 1
include_once “connect.php”;
The first line in the script is just what it appears to be. It includes whatever is in the file “connect.php”. The “_once” means that it’s only included once, even if you had the line twice in the script. The reason I’ve separated it out is that it’s all the connection stuff to the database. All the php/Mysql scripts will need it, it’s always the same, so you can just put it by itself and use the include function.
Line 2
$pagename=$_SERVER["REQUEST_URI"];
The next line creates a variable called $pagename and sets the value to a special pre-defined variable $_SERVER["REQUEST_URI"]. The brackets [ ] are used by arrays in php. $_SERVER is a pre-defined array of headers and paths. This particular one is the name of the file that accesses the script, i.e., the name of the page that the counter is in.
Line 3
$result=mysql_query(”Select * from counter where pagename=’$pagename’”);
All the database work is done with mysql_query, which sends an SQL command string to MySQL, after you’ve already logged in and connected to the database with the connect.php script. “Select * from counter where pagename=’$pagename’” replaces $pagename with its value. But there’s a quirk here – the single quotes have to be inside the double quotes. If I had it the other way around, with the single quotes outside, the query would be for the text “$pagename” instead of the value. $result is the result set. It can be any name but in tutorial scripts it’s always $result, so it is here.
Line 4
if (mysql_num_rows($result)==0){
The fourth line is the php version of “if-then”. It simply checks whether there are any results from the query in line 3. The syntax is representative of php coding in general so it’s a good place to start. The curly brackets { } are used to group instructions. The curved brackets ( ) are used for the “if” condition. Everything inside the curly brackets will be executed if the “if” condition is true. PHP uses double equals == for comparison; if I had used only a single equal sign it would try to set mysql_num_rows to 0, which wouldn’t work for our purposes. A missing equal sign is the second thing to look for when your script is hosed and it’s not missing a $ or ;.
Line 5
mysql_query(”insert into counter (pagename,hits) values (’$pagename’,'0′)”); }
Inside the brackets, which only happens when line 4 finds no records of the page we searched for, the instruction creates a new record with the page’s name and zero for the hit count. Although mysql_query is a function, it doesn’t necessarily need a variable $result= in front of it. That’s optional in PHP if you don’t care about the return value.
The closing curly bracket } from the “if” statement comes here, since we only needed one statement to create our record.
Line 6
$count=mysql_result($result, 0, “hits”);
mysql_result fetches the actual data from the result set. You specify the result set (from mysql_query), the row number (0), and the column name (“hits”). This is a little confusing at first since to get here took four steps: 1) log into MySQL, 2) connect to the database, 3) select data from the table, and 4) fetch a particular piece of the data. Putting the repetitive first two steps into an include file where you can more or less forget about them makes it more intuitive: use SQL to select data with mysql_query, and then retrieve data with mysql_result.
Line 7
$count=$count + 1;
Just adds one to the count variable. This is the count of the page views of the page requesting the script.
Line 8
mysql_query (”update counter set hits=$count where pagename=’$pagename’”);
As with Line 5 we send an SQL command directly to MySQL. This one updates the count for just the page matching the variable $pagename.
Line 9
echo “Page Count: “.$count;
The echo function writes text to a web page, in this case the text “Page Count: “ followed by whatever value is in $count. The period in between is the PHP concatenation operator: it simply adds the two strings together. Echo sees it as one string and outputs it.
Details about the connect.php script:
All this script does is connect to the MySQL server and select the Database.
Line 1
$host=”localhost”;$user=”YourUserName”;$password=”YourPassword”;$dbase=”pages”;
These are the inputs for the connect and select_db functions. Naturally you can insert the values into the functions on line 3 and 4 and eliminate this line, but it’s simpler to change later (when you re-use this code for example) if you just list them out at the top. The host and dbase won’t need to be changed in this example. The user and password are specific to your MySQL setup. As shown here you can put as many statements on one line as you want; PHP doesn’t care.
Line 2
// change the user and password to your MySQL user and password
The double slashes // denote a comment line that is ignored by php. Each comment line needs the slashes.
Line 3
$connect = mysql_connect($host,$user,$password);
You log into your MySQL with the mysql_connect command. You would change the host from “localhost” to the database server if you were accessing MySQL from another server, provided you’ve set up the access rights for the specified user/
Line 4
mysql_select_db($dbase,$connect);
Since we can have multiple databases in the MySQL server, we have to select one before sending SQL statements to it. As I mentioned earlier, this part is repetitive, and once it’s in this file and working you can forget about it.
In this tutorial we’ve examined a simple but functional web page counter implemented with PHP/MySQL. We examined the basic syntax of PHP statements and variables, the PHP “include” function and “if” control function, and the fundamental PHP MySQL functions mysql_connect, mysql_select_db, mysql_query, mysql_num_rows, and mysql_result. For further reference the reader should bookmark http://dev.mysql.com/doc/refman/6.0/en/index.html and http://us.php.net/manual/en/funcref.php .
Bill Hamilton is a former Database Administrator for United News and Media, and VNU inc. He currently operates several php/mysql driven websites including Gemstones and Beads
Mario
Self-Taught PHP/MYSQL: a simple Page Counter
This article is a short introduction to PHP and MySQL using the example of a simple page counter. I will illustrate creating the database in MySQL, connecting to the database from the PHP script, querying the database for information, displaying the information in a web page, and writing the information back to the database. As always, the fastest way to master the process is to jump right in with the code, look it over and use it. We’ll make a MySQL database to store the page names and the number of page views, and use PHP to increment and display the count on a web page. First here is all of the code, and then I’ll go over it in detail:
This goes into a file called “pagecounter.php”
You’ll no doubt have noticed that the script “includes” another, so without further delay here is the “connect.php” file:
The pagecounter.php script needs a database to operate on. Just briefly, here’s how to create it.
Creating the database:
Log in to MySQL at your Unix prompt (which might be #):
# mysql –uYourUserName –pYourPassword
At the MySQL prompt enter these commands:
mysql> create database pages;
mysql> use pages;
mysql> create table counter (pagename varchar(60),hits int, stamp timestamp);
mysql> quit;
Naturally you can create the database and table with utilities or web-based interfaces, but doesn’t it seem simpler to just enter three commands?
If you just wanted some code for a simple counter, this is all you need. Put this text into an SHTML web page, or this text into a php web page, copy the above two files into the same directory, and you’re done.
The first thing you’ll have noticed about the scripts are the dollar signs ($). All variables in PHP scripts start with a $. Anything starting with a $ is a variable. Instructions - statements and functions – end with a semicolon (;). starts the script and it ends with . When your script is hosed, look at these first.
Details about the pagecounter.php script
Line 1
include_once “connect.php”;
The first line in the script is just what it appears to be. It includes whatever is in the file “connect.php”. The “_once” means that it’s only included once, even if you had the line twice in the script. The reason I’ve separated it out is that it’s all the connection stuff to the database. All the php/Mysql scripts will need it, it’s always the same, so you can just put it by itself and use the include function.
Line 2
$pagename=$_SERVER["REQUEST_URI"];
The next line creates a variable called $pagename and sets the value to a special pre-defined variable $_SERVER["REQUEST_URI"]. The brackets [ ] are used by arrays in php. $_SERVER is a pre-defined array of headers and paths. This particular one is the name of the file that accesses the script, i.e., the name of the page that the counter is in.
Line 3
$result=mysql_query(”Select * from counter where pagename=’$pagename’”);
All the database work is done with mysql_query, which sends an SQL command string to MySQL, after you’ve already logged in and connected to the database with the connect.php script. “Select * from counter where pagename=’$pagename’” replaces $pagename with its value. But there’s a quirk here – the single quotes have to be inside the double quotes. If I had it the other way around, with the single quotes outside, the query would be for the text “$pagename” instead of the value. $result is the result set. It can be any name but in tutorial scripts it’s always $result, so it is here.
Line 4
if (mysql_num_rows($result)==0){
The fourth line is the php version of “if-then”. It simply checks whether there are any results from the query in line 3. The syntax is representative of php coding in general so it’s a good place to start. The curly brackets { } are used to group instructions. The curved brackets ( ) are used for the “if” condition. Everything inside the curly brackets will be executed if the “if” condition is true. PHP uses double equals == for comparison; if I had used only a single equal sign it would try to set mysql_num_rows to 0, which wouldn’t work for our purposes. A missing equal sign is the second thing to look for when your script is hosed and it’s not missing a $ or ;.
Line 5
mysql_query(”insert into counter (pagename,hits) values (’$pagename’,'0′)”); }
Inside the brackets, which only happens when line 4 finds no records of the page we searched for, the instruction creates a new record with the page’s name and zero for the hit count. Although mysql_query is a function, it doesn’t necessarily need a variable $result= in front of it. That’s optional in PHP if you don’t care about the return value.
The closing curly bracket } from the “if” statement comes here, since we only needed one statement to create our record.
Line 6
$count=mysql_result($result, 0, “hits”);
mysql_result fetches the actual data from the result set. You specify the result set (from mysql_query), the row number (0), and the column name (“hits”). This is a little confusing at first since to get here took four steps: 1) log into MySQL, 2) connect to the database, 3) select data from the table, and 4) fetch a particular piece of the data. Putting the repetitive first two steps into an include file where you can more or less forget about them makes it more intuitive: use SQL to select data with mysql_query, and then retrieve data with mysql_result.
Line 7
$count=$count + 1;
Just adds one to the count variable. This is the count of the page views of the page requesting the script.
Line 8
mysql_query (”update counter set hits=$count where pagename=’$pagename’”);
As with Line 5 we send an SQL command directly to MySQL. This one updates the count for just the page matching the variable $pagename.
Line 9
echo “Page Count: “.$count;
The echo function writes text to a web page, in this case the text “Page Count: “ followed by whatever value is in $count. The period in between is the PHP concatenation operator: it simply adds the two strings together. Echo sees it as one string and outputs it.
Details about the connect.php script:
All this script does is connect to the MySQL server and select the Database.
Line 1
$host=”localhost”;$user=”YourUserName”;$password=”YourPassword”;$dbase=”pages”;
These are the inputs for the connect and select_db functions. Naturally you can insert the values into the functions on line 3 and 4 and eliminate this line, but it’s simpler to change later (when you re-use this code for example) if you just list them out at the top. The host and dbase won’t need to be changed in this example. The user and password are specific to your MySQL setup. As shown here you can put as many statements on one line as you want; PHP doesn’t care.
Line 2
// change the user and password to your MySQL user and password
The double slashes // denote a comment line that is ignored by php. Each comment line needs the slashes.
Line 3
$connect = mysql_connect($host,$user,$password);
You log into your MySQL with the mysql_connect command. You would change the host from “localhost” to the database server if you were accessing MySQL from another server, provided you’ve set up the access rights for the specified user/
Line 4
mysql_select_db($dbase,$connect);
Since we can have multiple databases in the MySQL server, we have to select one before sending SQL statements to it. As I mentioned earlier, this part is repetitive, and once it’s in this file and working you can forget about it.
In this tutorial we’ve examined a simple but functional web page counter implemented with PHP/MySQL. We examined the basic syntax of PHP statements and variables, the PHP “include” function and “if” control function, and the fundamental PHP MySQL functions mysql_connect, mysql_select_db, mysql_query, mysql_num_rows, and mysql_result. For further reference the reader should bookmark http://dev.mysql.com/doc/refman/6.0/en/index.html and http://us.php.net/manual/en/funcref.php .
Bill Hamilton is a former Database Administrator for United News and Media, and VNU inc. He currently operates several php/mysql driven websites including Gemstones and Beads
Mario
Php Nuke Themes: for a New Look and Feel
Fat Jack asked:
An Introduction to PHP Nuke
Based on the PHP scripting language and supported by MySQL database, PHP Nuke provides a web based automated news publishing and content management system. As an open source software released under a GNU public license, it allows for free downloaded and installation.
You can use this software to create a weblog or use it just as a CMS. PHP Nuke allows the editors as well as the users to eas Content Management Systems ily post contents and create comments threads.
PHP Nuke theme manager
There is an advantage of PHP Nuke in being an open source project—-Because PHP Nuke is open source, there is a large community of developers who work on the PHP Nuke theme modifications. In addition to that the flow of free PHP Nuke Modules, free PHP Nuke Add-ons and free PHP Nuke Templates never seem to end. An efficient PHP Nuke web host will help you to customize your site with free PHP Nuke themes.
How your web host can help you in this regard?
Choosing the right PHP Nuke web host is important in case you want to switch from one theme to another, because only then you get access to a really striking collection of PHP Nuke themes.
Then, PHP Nuke web hosting requires a complex combination of web hosting hardware and software. In the absence of this criterion, you are not going to get access to your desired themes. In order to change the theme, you should be connected to a theme archive, from where you have to download it to your web server.
A PHP Nuke tutorial can provide you with good resource for learning about the theme changing process. PHP Nuke is backed up by a huge supporting community and as such finding the add- ons like PHP Nuke themes is not at all hard. These tutorials will provide you with the step by step guide of how to change your PHP Nuke theme.
Suzanne
An Introduction to PHP Nuke
Based on the PHP scripting language and supported by MySQL database, PHP Nuke provides a web based automated news publishing and content management system. As an open source software released under a GNU public license, it allows for free downloaded and installation.
You can use this software to create a weblog or use it just as a CMS. PHP Nuke allows the editors as well as the users to eas Content Management Systems ily post contents and create comments threads.
PHP Nuke theme manager
There is an advantage of PHP Nuke in being an open source project—-Because PHP Nuke is open source, there is a large community of developers who work on the PHP Nuke theme modifications. In addition to that the flow of free PHP Nuke Modules, free PHP Nuke Add-ons and free PHP Nuke Templates never seem to end. An efficient PHP Nuke web host will help you to customize your site with free PHP Nuke themes.
How your web host can help you in this regard?
Choosing the right PHP Nuke web host is important in case you want to switch from one theme to another, because only then you get access to a really striking collection of PHP Nuke themes.
Then, PHP Nuke web hosting requires a complex combination of web hosting hardware and software. In the absence of this criterion, you are not going to get access to your desired themes. In order to change the theme, you should be connected to a theme archive, from where you have to download it to your web server.
A PHP Nuke tutorial can provide you with good resource for learning about the theme changing process. PHP Nuke is backed up by a huge supporting community and as such finding the add- ons like PHP Nuke themes is not at all hard. These tutorials will provide you with the step by step guide of how to change your PHP Nuke theme.
Suzanne



