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
609
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.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top