Jump to content

quick tip for testing on live website


diogo
 Share

Recommended Posts

A very simple tip, but that might be useful for someone that didn't think of it...

This is what I usually do if I want to change something on a live site.

if($user->name!='diogo'){
  // live code
}else{
  // my new code
}

Like this I'm the only one that sees the changes.

More examples:


// test new javascript. do the same for styles

<?php if ($user->name!='diogo'){?>
<script src="<?php echo $config->urls->templates?>scripts/main.js"></script>
<?php }else{?>
<script src="<?php echo $config->urls->templates?>scripts/main-dev.js"></script>
<?php }?>

// test new head file

if($user->name!='diogo'){
  include(head.inc);
}else{
  include(head-dev.inc):
}

and so on...

edit: corrected the first block by Nik's suggestion

  • Like 15
Link to comment
Share on other sites

Greetings diogo,

Excellent idea.

This got me thinking...

It seems the concept could be expanded systamatically. I'm still working it out, but I'm imagining a system that detects development/testing elements. Maybe a way to tag certain CSS classes/IDs and place development JQuery plugins inside a specified folder? Then you could have a ProcessWire conditional that checks to see if certain CSS is present, or if there are any JQuery plugins inside that specified folder. If yes, the developer elements would happen; if no, then the "regular" site elements happen.

I like this!

Thanks,

Matthew

  • Like 1
Link to comment
Share on other sites

if($user->name!='diogo'){
// my new code
}else{
// live code
}

Sorry, I just have to point this out: don't you have the blocks here the wrong way around?

Everyone probably gets the point and corrects this automatically though - as you did with the latter examples yourself :). Unless they just copy and paste the first snippet and go from there...

  • Like 4
Link to comment
Share on other sites

@Nik, you are right of course. Already changed it.

@Matthew, seems interesting but I really like to keep it simple and adapted to each situations need. What you are asking can be closely achieved by creating a "dev" folder inside the templates folder and copying there your styles and scripts folders. Then, put this line on the top your header.php:

if ($user->name == 'me') $config->urls->templates .= "dev/";
  • Like 4
Link to comment
Share on other sites

I do the exact same as this quite a lot - obviously if you're tweaking things on a live site a lot and there are lots of visitors it's not ideal as if someone loads the page when you're just uploading a template change and you're doing this quite a lot they'll possibly get an error.

I'm doing it all the time on a site at the mo though as it's not open yet - it's in maintenance mode anyway using my module (cheap plug :D).

  • Like 2
Link to comment
Share on other sites

The reason I like these kind of snippets so much is the freedom they offer.

If you want to show the dev page to anyone that is logged in, change the conditional to:

if($user->name='guest')

If you want to give a special url like domain.com/?version=dev change it to:

if($input->get->version!='dev')

with the url version you can also make all the links work wth sessions like this:

if($input->get->version!='dev' OR $session->version != 'dev')

and inside the else:

$session->version = 'dev';
  • Like 7
Link to comment
Share on other sites

  • 1 year later...

Pete, in this case you could include a file conditionally like with the "head-dev.inc" diogo mentioned

so your changing the main template only once  ;)

oh, pretty old here..but maybe still helpful for someone

Link to comment
Share on other sites

  • 1 year later...

I realize this thread is beyond old, but I have a related question. I want to bring up a new domain name and migrate my dev site to it, but I don't want it to be visible to the public yet. What I would like to have is a "COMING SOON" image shown to everyone who browses into that domain (the domain name has already been published by the client), yet still allow those 'in the know' to peruse the entire dev site. I can do this by sniffing for the IP address of the visitor, right? Would something like this work in head.inc?

<?php

$allowed = array('ip address 1', 'ip address 2', etc);

if (!in_array($_SERVER['HTTP_CLIENT_IP']), $allowed) { header("Location: http://example.com/maintenance.html"); exit(); }

?>

Link to comment
Share on other sites

I've looked at the module, and I'd like it to be more passive than that. Plus, instead of confronting visitors with a login screen, I'd rather give them some information.  In fact, this code in head.inc seems to work nicely -

$allowed = array('192.168.1.0','192.168.1.1');
$ip = $_SERVER['REMOTE_ADDR'];
if (!in_array($ip, $allowed)) {
    header("Location: http://example.com/maintenance.html");
    exit();
}

  • Like 2
Link to comment
Share on other sites

  • 3 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...