Approaches to Web Development for Bioinformatics

Previous  Contents  Next
References

Interacting with Browsers and Servers

One of the great things about PHP is that it was originally created specifically for creating dynamic web user interfaces and it is simple to start doing that. There are also a number of capabilities for interacting with browsers and servers, including cookies, HTTP headers, and server modules.

Cookies are something that most users do not like and should not be necessary for bioinformatics programming. Having said that they are essential for a couple of tasks. Most importantly, they are the best tool for creating user sessions. This is handled automatically by the PHP framework. Cookies may be manipulated in PHP using the function setcookie and read using the request variable $_COOKIE.

A user can be redirected to a different page by setting a Location header. This is demonstrated below.


PHP

<?php
header('Location: http://medicalcomputing.net/index.html');
exit();
?>

The full URL not just the path is needed for the header.

When building a query string for a HTTP GET request you need to be careful about special characters like spaces, #, etc. The PHP function http_build_query() assists with this. For example,


PHP

<?php
header('Content-Type: text/plain;charset=utf-8');
$query_vars = array(
'search' => 'Huntington disease',
'keywords' => 'HD +/- huntingtin'
);
print '/search.php?' . http_build_query($query_vars);
?>

The spaces are converted to + and the +/ symbols are converted to the hexadecimal equivalents. The output of this program is


Pogram output

/search.php?search=Huntington+disease&keywords=HD+%2B%2F-+huntingtin


Previous  Contents  Next
References

Contributed Comments and NotesAdd a comment.

There are no user comments.

Google

Please send ideas and opinions by email at alexamies@gmail.com.

© 2006-2007 Alex Amies