So I just set this up:
http://www.phpeasystep.com/phptu/6.html
It was fairly easy, now I have it redirecting to another page but how can I pull the successful username used?
I'm trying to build a basic chat program to learn with.
Getting this would solve how I will add the variable when a message is sent off to the mysql database and to verify it was sent by the right person.
I think you are looking for what we commonly call SESSION variables. This type of variable offers persistence over different pages. The api for handling sessions is nice and simple, and in my (personal opinion) session variables can be very handy, and dead simple to put in action.
Especially for tasks like the one you have at hand, keeping messages and usernames and such. You can even pass objects in sessions, if you want to get wild, just serialise and deserialise the data before and after saving it in a $_SESSION var.
Read up the session handling section in php, this should give you a hint on how to tackle your problem.
On a sidenote, though, there are other ways that don't need session variables, since you posted php code I assumed you wanted a php related answer.
Good-luck
Related
This question already has an answer here:
Execute function stored in a variable
(1 answer)
Closed 10 months ago.
Is it possible to store asp classic code into a MYSQL database and have it execute the code when its pulled? Such as store a variable name into a string and have it execute the ASP before displaying it? I suspect it is either impossible, since the MYSQL request runs after the page is loaded and so the return data will not be execute and will just the variable name. The other thing is it could be an HTML encoding thing where it might be possible to encode it after you pass it to the MYSQL Server, but so far it just reads the variable name. Any ideas on this, is this impossible, or am I derping the encoding somehow:
I have tried using the encoding method like this using a Chr replace function that works elsewhere, but the use of the function is like this:
NEWSTRING = Server.HtmlEncode(OLDSTRING)
With or without the encoding attempt the results just display the ASP Classic code like this:
MESSAGE TO USER <%=Session("var_FOO")%>
Although the Encode doesn't seem to change the string displayed to the screen, the log result shows the encoding attempt, it doesn't put the data in, but converts the character types sort of like this:
"var_Foo"
I may be barking up the wrong tree with the encoding but if you have a hammer you can try smacking some screws until they go in.
This feature has a pin tack in for me at the moment, as a much more simple way is to just store the string in the database as I have been and just add the variables to the string after its pulled instead of putting them into the database. Granted this means the user can't control the error messages with variables tied to it, but meh I think I can live with that.
UPDATE - The similar question offers to do this as a function, and if you read the rest of the post, you will see there are difference, all negative votes are just rage/hate votes. The fact I am UNABLE to delete this post is proof that there are differences, so even S.O. thinks this post is different enough to exist.
Yes, it's possible. Classic ASP offers Eval, Execute, and ExecuteGlobal methods, to which you can pass a text string containing source code.
It's dangerous on a public-facing web site to do this; a cybercreep can, if he figures out how to write arbitary code into your database table, destroy, corrupt, or hijack your app. You're not paranoid: highly motivated strangers are actually plotting against you and looking for sites that work this way. Be careful.
Eval(codeText) runs an expression and returns the result. ExecuteGlobal(codeText) runs it as if it were in the top-level context.
Execute(codeText) runs it in the context (the subroutine or function) where you invoke it.
I have a editable html5 page and I store new elements in localStorage.
I want to synchronize my page with the server.
I want to know if I can do it without a server side script or if there is some tips to do something like this in a good way.
Thank you :)
You can pull information from the server quite easily using jQuery and then just put it on Local Storage but, if you want to upload local information to the server there is no way around, you have to use some kind of script, tough it's not that difficult, there are many languages (PHP, C#, Python...) and tools you can use.
Keep in mind that when you upload information to the server you have to sanitize it very important security measure.
Basically, the way to go is:
Post the information to the server (using AJAX or a HTML form, either way will do)
Use some server-side script to capture the variables posted.
Sanitize your data (check format, discard non-valid characters, etc)
Store it on database (Do not, ever, concatenate your data with a SQL query ok? that can make you vulnerable to a SQL injection attack), compute something or do stuff.
Return some status to the client (some confirmation maybe?)
You may want to take that confirmation and show a message to the user ("Your info was saved properly" or something like that)
is a javascript timer not sufficient for this manner? or jQuery?
The question really should be more of a problem than a question. If you're updating based on a server's variables then you could use AJAX i believe but if its like increment said variable every X seconds I would focus on using a javascript timer.
I know this question was asked a lot, but I didn`t find anything that could help me.
I`m using Java, JSF, EJB, JPA, GlassFish, MySQL.
I developed web sites with autentification, using these technologies, but with only from one location (one session at a time) and if another user logged in from another location (s)he could see the state of the first users session.
Now I need to develop a multiuser web application with a commom home page and a few commom features, but the rest needs to be user dependent a multi thread access to the web application and to the database.
I need to:
limit the users capabilities to start a session from only one location, one computer
have them make them register on the site for a limited period of time (the profile should be active for 1 year lets say)
to give them timeouts after 1 hour
and so on...
Please help me understand what I have to do to!
I dont know how and where to start, I read a lot of articles about this, but it was just bits and pieces and I dont have a full picture about this.
Thank you for your time, happy coding and keep up the excelent work your doing here!
if another user logged in from another location (s)he could see the state of the first users session.
This is not right. This application was badly designed from the beginning on. This can happen when you're storing request and/or session-scoped data in a static variable or in the application scope. This is not right. Request scoped data should be stored in non-static variable in a request scoped bean. Session scoped data should be stored in a non-static variable in a session scoped bean.
In other words, stop using static variables until you really understand what that means and don't store the data in a too wide scope.
See also:
How to choose the right bean scope?
I have rest services that i will be posting data to. Is it better to post data using http form elements in the post data or is it better to post all the data in one json string and then parse the string at the server side. Any reason to go one way vs the other?
Thanks in advance. I am trying to make sure architecturally we code this the best way.
Thanks
I think you have to use the first solution because it is more close to the RESTful architecture. In addition, this solution is a standard, so you will don't need to do extra things to encode / decode the POST parameters.
I think it depends on your data.
If your data is quite flat with a one to one correspondence between keys and simple values then the form style submission is probably most appropriate. If you have more complex nested data or an array of some kind I would roll with the json approach. I don't think either option is more or less RESTful.
Form elements are the way to go. If you use json in your post, then you need to communicate the structure to the clients. This is usually done out-of-band (I've never seen it done in-band, but I might be wrong), which creates a coupling between the client and the server.
When you use a form, the in-band form communicates to the client what the post data should be. When the data requirements change, the form is changed and the client can (possibly) adjust accordingly.
For instance, just say you've defined the following nouns in your media-type: email, password, first-name, last-name, date-of-birth etc and you have a user creation form that requires email and password, with the other user optionally data populated later on (via another form). Later it's decided that you want users to provide their name when the account is created, so you update the form so that is requires email, password, first-name and last-name. Since the clients are already familiar with these nouns (and know what data belongs in each), well written clients will be compatible with the updated form. If it was just json data being posted, the clients would not work as they would have no idea the required json data had changed (unless you change the media-type, in which case you'll break them anyway).
Now this approach only works for nouns that have been defined in your media-type. If you are adding a new noun, then you can either only ever make it optional (existing clients will still work, new clients can take advantage of the new noun) or if you need to make it required, then you need to create a new media-type, which only new (or updated) clients will be able to use.
Can I write a Stored Procedure (or a simple query) in mySQL which can send an email out containing results of a query.
Any help will be useful.
Not without modifications. It has no email-related functions at all. You could write a custom module for it to add such a function, but it seems to me that something like that is in the purview of the application using MySQL, not MySQL itself.
Not directly in MySQL, but I worked on something similar over the weekend.
Background: I wrote an app over the weekend to learn PHP. I knew I would have to be emailing out information from a MySQL database, so I needed a way to send emails with PHP easily, so I integrated PostageApp into my app, which took less than 15 minutes.
Relevant: I wrote a script to pull specific rows in MySQL, and used mysql_fetch_array() to be able to access the information for each of the fields in a row. With the array, I just passed the variables into a PostageApp API call, which used a template that had placeholders for these variables. PostageApp did the rest for me.
Here's how my template in PostageApp looked like:
Hey {{first_name}},
On {{date}}, we noted that you went to {{url}} for the first time.
Of course, not exactly what it is, but those are the variables, that were then passed into the API call.
Let me know if I can help you out with that.
(Full Disclosure: I am the Product Manager of PostageApp. But I actually did build an app over the weekend as a side project.)