Daily Web Snippet

codemonkey

Code monkey not crazy, just proud.
Reaction score
66
2my6phs.png

In this lovely thread I'll be posting a code snippet each day that involves doing something on your website.

subscribe

Snippets of code may be in (X)HTML, CSS, JavaScript or PHP. If you would like to see another language sometimes you can contact me via PM.

To use these snippets you'll need at least a basic understanding of the language the snippet is for.

You may also wish to check out the Daily Web Snippet pastebin.

Index:

  1. Force IE8 to parse as IE7
  2. Make a minimum width
  3. Run code for specific IP Addresses
  4. Detect browsers
  5. Fake a 404
  6. Change Element Content (innerHTML)
 

codemonkey

Code monkey not crazy, just proud.
Reaction score
66
Force IE8 to parse as IE7

2eelau8.png

Code:
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
Syntax Highlighting

34q79y8.png

HTML (?)

2vv883t.png

Forces Internet Explorer 8 to parse HTML and CSS as Internet Explorer 7 does.

n6zucx.png

You put the snippet in the <head> section of your HTML document.

2iqo5yw.png

This only works for Internet Explorer 8 users, Internet Explorer 7 through 1 users (and other browser users) will not be changed.
 

UndeadDragon

Super Moderator
Reaction score
447
Why would you want to force an internet browser, which works properly, to not work properly?
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
IE is most likely going to display it incorrectly anyway.
 

UndeadDragon

Super Moderator
Reaction score
447
IE8 isn't too bad. It's better than IE7 and below.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
Still. If the syntax is built for 7, and doesn't work correctly in 8, you can add that rather than rewrite all of the code.
 

codemonkey

Code monkey not crazy, just proud.
Reaction score
66
Make a minimum width

2eelau8.png

Code:
body {
 min-width: XXXpx !important;
}
Syntax Highlighting

34q79y8.png

CSS (?)

2vv883t.png

Users with a screen width smaller than you specify get a horizontal bar at the bottom of their browser, often used for making web pages not break on small screens.

n6zucx.png

You put the snippet in your CSS stylesheet.

2yo7o61.png

You must change 'XXX' to your desired minimum width in pixels.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
You'd need an HTML form, along with JavaScript to save a cookie for that, I think.
 

UndeadDragon

Super Moderator
Reaction score
447
You'd need an HTML form, along with JavaScript to save a cookie for that, I think.

Actually, you would need PHP (and SQL).
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
I don't think you'd need PHP + SQL.
Just an HTML form to submit the information, and a JavaScript cookie to set that the user is logged in, and a function to check if they're logged in.
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
608
I don't think you'd need PHP + SQL.
Just an HTML form to submit the information, and a JavaScript cookie to set that the user is logged in, and a function to check if they're logged in.
He did ask for "A user-login system in PHP + MySQL. "

So PHP and MYSQL must be used...:rolleyes:
 

UndeadDragon

Super Moderator
Reaction score
447
How would you know what the username/password was if you don't access a database?
 

codemonkey

Code monkey not crazy, just proud.
Reaction score
66
Run code for specific IP Addresses

2eelau8.png

PHP:
<!-- First part -->
<?php
$safe_ip = array();
$safe_ip[0] = "127.0.0.1"; // Change this to the admin IP
// Add any extra IPs here in the format of the above one
?>

<!-- Second part -->
<?php
// Place the below code wherever you want to do admin-only stuff
if (in_array($_SERVER["remote_addr"], $safe_ip))
{
  // Do admin stuff
}
else
{
 // Do normal stuff
}
?>

34q79y8.png

PHP (?)

2vv883t.png

Allows your site to do admin IP verification, executing code for only certain IPs.

n6zucx.png

You put the first part above everything else and the second part where needed.

2iqo5yw.png

Pros
  • Impossible to hack into without going onto your internet connection
  • Multiple IPs allowed
Cons
  • Admin access would be given to anybody on your internet connection
  • If your IP (or any other IP listed) changes you'll have to change this code too, or have it auto update with another script

Protip: Use this in combination with a password if you have a Static IP.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top