Web Dev Questions That Don't Need Their Own Thread v4
5,001 replies, posted
So a career question: I go to community college and plan to transfer to george mason university. This isn't a target school so I'm afraid it will hurt my career prospects. Going to CC may hurt my Internship prospects. What projects can I work on that will build my resume (moreso than small projects like small games) and what can I do to network better when my CC has no career fairs or recruiters or anything like that
edit: ah shit wrong questions thread
[QUOTE=Rocket;46975802]What kind of data does your API serve? There's a bunch of different solutions you could use.[/QUOTE]
[QUOTE=Svenskunganka;46975264]A VPS would be a good place to host it on. [URL="https://hosthatch.com/openvz-ssd-vps"]HostHatch[/URL] has 99.97% - 100% uptime and I got a couple of servers with them. The $4 package should bring you all the power you need. What language is the API written in and what kind of DB does it utilize (if any)?[/QUOTE]
It's in PHP and serves data from a MySQL database.
[QUOTE=Moofy;46976022]This[/QUOTE]
line-height:0px fixed it, thanks.
now my map for h1z1, made in javascript, works correctly.
heres an image
[img]http://i.imgur.com/HYzoQG3.jpg?1[/img]
What would be the easiest way to create a simple scraper that just pulls images off of say a 4chan thread? I wanna have a page on my project website where you can punch in a threads url or ID and it'll send you back thumbnails (with links) to all the images. I'm sure it's do-able, but I'm relatively new to this kind of thing, just making a site for funsies at the moment.
One option would be NodeJS with [url=https://www.npmjs.com/package/request]request[/url] and [url=https://github.com/cheeriojs/cheerio]cheerio[/url] to load the HTML with basic jQuery for finding the images
Just starting with PHP, coming form java and now c# how are passwords handled?
I mean, like passwords for a database, do you just write them right in the PHP code? Is that even safe?
What I've done now is following this link ([url]http://php.net/manual/en/function.password-hash.php[/url]) and generated a hash with this:
[code]<?php
$options = [
'cost' => 12,
'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM),
];
echo password_hash("my pass B)", PASSWORD_BCRYPT, $options)."\n";
?>[/code]
and test it with this:
[code]$password = $_POST["uploadpass"];
$hash = "long hash";
if(! password_verify($password, $hash)){
return;
}[/code]
[QUOTE=diwako;46993665]Just starting with PHP, coming form java and now c# how are passwords handled?
I mean, like passwords for a database, do you just write them right in the PHP code? Is that even safe?
What I've done now is following this link ([url]http://php.net/manual/en/function.password-hash.php[/url]) and generated a hash with this:
[code]<?php
$options = [
'cost' => 12,
'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM),
];
echo password_hash("my pass B)", PASSWORD_BCRYPT, $options)."\n";
?>[/code]
and test it with this:
[code]$password = $_POST["uploadpass"];
$hash = "long hash";
if(! password_verify($password, $hash)){
return;
}[/code][/QUOTE]
Store your passwords for databases outside of the web root, if your web server decides to serve the php file as plaintext (can happen), your passwords won't get leaked.
For user passwords stored in a db, hashing with scrypt/bcrypt/mcrypt is fine (in order of preference, scrypt is the best).
[QUOTE=diwako;46993665]Just starting with PHP, coming form java and now c# how are passwords handled?
I mean, like passwords for a database, do you just write them right in the PHP code? Is that even safe?
What I've done now is following this link ([url]http://php.net/manual/en/function.password-hash.php[/url]) and generated a hash with this:
[code]<?php
$options = [
'cost' => 12,
'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM),
];
echo password_hash("my pass B)", PASSWORD_BCRYPT, $options)."\n";
?>[/code]
and test it with this:
[code]$password = $_POST["uploadpass"];
$hash = "long hash";
if(! password_verify($password, $hash)){
return;
}[/code][/QUOTE]
Use [URL="https://github.com/ircmaxell/password_compat"]this[/URL] if you're using password_hash. It will detect what version PHP the server is running, if it runs PHP 5.5 it will use the native password_hash built in PHP. Otherwise it will use this library to do pretty much the same thing but for PHP >= 5.3.0.
Pretty good if you want to make sure this works on earlier versions too.
[QUOTE=diwako;46993665]Just starting with PHP, coming form java and now c# how are passwords handled?
I mean, like passwords for a database, do you just write them right in the PHP code? Is that even safe?
What I've done now is following this link ([url]http://php.net/manual/en/function.password-hash.php[/url]) and generated a hash with this:
[code]<?php
$options = [
'cost' => 12,
'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM),
];
echo password_hash("my pass B)", PASSWORD_BCRYPT, $options)."\n";
?>[/code]
and test it with this:
[code]$password = $_POST["uploadpass"];
$hash = "long hash";
if(! password_verify($password, $hash)){
return;
}[/code][/QUOTE]
Don't bother setting the salt manually. The password_hash function does this automatically (unless you have a good reason, eg, integrating with an existing system).
Of course, you may already know this, but if you plan to integrate this with an existing system, i'd highly recommend putting the password_hash function into a wrapper function, like so...
[CODE]
function password_new_hash($password)
{
$options = [
"cost" => 12
];
return password_hash($password, PASSWORD_BCRYPT, $options);
}
[/CODE]
Since it's likely you are going to use the same algorithm and cost for your entire project, this can simplify things later if you have to re-use the hashing function. You can do the same with password_verify. If want to compare a provided password with one stored in a database.
You've got a good hold on hashing, frankly, if i were you, make sure you're all brushed up on your HTTPS skills.
[video=youtube;nm-85-bDP6c]https://www.youtube.com/watch?v=nm-85-bDP6c[/video]
This video gives a good explanation of a common problem
Crossposting from the [url=http://facepunch.com/showthread.php?t=1446371&p=46957830&viewfull=1#post46957830]General What Do You Need Help With? thread[/url].
I'm currently designing a webapp that allows you to click on a button and choose from one of many options to fill that button with, which will then be assembled into a final image later as a collage of "favorites". What would be the best way to do this? My first thought was to make the group of buttons (hardcoded, not an array) with jQuery mobile that would push up a popup when clicked, but I couldn't figure out a way to take the selected item from the popup back to the button that was clicked. I'm still not entirely sure how to do it but I'm figuring an array of buttons with callback functions? But I'm still not entirely sure on how to implement that specifically.
Hey, i'm thinking about getting my first VPS as opposed to in the past whereas I've had just "Webservers". I'm going with one because of the possibility of switching it from a webserver to whatever else i want whenever i want a little project to work on, so basically would getting one of those $15/y VPS' from ramnode. would this be a good choice for just fiddling around for web development or am I about to make a huge mistake.
[editline]24th January 2015[/editline]
hopefully this was the right place to ask
I want to get into web development but don't want to use php, I want to use a normal language is this possible or something?
[QUOTE=eirexe;47007263]I want to get into web development but don't want to use php, I want to use a normal language is this possible or something?[/QUOTE]
Define a "normal language"... There are plenty really, nodejs, ruby, python, asp.net
[QUOTE=biodude94566;46997645]Crossposting from the [url=http://facepunch.com/showthread.php?t=1446371&p=46957830&viewfull=1#post46957830]General What Do You Need Help With? thread[/url].
I'm currently designing a webapp that allows you to click on a button and choose from one of many options to fill that button with, which will then be assembled into a final image later as a collage of "favorites". What would be the best way to do this? My first thought was to make the group of buttons (hardcoded, not an array) with jQuery mobile that would push up a popup when clicked, but I couldn't figure out a way to take the selected item from the popup back to the button that was clicked. I'm still not entirely sure how to do it but I'm figuring an array of buttons with callback functions? But I'm still not entirely sure on how to implement that specifically.[/QUOTE]
here's one way to do it without jquery at least. feel free to adapt it to jquery, or however you need it
i just extended the original answer i gave you to make this, and tried commenting at least a few of the lines
you sounded like you wanted a bunch of images, but i just used random colors for this demo
[url]http://xelivo.us/upload/ColorSelectorDemo.html[/url]
i'm bad coder but it works so~~~
source code incase i delete that file some day:
[code]<!DOCTYPE >
<html><head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<title>Color Selector Demo</title>
<style type="text/css">
body {
padding: 1em;
margin: 0;
}
#maincontent {
width: 450px;
}
#popup {
background-color: rgba(255,200,200,.8);
border: 1px solid rgb(225,180,180);
padding: 1em;
margin: 0;
z-index:10;
}
.center_both {
margin: inherit auto;
position: fixed;
left: 50%;
top: 50%;
transform: translate(-49.999%, -50%);
}
button {
cursor:pointer;
}
.collageButton {
width:150px;
height:150px;
border:0px;
}
.popupButton{
width:50px;
height:50px;
}
</style>
<script>
function createPopup(){
var popup = document.createElement("div");
popup.className = "center_both";
popup.id = "popup";
popup.style.display = "none" //default to hidden
//add the popup to the page
document.getElementById("maincontent").appendChild(popup);
//create some stuff to click on in the popup itself
for(var i = 0; i < 9; i++ ){
var butt = document.createElement("button");
butt.className = "popupButton";
//lazily choose a color based on the i value;
butt.style.background = "rgb(" + Math.floor(Math.random()*256) + "," + Math.floor(Math.random()*256) + "," + Math.floor(Math.random()*256) + ")";
//what happens when we click this button
butt.addEventListener('click', function(){
hidePopup();
var callback = document.getElementById(popup.dataset.callbackNode);
if(callback) { //if callback actually exists
//set our callback item to have the same background as our popup button
callback.style.background = this.style.background;
} else {
alert("critical error");
}
});
//attach the button to the popup
popup.appendChild(butt);
}
}
function showPopup(){
var popup = document.getElementById("popup");
popup.style.display = ""; //reset style of popup to not be "display:hidden;"
popup.dataset.callbackNode = this.id; //tell popup to store the id of who called this function
}
function hidePopup(){
// just make our popup hidden again
document.getElementById("popup").style.display = "none";
}
window.onload = function(){
createPopup(); //call our popup creation function
//create a bunch of testing buttons
for(var i = 0; i < 9; i++ ){
var butt = document.createElement("button");
butt.innerHTML = "Favorite Button " + (i+1);
butt.className = "collageButton"
butt.id = "favoriteButton"+ (i+1);
document.getElementById("maincontent").appendChild(butt);
butt.addEventListener('click', showPopup);
}
}
</script>
</head>
<body>
<div id="maincontent"></div>
</body></html>[/code]
[QUOTE=eirexe;47007263]I want to get into web development but don't want to use php, I want to use a normal language is this possible or something?[/QUOTE]
[QUOTE=Svenskunganka;47007309]Define a "normal language"... There are plenty really, nodejs, ruby, python, asp.net[/QUOTE]
In my book PHP is classified as a normal language, as are all off those. The only other class is joke languages such as brainfuck and lolcode.
All these languages have their quirks that people love or hate (I personally don't see ruby's appeal and can't stand python's whitespace). What it comes down to in the end is your setup. If you're on shared hosting you'll usually be limited to PHP, sometimes ASP. If you're in control of your own server you can pretty much use any language, some with more setup required than others.
[QUOTE=HeroicPillow;47008058]here's one way to do it without jquery at least. feel free to adapt it to jquery, or however you need it
i just extended the original answer i gave you to make this, and tried commenting at least a few of the lines
you sounded like you wanted a bunch of images, but i just used random colors for this demo
[url]http://xelivo.us/upload/ColorSelectorDemo.html[/url]
i'm bad coder but it works so~~~
source code incase i delete that file some day:
[code]code[/code][/QUOTE]
I could imaging some very extensive pixel art with this xD
[QUOTE=Goz3rr;47008345]In my book PHP is classified as a normal language, as are all off those. The only other class is joke languages such as brainfuck and lolcode.
All these languages have their quirks that people love or hate (I personally don't see ruby's appeal and can't stand python's whitespace). What it comes down to in the end is your setup. If you're on shared hosting you'll usually be limited to PHP, sometimes ASP. If you're in control of your own server you can pretty much use any language, some with more setup required than others.[/QUOTE]
Lenguages that are not focused on web, like c++ or Lua, but are more or less universal.
I would like to work in web development without learning a new language, is this even possible?
[QUOTE=eirexe;47008970]Lenguages that are not focused on web, like c++ or Lua, but are more or less universal.
I would like to work in web development without learning a new language, is this even possible?[/QUOTE]
At some point you're gonna be forced to learn a new language, but I don't see why that should be a problem? If you're passionate enough for development, new languages should be thrilling and fun to learn, not the other way around. After a while you'll get to the point where you can tell the difference and choose your own personal favorite - there's already too much this and that about different languages going on here so I'm not even going to bother suggesting one for you.
Either way Web Development consists of HTML, CSS and Javascript and those are the minimum requirements of what you need to know to develop web applications and even then those languages are enough. After that you can move on to databases and back-end languages but you just have to find what ever you feel most comfortable with. It's not more complicated than that. Nowadays you can develop the back-end in almost any language you feel like. Be it C++ or Lua.
Guys I have a "problem". I currently have SourceChatJS working on one server. However, it must be scalable (it'll have multiple nodes when needed, right now I just want one box). The idea is that I have a website application that spawns "worker applications" using some sort of Remote Procedure Call. Either way, server usage is an issue.
I currently have a Redis server, MySQL server and a ExpressJS website running on this machine, along with 3 other websites hosted using "forever". I'm not sure how much overhead forever gives, either way, I want to get some advice on how I could best make all these worker threads.
Currently, all the worker threads do is receive UDP packages, parse it, send the output over websockets to the clients. I want to make it some sort of set up like this:
[img]http://i.imgur.com/3OP3qn7.png[/img]
Would I be looking at more memory, looking at more cores? I'm trying to find out what's the most efficient. Should I handle all servers in one application or spawn a seperate application for one server? Answers are appriciated
[QUOTE=HeroicPillow;47008058]here's one way to do it without jquery at least. feel free to adapt it to jquery, or however you need it
i just extended the original answer i gave you to make this, and tried commenting at least a few of the lines
you sounded like you wanted a bunch of images, but i just used random colors for this demo
[url]http://xelivo.us/upload/ColorSelectorDemo.html[/url]
i'm bad coder but it works so~~~
source code incase i delete that file some day:
[code]code[/code][/QUOTE]
Well hot damn, man. I was expecting just some ideas and guidance on what to do, not a full solution. Thank you [i]so[/i] much, you're a massive help!
How do I set a header to cache an image made with GD to expire after a certain amount of time? Right now, I have my headers set to this:
[code] Header('Content-type: image/png');
Header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
Header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
Header('Pragma: no-cache'); [/code]
What would I change to make the image update every 6 hours for the client? So, the next time a client views the page after 6 hours, it updates the image?
Something along the lines of:
[code]
Header('Content-type: image/png');
Header('Cache-Control: public, max-age=21600');
[/code]
[QUOTE=Nisd;47012864]Something along the lines of:
[code]
Header('Content-type: image/png');
Header('Cache-Control: public, max-age=21600');
[/code][/QUOTE]
That doesn't seem to be working, if I am doing it correctly. It still updates on each refresh.
It's a dynamic image that is made with data from SQL tables, but to reduce strain on the servers, I only want it to update every few hours.
[QUOTE=Th3applek1d;47013471]That doesn't seem to be working, if I am doing it correctly. It still updates on each refresh.
It's a dynamic image that is made with data from SQL tables, but to reduce strain on the servers, I only want it to update every few hours.[/QUOTE]
Then save the image created and check if the filemtime() is more than 6 hours ago, otherwise regenerate. Not all browsers cache files and if someone would want to annoy you they could just spam requests to generate the images, don't trust the client.
Hey guys no idea why I haven't spent more time in the web development threads, but I'm trying to create a posting system similar to ScriptFodder.
Basically, once a user logs in through steam (already set up) he would fill out a form with an option to input file type.
Once clicking submit, it would display it on a webpage. [url]https://scriptfodder.com/scripts/view/20000[/url] when you submit a script on scriptfodder it would fill out the blank template.
How would I approach this?
Would you guys say it's worth the while building your own Vagrant box for multiple tasks (or individual), or would it just be easier and better to grab one already made?
Doing a quick Google search on Ruby boxes [URL="https://github.com/rails/rails-dev-box"]I found this[/URL] and it seemed nice enough to just get and run, but should I build 1 box to rule them all myself?
[QUOTE=Rocket;47015368]What language?[/QUOTE]
PHP, I'll decorate it with css later. I'm open to more solutions such as js if it makes it easier.
[url]https://gist.github.com/NeophytePHP/8ed6274cae234754b9c2[/url]
Any suggestions to improve this?
[QUOTE=Rocket;47021824]
Besides the weird indentation and naming style, don't hardcode the database credentials. Load them from a config file.[/QUOTE]
Alright, any suggestions on how to load them from a config file, any specific method?
(the indentation and spacing is for my eyes, I have shitty eyesight. )
Sorry, you need to Log In to post a reply to this thread.