Jump to content

Sharing website scripts


Recommended Posts

Directory Sweeper Script

 

This is a simple php script that will delete files in a directory by age. You can change how old the file has to be before it gets deleted. The way I use this is on a cron job and sometimes I use it as an include at the bottom of the page. The script is written to go inside the directory below the "tmp" but you can change that.

 

<?php
### Directory Sweeper ###
# create directory resource and read it 
# directory to delete files
$dir = "tmp/";
$directory = opendir("$dir"); 
while (true == ($file = readdir($directory))) 
{ 
# but don't read the links to directories 
if ( is_file("$dir/$file") ) 
{ 

# find out when it was created 
$created_time = filemtime("$dir/$file"); 

# $age = present time-$created_time 
$age = time()-filemtime("$dir/$file"); 

# how many hours before file gets deleted
$hrs = 24;
$expire = 60*60*$hrs;

# delete if more than  $hrs old. 
# don't delete the indexe or .htaccess
if ( $age > $expire && !preg_match("@\.htaccess|index\.html@i", $file, $x) )
{ unlink("$dir/$file"); } 
} 
} 
closedir($directory); 
###############
exit;
?>

 

Like I said you can use this as an include on another page if you want like this:

 

<?php
include("sweeper.php");
?>

 

That way anytime somebody clicks onto your page your sweeper script checks for old files and deletes them.

 

Link to comment
Share on other sites

Password Protection Without Logging In

 

If you have a password protected directory that you use just for yourself, this will keep you from logging in. Also if your on another machine that isn't yours it will prompt you for the password.

 

Just go to your cpanel and create a password protected directory like you normally would. Then you go to the directory's .htaccess and replace the code with this:

 

AuthName "Restricted Access"
AuthUserFile "/home/byron/.htpasswds/public_html/passwd"
AuthType Basic
Require valid-user
Order Allow,Deny
Allow from 172.17.10.1
Satisfy Any

 

Replace 172.17.10.1 with your ip address. You can also add more ips if you want by adding a new line like this:

 

Allow from 172.19.14.12

Allow from 172.27.60.01

Allow from 132.35.10.63

 

 

 

Link to comment
Share on other sites

  • 1 month later...

Found this on Google.

 

http://byrondallas.heliohost.org/temp/wap_redirect.txt

 

<?php
//Do not remove the below code. This will lead to voilation of Terms Of Use
/****************************************************************************
Copyright (C) <2009> <Dr. Anurag Singh>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
This script is written by Dr. Anurag Singh
Title: Wap Redirect
Version: 4.0
Email: tom.anu007@gmail.com,
Homepage: http://tom.anu007.googlepages.com/wapredirect
Special thanks to Harald Hope, Website: http://techpatterns.com/
And also to Joseph George Jacobs , Email joe@spitzbucket.com
Special thanks to Anna Rogers , Email missannalr@aol.com for PSP Browser support
--------------------------------------------------------------------------------
Latest Version (4.0) Wap Redirect Now Supports iPhone , PSP , WAP & usual PC browser Detection.
Now you can Support four Different websites (for PC, Mobile, iPhone & PSP) through a single Link version (4.0)
--------------------------------------------------------------------------------
Version 3.0 had some Dramatic but Desirable Changes in the Code Thanks to Alan Reiblein.
He had to say this
" The version (3.0) supports both PSP & WAP bowser Detection along with
usual PC browser detection in the same script. So now you can support three different websites (for PC , Mobile & PSP)
through a single link Version(3.0)
Some changes made to check for WAP before anything else
Will also check what doument types the user's browser can accept
also some slight tweaking by using an array of identities to match against the User Agent string 
Alan Reiblein EMail alan@cedar-view.co.uk Website Http://www.cedar-view.co.uk
Updated as many WAP Browser identities I could find "
--------------------------------------------------------------------------------
iPhone support by Ben Lopez benlopez7@gmail.com
****************************************************************************/
//Configuration
global $userBrowser;
global $userAccept;
// Exit this area 

// Your wapsite
//enter the link you want user to be redirected in case of WML browser
$wmllink = "http://wap.yahoo.com/";
// Your website
//enter the link you want user to be redirected in case of PC browser
$htmllink = "http://www.google.com";
// Your PSPsite
//enter the link you want user to be redirected in case of PSP browser
$psplink = "http://www.yourPSPsite.com";
// Your iPhone site
//enter the link you want user to be redirected in case of iPhone browser
$iPhonelink = "http://www.iphone-site.com";

//end of your edits
//There is no need to edit any information from this point on
//however in case if you want to contribute please do so
//please be sure to let me know about the changes
//Detect the browser
// put in lowercase to aid searching
$userBrowser = strtolower($_SERVER['HTTP_USER_AGENT']); 
//Detect acceptable document types
$userAccept= strtolower($_SERVER['HTTP_ACCEPT']);

//Remove the below // quotes.

//It helps to check if there is any error when editing
//If everything is all right it will display the browser information
//please remember to put // back after testing or no redirection will occur
//echo "HTTP_USER_AGENT = " . $userBrowser . "<br>HTTP_ACCEPT = " . $userAccept;


function checkidentity($fromThis,$identities){
//this function iterates through the array identities matching to see if in the $fromThis string
// returns true if found otherwise false
  foreach ($identities as $identity) {
        if (stristr($fromThis,$identity)){
          //found
          return true;
        }
  }
  //not found
  return false;
}


if (stristr($userAccept,'wml')) {
   // This can accept wml (Wireless Meta Language files) so let's assume its WAP)
   // trouble is accept can contain wildcards ... but here we go
   $ub="WML";
   }
else {
// Lets look at the browser
//specify an array of identities to match against
$wapidentity = array('wapbrowser','up.browser','up/4','mib','cellphone','go.web',
                     'nokia','panasonic','wap','wml-browser','wml'
                     );// can add other identities to this list
$pcidentity = array(
                'mozilla','gecko','opera','omniweb','msie','konqueror','safari',
                'netpositive' ,'lynx' ,'elinks' ,'links' ,'w3m' ,'webtv' ,'amaya' ,
                'dillo' ,'ibrowse' ,'icab' ,'crazy browser' ,'internet explorer' 
                ); // can add other identities to this list
$pspidentity= array('PlayStation Portable'); //can add other identities to this list
$iPhoneidentity= array('iphone'); //can add other identities to this list
if (checkidentity($userBrowser,$wapidentity)){
  $ub="WML";
  }
elseif (checkidentity($userBrowser,$iPhoneidentity)){
  $ub="iphone";
  }
elseif (checkidentity($userBrowser,$pspidentity)){
  $ub="PSP";
  }
elseif (checkidentity($userBrowser,$pcidentity)){
  $ub= "PC";
  }
else {
  $ub="WML"; // can't find anything else so let's hope it is WML 
}
}



//Code for redirecting based upon the results
switch ($ub){
  case 'PC':
    header("Location: ".$htmllink);
    exit;
  case 'WML':
    header("Location: ".$wmllink);
    exit;  
  case 'PSP':
    header("Location: ".$psplink);
    exit;
  case 'iphone':
    header("Location: ".$iPhonelink);
  exit;
  }
?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...