tri_94 Posted August 30, 2012 Posted August 30, 2012 hi there currently working away on Moodle VLE for my School just trying to tidy up some parts. and i would really like to loss some of the links i currently have. so im after a bit of magic in the form of php coding to enable me to say if local url then goto one address if external goto a different address please help thanks nick
danbuntu Posted August 30, 2012 Posted August 30, 2012 You're probably better doing this kind of think in the .htacess file. htaccess Redirect
tri_94 Posted August 30, 2012 Author Posted August 30, 2012 hi there what it is that we have drop down menus with hyperlinks, but rather then have loads one for external and one for internal everything, we wanted to replace them with a single one for each link. and use the power or php/html to check which url the user is on and there direct them accordly. any ideas?
danbuntu Posted August 30, 2012 Posted August 30, 2012 are the internal and external links linking to the same things? ie are you using something like moodle.college.ac.uk for one and moodle.local for the other? or are they going to completely separate sites? ie moodle.college.ac.uk for one and google.co.uk for the other?
tri_94 Posted August 30, 2012 Author Posted August 30, 2012 Think i've got it sorted now. using the following php code. E-mail thanks nick
mdench Posted August 30, 2012 Posted August 30, 2012 Could not use a DNS record to redirect the users internally instead of them going out and then back in?
danbuntu Posted August 30, 2012 Posted August 30, 2012 Think i've got it sorted now. using the following php code. E-mail thanks nick $CFG->wwwroot is the moodle url as set in your config file, so that code will always return true. you want to use the global $_SERVER variable: PHP: $_SERVER - Manual ; something like if ($_SERVER['SERVER_NAME'] == 'mydomian.co.uk') { echo 'url1'; } else { echo 'url2'; }
CESIL Posted August 30, 2012 Posted August 30, 2012 Have a look at the tag HTML base tag You can use the PHP $_SERVER to check the server that a user is accessing from and then set the default base path accordingly. This will then affect all relative links on the page. if ($_SERVER['SERVER_NAME'] == 'mydomain.co.uk') { echo ""; } else { echo ""; } This should be in the section of the page.
Marci Posted August 31, 2012 Posted August 31, 2012 (edited) Install Net_IPv4 via Pear (Net_IPv4), then whack the following somewhere before where you want the link... (eg: in Moodle's config.php) require 'Net/IPv4.php'; $ip = $_SERVER['REMOTE_ADDR']; // Get user's IPv4 // Define all LAN/LOCAL IP ranges... $net1 = '172.16.96.0/21'; // Curriculum Range $net2 = '10.113.140.0/24'; // Admin Range $CFG->localuser=4; if ((Net_IPv4::ipInNetwork($ip, $net1)=='1') || (Net_IPv4::ipInNetwork($ip, $net2)=='1')){ $CFG->localuser=1; } then, for the link... echo 'Linky Text'; (I think) Edited August 31, 2012 by Marci
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now