Web Dev Questions That Don't Need Their Own Thread v4
5,001 replies, posted
[QUOTE=Fizzadar;39782231]There's absolutely nothing wrong with using %'s as margins.
What if you want 3 flexible columns with horizontal borders between - you [i]need[/i] % margins, padding & width.[/QUOTE]
I should elaborate on what I meant. If you're trying to center content, percentage margins are a bad idea. That's all.
What's the best way to make javascript navigation based on the hashtag? ie.
<a href="#admin/users/list">List Users</a>
clicking that would do a GET request in jQuery to "/get/admin/users/list"
[code]
$('a[href^=#]').click(function(){
$.get($(this).attr('href').replace("#",""), function(data){
//
});
});
[/code]
Something along those lines?
Much easier than I thought, thanks!
(I'm probably just going to use $(this).attr('href').substr(1) instead of filtering all of the # symbols, just in case)
You have no browser history like that though.
[editline]3rd March 2013[/editline]
I suggest to rather use something like this: [url]http://stackoverflow.com/questions/3090478/jquery-hash-change-event[/url]
Or even better, SammyJS so you don't have to worry about anything.
Anyone have a tutorial for an image slideshow/gallery or images that when you click on them they 'enlarge'? Google is failing me, its only coming up with navigation menus
If you're using a MySQL database for a forum, would it be faster to write a field to a thread for the last post and update that every new post or instead use a query over the whole posts table to find the last post in that thread when the page gets served?
I heard that PHP isn't used so much these days? What is the new thing? ASP.NET?
[QUOTE=AlienCat;39793827]I heard that PHP isn't used so much these days? What is the new thing? ASP.NET?[/QUOTE]
PHP [b]is[/b] used a lot these day, that's the problem ;)
Hey working on a PHP Hash with bcrypt.
[CODE]
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="email" id="email" required>
<input type="password" name="password" required>
<input type="submit" name="submit" value="Lähetä">
</form>
<?php
//ini_set("display_errors","1");
//ERROR_REPORTING(E_ALL);
CRYPT_BLOWFISH or die ('No Blowfish found.');
$link = mysql_connect('localhost', 'root', '')
or die('Not connected : ' . mysql_error());
mysql_select_db('bcrypt', $link)
or die ('Not selected : ' . mysql_error());
if(isset($_POST['submit'])) {
$password = mysql_real_escape_string($_POST['password']);
$email = mysql_real_escape_string($_POST['email']);
echo $email;
//This string tells crypt to use blowfish for 5 rounds.
$Blowfish_Pre = '$2a$05$';
$Blowfish_End = '$';
// Blowfish accepts these characters for salts.
$Allowed_Chars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./';
$Chars_Len = 63;
$Salt_Length = 21;
$mysql_date = date( 'Y-m-d' );
$salt = "";
for($i=0; $i<$Salt_Length; $i++)
{
$salt .= $Allowed_Chars[mt_rand(0,$Chars_Len)];
}
$bcrypt_salt = $Blowfish_Pre . $salt . $Blowfish_End;
$hashed_password = crypt($password, $bcrypt_salt);
$sql = 'INSERT INTO users (reg_date, email, salt, password) ' .
"VALUES ('$mysql_date', '$email', '$salt', '$hashed_password')";
mysql_query($sql) or die( mysql_error() );
}
?>
[/CODE]
Is this safe?
oh and the database connection is just my local testing one.
oh the email echo is for testing aswell.
[QUOTE=j4NZKUE;39794561]Hey working on a PHP Hash with bcrypt.
[CODE]
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="email" id="email" required>
<input type="password" name="password" required>
<input type="submit" name="submit" value="Lähetä">
</form>
<?php
//ini_set("display_errors","1");
//ERROR_REPORTING(E_ALL);
CRYPT_BLOWFISH or die ('No Blowfish found.');
$link = mysql_connect('localhost', 'root', '')
or die('Not connected : ' . mysql_error());
mysql_select_db('bcrypt', $link)
or die ('Not selected : ' . mysql_error());
if(isset($_POST['submit'])) {
$password = mysql_real_escape_string($_POST['password']);
$email = mysql_real_escape_string($_POST['email']);
echo $email;
//This string tells crypt to use blowfish for 5 rounds.
$Blowfish_Pre = '$2a$05$';
$Blowfish_End = '$';
// Blowfish accepts these characters for salts.
$Allowed_Chars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./';
$Chars_Len = 63;
$Salt_Length = 21;
$mysql_date = date( 'Y-m-d' );
$salt = "";
for($i=0; $i<$Salt_Length; $i++)
{
$salt .= $Allowed_Chars[mt_rand(0,$Chars_Len)];
}
$bcrypt_salt = $Blowfish_Pre . $salt . $Blowfish_End;
$hashed_password = crypt($password, $bcrypt_salt);
$sql = 'INSERT INTO users (reg_date, email, salt, password) ' .
"VALUES ('$mysql_date', '$email', '$salt', '$hashed_password')";
mysql_query($sql) or die( mysql_error() );
}
?>
[/CODE]
Is this safe?
oh and the database connection is just my local testing one.
oh the email echo is for testing aswell.[/QUOTE]
[URL="https://gist.github.com/nikic/3707231"]Use this instead[/URL]
[QUOTE=HTF;39794766][URL="https://gist.github.com/nikic/3707231"]Use this instead[/URL][/QUOTE]
oh thanks :) but is there any faults in my code or is it usable?
[QUOTE=j4NZKUE;39794953]oh thanks :) but is there any faults in my code or is it usable?[/QUOTE]
I don't see any obvious security flaws. Generally I would use something like current unix timestamp to generate the salt. Your way is a tad convoluted for no gain. I'd also do 10 rounds not 5 but that depends on your hardware more than anything. Mess with the number of rounds to see what gives the desired length of time to process, you don't want it too fast or too slow.
Also, you should use [URL="http://www.php.net/manual/en/book.mysqli.php"]MYSQLi [/URL]or [URL="http://www.php.net/manual/en/ref.pdo-mysql.php"]PDO[/URL]. mysql_ is deprecated, and is not so secure.
Okay, thanks guys going to use PDO and do some tests with the rounds and clean up my code a bit :) and probably test the password hashing api too
EDIT: A bit late, didn't see a new page.
I'd use something like the [URL="http://www.openwall.com/phpass/"]Portable PHP password hashing framework[/URL] or [URL="https://github.com/ircmaxell/password_compat"]password_compat[/URL] (going to be implemented in PHP 5.5) if you have PHP >= 5.3.7.
You should probably increase the number of rounds to something like 10 as well as 5 isn't that significant.
5 rounds took around 0.002 seconds~ on my web server whereas 10 rounds took around 0.12~ seconds. I personally would aim for something between 0.1 and 0.5 seconds.
Social networking site (don't ask):
[img]http://www.facepunch.com/fp/ratings/tick.png[/img] Existing CMS
[img]http://www.facepunch.com/fp/ratings/information.png[/img] MVC framework
[img]http://www.facepunch.com/fp/ratings/wrench.png[/img] Build from scratch
[QUOTE=Vietnow;39799196]Social networking site (don't ask):
[img]http://www.facepunch.com/fp/ratings/tick.png[/img] Existing CMS
[img]http://www.facepunch.com/fp/ratings/information.png[/img] MVC framework
[img]http://www.facepunch.com/fp/ratings/wrench.png[/img] Build from scratch[/QUOTE]
Depends on how big you expect the site to grow, and how much work you want to do.
How do you add jquery script to something?
I have this in my html document
[CODE]$(document).ready(function() {
$(".fancybox-thumb").fancybox({
prevEffect : 'none',
nextEffect : 'none',
helpers : {
title : {
type: 'outside'
},
thumbs : {
width : 50,
height : 50
}
}
});
});
[/CODE]
and I'm trying to add a no right click script
[CODE]$(".fancybox")
.attr('rel', 'gallery')
.fancybox({
beforeShow: function () {
/* Disable right click */
$.fancybox.wrap.bind("contextmenu", function (e) {
return false;
});
}
});[/CODE]
and the html
[HTML]<a title="Tinie Tempah CD Cover Illusions" class="fancybox-thumb" rel="fancybox-thumb" href="work\tinie_b.jpg"><img src="work\tinie_s.jpg" alt="" /></a>
<a title="Supra Shoe Logo" class="fancybox-thumb" rel="fancybox-thumb" href="work\supra_b.jpg"><img src="work\supra_s.jpg" alt="" /></a>[/HTML]
My teacher is apparently forcing us to not use Sublime Text 2 because "it's free but not open source"
Any suggestions to convince him to let us use it or some editors that I don't hate with a burning passion (hi notepad++)
[QUOTE=Banana Lord.;39807658]My teacher is apparently forcing us to not use Sublime Text 2 because "it's free but not open source"
Any suggestions to convince him to let us use it or some editors that I don't hate with a burning passion (hi notepad++)[/QUOTE]
Try "Just fuckin' teach the goddamn stuff and shut up"
[QUOTE=Banana Lord.;39807658]My teacher is apparently forcing us to not use Sublime Text 2 because "it's free but not open source"
Any suggestions to convince him to let us use it or some editors that I don't hate with a burning passion (hi notepad++)[/QUOTE]
How's he gonna notice what you use as a text editor.
[QUOTE=xianlee;39807441]How do you add jquery script to something?
[/QUOTE]
[code]
<script>
///the script here
</script>[/code]
Assuming you have jQuery already added.
[QUOTE=asantos3;39807770]Try "Just fuckin' teach the goddamn stuff and shut up"[/QUOTE]
Thát's not going to go down well.
Just ignore and carry on.
[QUOTE=Banana Lord.;39807658]My teacher is apparently forcing us to not use Sublime Text 2 because "it's free but not open source"
Any suggestions to convince him to let us use it or some editors that I don't hate with a burning passion (hi notepad++)[/QUOTE]
What could possibly make you prefer notepad++ to sublime?
[QUOTE=KmartSqrl;39808529]What could possibly make you prefer notepad++ to sublime?[/QUOTE]
Think you misinterpreted his post.
[QUOTE=mobrockers2;39808017]How's he gonna notice what you use as a text editor.[/QUOTE]
because when he comes by to help people he looks at nearby screens
Oh wait I missed a "not" haha
[QUOTE=SataniX;39808031][code]
<script>
///the script here
</script>[/code]
Assuming you have jQuery already added.[/QUOTE]
I have it added but its not applying the changes :S
[QUOTE=xianlee;39809883]I have it added but its not applying the changes :S[/QUOTE]
Any console errors?
Have you included jQuery?
Is there actually a .fancybox element?
Sorry, you need to Log In to post a reply to this thread.