Systems Developer/Engineer, Ohio State University Libraries * http://library.osu.edu/opensource/ * Last Updated 5/6/2008 * Automatically adds prepends proxy url to the link if the user is off campus * Copyright (C)2008 [James Muir] * 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 . *********************************************************/ /* * Check remote user's IP address and compare it to campus IP's * returns true or false if the IP is in the campus IP range */ function check_ip() { // Easy to debug by adding ?debug_off_campus=1 to the end of the url of the page being tested if(isset($_GET['debug_off_campus'])) { $campus_ips = array('000.000.000.000'); } else { // IP's can be any length, for example: 123.456 will match 123.456.xxx.xxx $campus_ips = array( '140.254', '128.146', '164.107' ); } // Get IP address of the user $user_ip=$_SERVER['REMOTE_ADDR']; // Assume off campus $on = false; foreach ($campus_ips as $ip){ if(substr($user_ip,0,strlen($ip)) == $ip) { $on = true; break; } } // finally return whether or not the user is using a campus IP return $on; } // Call to the function check_ip() and stores the result in $oncampus $oncampus = @check_ip() ? 'true' : 'false'; // print the result into a javacript variable on the page. After this, generic_offcampuscheck.js will take over. print << var oncampus = $oncampus; END; ?>