Hey guys I am making a website and I want to do something similar to the login buttons for this website. My plan is to have some client side javascript that will toggle the Sclasses for an image and for the login and create account button and let the css hide them. I was wondering how I would get the image from my database to the client?
The site has a Node.js server, MySQL Database, for the client I am using Express.
I have never stored a image in a database before so I wanted to give it a shot. Essentially I want to store it as bytes as a text field but I am not sure on how to process those bytes and get that to the client.
What you will want to do is to store it in a format that is specifically designed for storing raw binary data (maybe blob?)
To transmit it to the client, you can either just dish out the image in a HTTP response, you can create your own protocol to transfer the data or you can use another protocol.
Also I want to be able to do an if then statement to check if the account is logged in or not. If I had a java script file on the server could that hold variables while the client is in session so I could make an AJAX call to the server to get those variables?
For something like this, the client should be nothing more then an interface to display data given by the server, and give data to the server.
Following this principle. You should not be performing any security checks in the client.
If you want the client to know if it's logged in. Get it to check if it's got a session token, or ask the server to give it a JSON response telling it if it is or not.
Sorry I didnt mean on the client. I am using node.js so its all javascript for the server as well. I meant if I create a variable in the server code is that specific to the session?
Storing file data in a db is generally a bad idea. Relational databases are not meant to store such large chunks of data and you'll notice performance issues pretty fast if you're making a real world app. The only exception that I know of is Postresql's large object store which breaks your large chunks of data into multiple rows to keep performance decent.
You could do the same manually for mysql. Split your images into multiple rows in a blob column.
I will look into that in a moment. For now I need a way of holding session data for each client and I assume I somehow use something called a cookie as a unique key to find data unique to each user. In this case I want to use Redis but I am not sure how to do it in code.
An example would be to see if the person is logged in or not.