#native_company# #native_desc#
#native_cta#

Creating a Printer Version Grab Method Page 5

By Jim Fletcher
on 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);

?>



1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
|