Skip to content

Instantly share code, notes, and snippets.

View smonteverdi's full-sized avatar

Sean Monteverdi smonteverdi

View GitHub Profile
@smonteverdi
smonteverdi / gist:1993937
Created March 7, 2012 15:55
PHP: Login Form
login_page.php
<form action="verify.php" method="post">
User Name:<br>
<input type="text" name="username"><br><br>
Password:<br>
<input type="password" name="password"><br><br>
<input type="submit" name="submit" value="Login">
</form>
verify.php
@smonteverdi
smonteverdi / gist:2378216
Created April 13, 2012 16:37
WordPress: Breadcrumbs
<?php
if (function_exists('register_sidebar')) {
register_sidebar(array(
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
}
@smonteverdi
smonteverdi / gist:1993940
Created March 7, 2012 15:56
PHP: Registration Form
<?php
if(isset($_POST['submit'])){
# connect to the database here
# search the database to see if the user name has been taken or not
$query = sprintf("SELECT * FROM users WHERE user_name='%s' LIMIT 1",mysql_real_escape_string($_POST['user_name']));
$sql = mysql_query($query);
$row = mysql_fetch_array($sql);
#check too see what fields have been left empty, and if the passwords match
if($row||empty($_POST['user_name'])|| empty($_POST['fname'])||empty($_POST['lname'])|| empty($_POST['email'])||empty($_POST['password'])|| empty($_POST['re_password'])||$_POST['password']!=$_POST['re_password']){
# if a field is empty, or the passwords don't match make a message
@smonteverdi
smonteverdi / gist:1993913
Created March 7, 2012 15:50
PHP: Check if user is logged in
functions.php
<?php
function loggedIn(){
//Session logged is set if the user is logged in
//set it on 1 if the user has successfully logged in
//if it wasn't set create a login form
if(!$_SESSION['loggd']){
echo'<form action="checkLogin.php" method="post">
<p>
@smonteverdi
smonteverdi / gist:1993945
Created March 7, 2012 15:57
PHP: Upload Image and Create Thumbnail
<?
if ($_REQUEST['action']=="add"){
$userfile = $HTTP_POST_FILES['photo']['tmp_name'];
$userfile_name = $HTTP_POST_FILES['photo']['name'];
$userfile_size = $HTTP_POST_FILES['photo']['size'];
$userfile_type = $HTTP_POST_FILES['photo']['type'];
/////////////////////////
//GET-DECLARE DIMENSIONS //
@smonteverdi
smonteverdi / gist:1993918
Created March 7, 2012 15:51
PHP: Connect to Database mysql way
<?php
$username = "your_name";
$password = "your_password";
$hostname = "localhost";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
@smonteverdi
smonteverdi / gist:1993935
Created March 7, 2012 15:54
PHP: Log Out Inactive User
This takes 3 functions to complete the inactive session task.
1. We need to check if the person is actually logged in using our isLogged function
2. We need the function to check the time the page loaded, and when the last page was loaded
3. We need a function to log the user out after inactivity.
It is reccomended that you place the 3 functions in the same file, and have this file
included on EVERY page that requires a login to view the page.
Function sessionX() MUST come after session_start()
@smonteverdi
smonteverdi / gist:2822016
Created May 29, 2012 01:14
jQuery: Display favicon next to external link
$("a[href^='http']").each(function() {
$(this).css({
background: "url(http://www.google.com/s2/u/0/favicons?domain=" + this.hostname +
") left center no-repeat",
"padding-left": "20px"
});
});
@smonteverdi
smonteverdi / gist:3440448
Created August 23, 2012 19:08
jQuery: Get URL Variable
$.urlParam = function(name){
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results[1] || 0;
}
// example.com?param1=name&param2=&id=6
$.urlParam('param1'); // name
$.urlParam('id'); // 6
$.urlParam('param2'); // null
@smonteverdi
smonteverdi / gist:3428075
Created August 22, 2012 18:14
CSS: Prevent Text Breakouts
.prevent-text-breakouts {
-ms-word-break: break-all;
word-break: break-all;
word-break: break-word;
-webkit-hyphens: auto;
-moz-hyphens: auto;
hyphens: auto;
}