Checking and displaying the user’s IP with PHP

0Comments

This quick, yet very useful snippet harnesses the power of PHP and it’s superglobals.

 
<?php
 
$ip = $_SERVER['REMOTE_ADDR']; 
 
echo "<p>Your IP address is: <strong>$ip</strong></p>";
 
?>

View Demo

Fading images with jQuery

0Comments

All you have to do to implement this jQuery, is put an image inside a div with an ID of someImage.

$("#someImage").hover(function(){
 
    $(this).find("img").fadeOut();
 
}, function() {
 
    $(this).find("img").fadeIn();
 
})

Password protecting a page with PHP

0Comments

This password protects a single page whereas the use of .htaccess only protects folders.

<?php
 
 
 
// Define your username and password
 
$username = "someuser";
 
$password = "somepassword";
 
 
 
if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) {
 
 
 
?>
 
 
 
<h1>Login</h1>
 
 
 
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
 
    <p><label for="txtUsername">Username:</label>
 
    <br /><input type="text" title="Enter your Username" name="txtUsername" /></p>
 
 
 
    <p><label for="txtpassword">Password:</label>
 
    <br /><input type="password" title="Enter your password" name="txtPassword" /></p>
 
 
 
    <p><input type="submit" name="Submit" value="Login" /></p>
 
 
 
</form>
 
 
 
<?php
 
 
 
}
 
else {
 
 
 
?>
 
 
 
<p>This is the protected page. Your private content goes here.</p>
 
 
 
<?php
 
 
 
}
 
 
 
?>

Force files to download using .htaccess

1Comments

This snippet comes in handy if you are tired of putting things in .zip formats for people to download.

AddType application/octet-stream .csv
AddType application/octet-stream .xls
AddType application/octet-stream .doc
AddType application/octet-stream .avi
AddType application/octet-stream .mpg
AddType application/octet-stream .mov
AddType application/octet-stream .pdf

Add other file types accordingly.

Checking if an image has loaded

0Comments
$('#theImage').attr('src', 'theimage.png').load(function() {  
alert('Image Has Loaded!');  
});

Make an entire div clickable with jQuery

1Comments

jQuery

$("someDiv").click(function(){
     window.location=$(this).find("a").attr("href");
     return false;
});


HTML

<div id="someDiv">
     This is some of the div's content.
    <a href="http://google.com">The Link</a>
</div>

Getting your latest twitter status using PHP

0Comments
<?php
 
function getTwitterStatus($userid){
$url = "http://twitter.com/statuses/user_timeline/$userid.xml?count=1";
 
$xml = simplexml_load_file($url) or die("could not connect");
 
       foreach($xml->status as $status){
       $text = $status->text;
       }
       echo $text;
 }
 
 
getTwitterStatus("insert.twitter.username.here");
 
/*Put your twitter ID above in the brackets*/
 
?>

CSS Arrows

6Comments

Up

font-size: 0px; line-height: 0%; width: 0px;
border-bottom: 20px solid #0094ff; 
border-left: 10px solid #fff;
border-right: 10px solid #fff;

Down

font-size: 0px; line-height: 0%; width: 0px;
border-top: 20px solid #0094ff;
border-left: 10px solid #fff;
border-right: 10px solid #fff;

Read more…

CSS Text Shadow

1Comments
.someElement {
   text-shadow: 1px 1px 3px #fff;
}

Contact Form with PHP

0Comments

HTML

<form action="" method="post">
  <label for="Name">Name:</label>
  <input type="text" name="Name" id="Name" />
 
  <label for="Email">Email:</label>
  <input type="text" name="Email" id="Email" />
 
  <label for="Message">Message:</label><br />
  <textarea name="Message" rows="20" cols="20" id="Message"></textarea>
 
  <input type="submit" name="submit" value="Submit" />
</form>

Read more…

Sponsors

  • Ads by Yoggrt