php - Login automatic using session_start(); and detect network -


hey i'm thinking 3 days of solution login scipt login people specific network automaticly. can't figure out :)

this part of index script use people can login manually

<?php  session_start();  if (session_is_registered("example")) {  require('./log_header.php');  } else {  header( 'location:  pre.php' ) ;  } ?> 

but want users connected through specific network [10.92.80.1] don't have login :)

plz :)

thanks!


solution

firts of fast responses! :)

it's working now. here's code used, :)

if (session_is_registered("example")) {

require('./header.php'); require('scripts/members.php');

}

elseif (strripos(gethostbyaddr($_server['remote_addr']), ".kulnet.kuleuven.be")) {

require('./header.php'); require('scripts/members.php');

} else {

header( 'location: login.php' ) ;

} ?>

thanks again! :)

knowing server not located within private network, it's still little more complicated seems. there's helpful network functions can use though.

step 1:
put script somewhere burried within site know url to:

<?php echo gethostbyaddr($_server['remote_addr']); ?> 

step 2:
open above page in browser while browsing from within private network. give outfacing hostname of network. write down last qualified hostname part (ie, out of "436-2-x235.myuniversity.com", want ".myuniversity.com". or maybe has "mydorm.myuniversity.com" in it, can filter down dorm). hostname written down, can delete above file. reason getting network hostname external ip address of network may unexpectedly change either because of isp reassignment or university switching users through different exit point.

step 3:
change code in login check this...

if (strripos(gethostbyaddr($_server['remote_addr']), ".myuniversity.com")) {     // client in private network     } else {     // client _not_ in private network     } 

some caveats: client's remote address not reliable due proxies or spoofing. if proxying through network, may student there.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -