PHP- session Example
June 3rd, 2009No Comments | Filed Under: Tutorials
Session support in PHP consists of a way to preserve certain data across subsequent accesses. This enables you to build more customized applications and increase the appeal of your web site.
A visitor accessing your web site is assigned a unique id, the so-called session id. This is either stored in a cookie on the user side or is propagated in the URL.
Session Example in PHP:
Source : session_start
// Initialize the session.
session_start();
//store values
$_SESSION['favcolor'] = ‘green’;
$_SESSION['animal'] = ‘cat’;
$_SESSION['time'] = time();
//print stored values
echo $_SESSION['favcolor']; // green
echo $_SESSION['animal']; // cat
echo date(‘Y m d H:i:s’, $_SESSION['time']);
// Unset all of the session variables.
$_SESSION = array();
// Finally, destroy the session.
session_destroy();
?>
Outlook 2002 – The messaging interface has returned an unknown error
May 28th, 20092 Comments | Filed Under: Tutorials
Basically this message comes when the outlook storage capacity is full
Outlook, It can’t hold one more message.
You can’t delete because the message is only going to another folder inside the file cabinet.
Can’t send – no space to hold the message.
Super easy fix is -
In any folder, deleted, sent, inbox click on a message you want to delete. Start from the deleted folder. You have already deleted it once
Using…. shift+delete… get rid of the messages. This method blows it out of Outlook completely. If you click on a message and holding the shift key down you can highlight many messages and get rid of them.
After you get rid of about 30 messages you have enough room for the delete key to work.
Keep dumping the deleted items folder as you are working in sent or the inbox.
You’ll get your Outlook Program working back to normal. 1.8 GB is the capacity of default outlook storage
Serving Image from Absolute Path in Java/J2EE
April 27th, 2009No Comments | Filed Under: Tutorials
import java.io.*;
import java.net.URLDecoder;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Serving Image from Absolute Path.
*/
public class ImageServAbsolutePath extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final int BUFFER_SIZE = 10240;
private String imagePath;
public void init() throws ServletException {
/*——- Image Base Path ———–*/
this.imagePath = "/images";
}
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
// Get requested image by path info.
String requestedImage = req.getPathInfo();
// Check if file name is there in request URI.
if (requestedImage == null) {
// if file name is not there in request URI, send 404 Error, or show default image.
res.sendError(HttpServletResponse.SC_NOT_FOUND); // 404.
return;
}
// Decode the file name (might contain spaces and on) and prepare file object.
File image = new File(imagePath, URLDecoder.decode(requestedImage, "UTF-8"));
// Check if file actually exists in filesystem.
if (!image.exists()) {
// if file not exists in filesystem send 404 Error, or show default image.
res.sendError(HttpServletResponse.SC_NOT_FOUND); // 404.
return;
}
// Get content type of Image by filename.
String contType = getServletContext().getMimeType(image.getName());
// Check if file is actually an image.
if (contType == null || !contType.startsWith("image")) {
// if the file is not a real image send 404 Error, or show default image.
res.sendError(HttpServletResponse.SC_NOT_FOUND); // 404.
return;
}
// Reset servlet response.
res.reset();
res.setBufferSize(BUFFER_SIZE); //set buffer size
res.setHeader("Content-Type", contType); //set content type
res.setHeader("Content-Length", String.valueOf(image.length())); //set image size
res.setHeader("Content-Disposition", "inline; filename=\"" + image.getName() + "\""); //set image name
// Create streams.
BufferedInputStream input = null;
BufferedOutputStream output = null;
try {
// Open streams.
input = new BufferedInputStream(new FileInputStream(image), BUFFER_SIZE);
output = new BufferedOutputStream(res.getOutputStream(), BUFFER_SIZE);
// Write image contents to response.
byte[] buffer = new byte[BUFFER_SIZE];
int length;
while ((length = input.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
output.flush();
} finally {
if (output != null) {
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
Add the following entries to the web.xml file
<servlet-name>ImageServAbs</servlet-name>
<servlet-class>ImageServAbsolutePath</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ImageServAbs</servlet-name>
<url-pattern>/image/*</url-pattern>
</servlet-mapping>
HOWTO USE :