PHPBuilder - Creating a Printer Version Grab Method Page 5



RSS Twitter
Articles Html

Creating a Printer Version Grab Method - Page 5

by: Jim Fletcher
|
April 1, 2004

Determine the original webpage
Depending on your implementation, you may pass a variable to the script telling it what URL to spider. If the script does not receive this variable, it will try to determine the URL using the $HTTP_REFERER variable.

<?php
//Get The URL to spider
    
if (!$url) {
        
$url=$HTTP_REFERER;
    }
?>
Verify user
This script is designed for you to set up multiple domain names which are allowed to use the Printer Version script. No other domain names will be allowed to use the script.
To accomplish these we will first extract the domain name from the URL:

<?php
$url2 
strtolower($url);
$url2 str_replace("http://"""$url2);
$url2 str_replace("www."""$url2);
$path explode ("/"$url2);
$domainname $path[0];
?>
Next we will query the MySQL database to look for a match for any users which match the domainname just parsed. If the user is active, then the settings for that user will be available later in the script in an array called $myrow.

<?php
$sql 
"SELECT * FROM member WHERE domain='$domainname'";
$result mysql_query($sql);
$myrow mysql_fetch_array($result);
?>
Even if a user exists, does not mean that they are active. If the user does not exist or is not active, we will return an error message.

<?php
if ($myrow["activeyn"]!="y"){
echo 
"This domain $domainname is not active";
exit;
}
?>
Retrieve the template
You can specify different template filenames for different users in their database record. The default template is 1.html . Templates should be stored in the same directory as the print.php script. Once opened, the template code is stored in the variable $body.

<?php
//Get template filename for this user from database
$filename $myrow["template"];
//Show the default template if necessary    
if ( !file_exists($filename) ) {
    
$filename "1.html";
}
//Open template file and store in variable $body

$fd fopen ($filename, &quot;rb&quot;);
$body fread ($fdfilesize ($filename));
fclose ($fd);
?>

« Previous Page
1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
|
10
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Jim Fletcher

Comment:



Comment:

(Maximum characters: 1200). You have characters left.