stillmovingdesign

"Is it me you're looking for?"

Serve a different CSS file based on your IP address.

I can’t remember where I pinched this bit of PHP up from – which is bad of me – so I’m logging it here for my own reference. Sometimes I need to work on some CSS on a live site. That’s not exactly good practice especially on a busy site. So here’s what I use to serve a different stylesheet if the server sees my IP address. Once I’m happy with my changes I just copy the new CSS into the current file and remove the code below from my header.

<?
$visitor = $_SERVER['REMOTE_ADDR'];
if (preg_match("/00.000.00.00/",$visitor)) {
      echo "<link rel='stylesheet/css' href='style_new.css' type='text/css' />";} 
else {
      echo "<link rel='stylesheet/css' href='style.css' type='text/css' />";};

Replace the noughts with your IP address.

Comment via Twitter…

© 2001—2012 stillmovingdesign|Built with Coda & ProcessWire on a Mac|RSS|LinkedIn|Follow me on twitter