WebMe
homeaboutportfolioservicescontact

WebMe - Website Design & Development

previous posts
archives
 

All resources published on this blog are free to use and redistribute. All we ask is that you keep any copyright notices and links to WebMe in your code. If you find something really useful we would appreciate you placing a link on your site to ours.

 
uk web design association Independent Web Developers Portal
This is a Carbon Neutral website Follow us on Twitter
All major credit cards accepted
Web Site Design BlogSubscribe to this Blog

DSN-Less Connection to MySQL in ASP

To access a MySQL database in ASP you can use the following script:

Function getDBConn()
Set conDB=Server.CreateObject("ADODB.Connection") conDB.Open "Driver={MySQL ODBC 3.51 Driver};" & _ "Server=mysql.myserver.net;" & _ "Port=3306;" & _ "Option=131072;" & _ "Stmt=;" & _ "Database=mydatabase;" & _ "Uid=myname;" & _ "Pwd=mypassword" End Function

Remember to change the Server address to the address of your MySQL database; also you will need to change the Database, Uid and Pwd parameters as appropriate.

Labels: , ,

Design web site media
2 Comments

 

Web Site Design BlogSubscribe to this Blog

PHP Connection to MySQL

To access a MySQL database in PHP you can use the following script:

<?php
$dbhost = 'mysql.myserver.net';
$dbuser = 'myname';
$dbpass = 'mypassword';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die 
('Error connecting to mysql');

$dbname = 'mydatabase';
mysql_select_db($dbname);
?>

Remember to change the Host address to the address of your MySQL database; also you will need to change the dbname, dbuser and dbpass parameters as appropriate.

Labels: , ,

Design web site media
0 Comments

 

Web Site Design BlogSubscribe to this Blog

ASP Server Variables

We have decided to remove our Resources section in order to keep all useful code snippets and tips in our blog so we will post some of the content of those pages here.
The first one is the ASP Server Variables table:

The table below shows the Server Variables available in ASP and example values.

Server Variable Description
ALL_HTTP Returns all HTTP headers sent by the client. Always prefixed with HTTP_ and capitalized
ALL_RAW Returns all headers in raw form
APPL_MD_PATH Returns the meta base path for the application for the ISAPI DLL
APPL_PHYSICAL_PATH Returns the physical path corresponding to the meta base path
AUTH_PASSWORD Returns the value entered in the client's authentication dialog
AUTH_TYPE The authentication method that the server uses to validate users
AUTH_USER Returns the raw authenticated user name
CERT_COOKIE Returns the unique ID for client certificate as a string
CERT_FLAGS bit0 is set to 1 if the client certificate is present and bit1 is set to 1 if the Certification authority of the client certificate is not valid
CERT_ISSUER Returns the issuer field of the client certificate
CERT_KEYSIZE Returns the number of bits in Secure Sockets Layer connection key size
CERT_SECRETKEYSIZE Returns the number of bits in server certificate private key
CERT_SERIALNUMBER Returns the serial number field of the client certificate
CERT_SERVER_ISSUER Returns the issuer field of the server certificate
CERT_SERVER_SUBJECT Returns the subject field of the server certificate
CERT_SUBJECT Returns the subject field of the client certificate
CONTENT_LENGTH Returns the length of the content as sent by the client
CONTENT_TYPE Returns the data type of the content
GATEWAY_INTERFACE Returns the revision of the CGI specification used by the server
HTTP_<HeaderName> Returns the value stored in the header HeaderName
HTTP_ACCEPT Returns the value of the Accept header
HTTP_ACCEPT_LANGUAGE Returns a string describing the language to use for displaying content
HTTP_COOKIE Returns the cookie string included with the request
HTTP_REFERER Returns a string containing the URL of the page that referred the request to the current page using an <a> tag. If the page is redirected, HTTP_REFERER is empty
HTTP_USER_AGENT Returns a string describing the browser that sent the request
HTTPS Returns ON if the request came in through secure channel or OFF if the request came in through a non-secure channel
HTTPS_KEYSIZE Returns the number of bits in Secure Sockets Layer connection key size
HTTPS_SECRETKEYSIZE Returns the number of bits in server certificate private key
HTTPS_SERVER_ISSUER Returns the issuer field of the server certificate
HTTPS_SERVER_SUBJECT Returns the subject field of the server certificate
INSTANCE_ID The ID for the IIS instance in text format
INSTANCE_META_PATH The meta base path for the instance of IIS that responds to the request
LOCAL_ADDR Returns the server address on which the request came in
LOGON_USER Returns the Windows account that the user is logged into
PATH_INFO Returns extra path information as given by the client
PATH_TRANSLATED A translated version of PATH_INFO that takes the path and performs any necessary virtual-to-physical mapping
QUERY_STRING Returns the query information stored in the string following the question mark (?) in the HTTP request
REMOTE_ADDR Returns the IP address of the remote host making the request
REMOTE_HOST Returns the name of the host making the request
REMOTE_USER Returns an unmapped user-name string sent in by the user
REQUEST_METHOD Returns the method used to make the request
SCRIPT_NAME Returns a virtual path to the script being executed
SERVER_NAME Returns the server's host name, DNS alias, or IP address as it would appear in self-referencing URLs
SERVER_PORT Returns the port number to which the request was sent
SERVER_PORT_SECURE Returns a string that contains 0 or 1. If the request is being handled on the secure port, it will be 1. Otherwise, it will be 0
SERVER_PROTOCOL Returns the name and revision of the request information protocol
SERVER_SOFTWARE Returns the name and version of the server software that answers the request and runs the gateway
URL Returns the base portion of the URL

To access Server Variables in ASP we use:

Request.ServerVariables (server_variable)

Labels: ,

Design web site media
0 Comments

 

Web Site Design BlogSubscribe to this Blog

Getting path and location details in Javascript

A couple of quick tips for you to get path information for your page in JavaScript, assuming that the URL we are manipulating is http://example.com/test/test.php?i=1&b=2#3 To get the complete URL use:
location.href
returns http://example.com/test/test.php?i=1&b=2#3

To get the hostname use:
location.hostname
returns example.com

To get the path of the current URL including the script use:
location.pathname
returns /test/test.php

To get the current URL excluding the script use:
location.hostname+location.pathname.substr(0, location.pathname.lastIndexOf("/"))+"/"
returns example.com/test/

Now to get passed parameters from the QueryString:
location.search
returns ?i=1&b=2

To get just the anchor or hash part use:
location.hash
returns #3

Finally to get the protocol use:
location.protocol
returns http:

Labels: , , , ,

Design web site media
0 Comments

 

Web Site Design BlogSubscribe to this Blog

Get Current Directory Function in PHP

Something that many people ask for is an extremely simple piece of code and that is "How do I get the current directory in PHP?" Well, we use a function to do this and the code is as follows:
function getDirectory() {
 $f = getcwd();
 return substr($f, strrpos($f, "/") + 1);
}
The PHP function getcwd() returns the current working directory and path. The following line simply strips the path and returns the name of the current directory. Instead of using getcwd() you can also use dirname(__FILE__) so the code could be rewritten as:
function getDirectory() {
 $f = dirname(__FILE__);
 return substr($f, strrpos($f, "/") + 1);
}

Labels: ,

Design web site media
0 Comments

 

Web Site Design BlogSubscribe to this Blog

Careful with your Comments in IE

Small tip today. Be careful where you place your HTML comments in Internet Explorer. Placing comments before you begin your HTML content can cause strange layout rendering. For example:
<!-- My Comment --> <html> <head> ....
This is wrong and can cause all sorts of layout issues. Always make sure your comment is in your HTML content.

Labels: , ,

Design web site media
0 Comments

 

Web Site Design BlogSubscribe to this Blog

XML Sitemap Generator Script in PHP for Google and others

We develop a lot of websites and quite rightly the owners want their site to appear in Google as quickly as possible. One way to speed up this process is to use Google's sitemap tool.
Google accept sitemaps in various formats, one of them being XML.
Now if you have a site, or develop websites, that quite often have new content and pages being added to them it can be a pain to create a new sitemap each time. For this reason we have taken a nice little script developed in ASP by Francesco Passantino and rewritten it in PHP.
To use this script, simply place it in the root of your website and tell Google where it is in the Add Sitemap section of Google sitemaps.
The script will generate a valid XML sitemap that will dynamically update whenever new pages are added or pages are deleted.

Version 1.0 can be found here. This is for PHP5 only, we also have a PHP4 version which can be found here. To use the PHP4 version you will need the strripos PHP4 script from here.

Labels: , , , ,

Design web site media
5 Comments

 

Web Site Design BlogSubscribe to this Blog

Random Password Generator in PHP

Today we thought we'd share our random PHP password generator code with you. This function returns a variable length password comprised of upper and lower case characters with numbers. Simply pass the desired password length to the function.
function RandomPW($myLength) {
 $strPW = '';
 //These constant are the minimum and maximum length for random
 //length passwords.  Adjust these values to your needs.
 $minLength = 6;
 $maxLength = 20;
 
 if ($myLength == 0) {
  $myLength = rand($minLength, $maxLength);
 }

 for ($X=1;$X<=$myLength;$X++) {
  //Randomize the type of this character
  $Y = rand(1,3); //(1) Numeric, (2) Uppercase, (3) Lowercase
  switch ($Y) {
   case 1:
    //Numeric character
    $strPW = $strPW.chr(rand(48, 57));
    break;
   case 2:
    //Uppercase character
    $strPW = $strPW.chr(rand(65, 90));
    break;
   case 3:
    //Lowercase character
    $strPW = $strPW.chr(rand(97, 122));
    break;
  }
 }
 return($strPW);
}

Labels: , ,

Design web site media
0 Comments

 

info@webme.co.uk

copyright About UsServicesPortfolioDemoGet QuoteContact