1. Adding role to user
Hello. I am creating my php system that will be used mainly to spread information and managing large database of users.
Let say i have my main "team" settings, and i want to have site where user (admin) can set up team data like "coordinator" or "manager" etc. I want to keep that simple, so admin can set up specific roles (they are stored in database under table team_settings with specific fields like team_manager etc.) by providing username/visible name.
Here is my question. I assume i will need to use jQuery to do simple "quick search" to choose specific user, but here is the deal. How to put this one in my form, that after choosing person, when i post the form i will store user_id in specific table field?
So mainly - how to set up user_id in my field when input will have user name instead?
2. Codeigniter Mailing / Bulk Emails
I am looking for any person that had faced mailing problems while using codeigniter or pure php. My problem is - my shared hosting have 30 sec execution time on PHP scripts, so i need to send email, mobile text message and IM message in this time.
Of course i can use cron to accomplish that, but the question is: Do anyone now any sort of extern API that i can use to send my bulk email? It will be same message (maybe with some variables, nothing more) send to about 150 users maximum.
3. Codeigniter Ajax
I just need to call same methods from my controllers and return different objects - when it is requested by AJAX it should return HTML, but when I call it (or my user) manually, it should load the view. How can i accomplish that?
Thanks in advance for all of your replies.
May The Force Be With You.
Answer for question 3, as I didn't understand the first two.
Simple way of using a function in two different ways:
Send an additinal parameter with ajax request like: ajax=true(either post or get request). when a normal request post/get will be posted, it will not be there. So just have a check that whehter aN ajax named variable exist in post/get request and process data accordingly. IF AJAX FOUND, do not load view, and echo $HTML; else $this->load->view('viewname'); Hope that helps.
After searching the user, when clicking on the edit user are you editing on the same page on a popup or navigating to different page for editing. If you are using same page, store the username in a Javascript global variable and post it while posting other edited details. If you using different page you can pass the username or user_id in the url segment and can use this as a parameter inside the controller function.
http://yoursite.com/controller/functionName/username or id
function functionName($username)
{
//do validate the $username and useit
//if posted update ot display the edit form
}
You can use some email queue concept. Where you insert all the generated emails to a queue table and with status off course. Then process them in a cron job in preferable limit so that it will not exceed the 30second limit. I am have included the same concept for the Codeigniter websites generated using thephpcode.com
Related
help me! I am a php rookie and i am confused with the php request.
Working on MVC structure for view, I created a HTML form, and on form submit i want to do call two different methods sendMail() and validateData() available in two different controllers (php file) - say one in process.php and another in register.php .
On form submit first I want to validate the data and save data to database using validatedata(). Then I want to send a verification mail to the user using sendMail().
To handle the request (click event) I am using jquery ajax. Ajax takes a single URL for posting data to the specified URL. So how can I make two different URL requests in a single Ajax call, or say how can I call both the methods in a single Ajax call?
Please suggest me what i should do to solve this issue?
thanks in advance.
A controller should handle an entire request.
So if the user makes (for example) a request asking to create a new user account then a single controller should:
Validate the data the user has sent to make sure it is what is required before creating an account
Create the account in the database
Send the email
Return a response saying if it worked or if there was an error
So you'll end up with something like
{
$errors = validateData($_POST);
if ($errors) {
echo generateErrorPage($errors);
exit;
}
$result = createUserInDBAndSendEmail($_POST);
showSuccessPage($result);
}
(That's very rough and ready for the sake of example).
Don't divide the steps you need to do to complete the task up between different controllers. Then you only have one URL to worry about.
You can divide the functions up between different files and then include them.
The complete process for creating a user might require additional feedback from the client, e.g.
Client makes a request to the CreateUser controller
Server creates a user in "unconfirmed" state, sends email to the user and returns an HTML page telling them to check their email
User clicks a link in the email to make a request to the ConfirmEmail conroller
Server changes the user to "confirmed" and returns a logged in homepage with a welcome message
… and in that case it would have multiple controllers since you need the user to make two different requests.
I am working with Qualtrics, which is just a web-based survey engine. The request is that, once users finish the survey, they will receive a small prize in the form of a gift code. Since I can't host the prize code data on the Qualtrics platform, my idea was to store the prize codes on a remote server. When the user finishes the survey they will be directed to my server (https), to a PHP script that will give out the prizes. On the surface this is possible, because as one piece of customization they allow to re-direct to a URL upon completion of the survey.
The problems that I am faced with, regarding my PHP script that gives out the prizes are as follows:
1) Make sure visitors have COME FROM the survey and have actually
finished the survey.
2) Only give out 1 prize per participant per survey.
It is difficult to address #1 because it seems like after the survey is complete, you just get a basic re-direct to my site. It would be possible to add GET data to the URL, its very easily readable and doesn't offer security. Even encrypting the GET data doesn't seem feasible because a hacker could just copy the data string once they see it.
The idea I had to address #2 was to check the user's IP address using PHP, and store the address in my DB after a 1-way encryption. This way the IP would be unknown, but I could check for duplicates, only allowing 1 prize per IP.
So the question is, is it even possible to do what I am trying to do with just a simple URL re-direct? Is my idea for addressing #2 acceptable?
Thanks.
There are probably many ways this could be handled. Two that come to mind:
1) At the end of survey, Qualtrics creates an embedded data field called ResponseID which is in the Qualtrics data. You can include the ResponseID in the redirect then have your php script call the Qualtrics REST API, and try to retrieve the response with that ResponseID to make sure it exists.
2) Just before the end of survey, you could do a web service call to a script that creates a unique id, store the id on the server side, and return it to the survey as an embedded data field. Then pass the unique id in your redirect and make sure it matches a unique id you stored.
EDIT based on comment below:
You can add custom parameters to your redirect by piping in parameter values like this:
http://mywebsite.com/myscript.php?rid=${e://Field/ResponseID}
If you are able generate special request parameter for redirect url and make it for every user unique, then you could invent some algorithm, and encrypt user ID with it and pass this ID as parameter in redirect url.
So we are building a website and created our basic information to send logins to our database. We have trouble trying to disallow requests that just plug their own data in.
E.g.
http://testing.site.com/php/interfaces/User.php?Action=1&Email=test#gmail.com&FirstName=herp%20derp
By replacing email and firstname, they are able to add multiple users to the database and potentially with a script thousands. Is there any way to prevent this without using a captcha? We are trying to be very minimal and open with the site's design so would love some input if this is possible.
One option we have considered is moving our PHP offline and only allowing our API to access it- however it still presents the problem of users adding in authorised data (and overloading our database with thousands of multiple requests)
Here is a sample option, create a table with 2 fields, one is an Auto Increment id and one is a random code, lets name them ID and CODE
When sending that request, create 1 record in that table and pass the ID and CODE along with request, when receiving the request, check if there is a record in database with that ID and CODE process the request and delete that record from database too and if there isn't that record, just ignore request ...
So I've made an extremely simple 4 page static webpage for this client with a quick contact form handled by php. Everything goes swimmingly.
Then the client comes to me and requests that he is able to see a counter of how many submits have been made. So he generally wants a counter for his form, Which is simple enough because I just add a counter for every successful email sent using the form and save it within some kind of data storage.
BUT...
the only way I can think to do it is have a separate user page with a simple box that has the number in it, that only the client can access.
I could do this... Save the counter in an xml file or a one table, one column, one row mySQL database.
But is there a better easier simpler way to do this??? Can I set up a link with Google analytics or something? Rather than making a single page with a number on it.
I suggest going with a separate page for the client to view counts. You can use .htaccess to control the access to this page. The main reason is looking forward to future client requests. Most likely, they will then ask you to show counts for specified periods of time, counts per day/week/months, etc. If you set up your page now, then you can have place to customize/extend.
As for storing the counter, I would suggest storing more than just the total. Have a table where you'd store:
date/time of form submission
remote IP address (for possible future reference)
content of the submitted form (if the client ever decides to want to see it)
maybe event content of the email (if the client ever decides to want to resend it)
Then to display the totals, you'd just select count(1) from that_table with any required date/etc. grouping.
I need to build a registration system which requires the collection of large data (many fields) from the user registering which is then inserted into a couple of tables in a database.
I don't really want to display a very long form to the user for the purposes of better UX.
This system will not run online, it is just a web app to run on the desktop.
I need help, pointers, references, etc on how I can better organize the registration process to make it more user friendly.
This How to encourage a user to fill in long application forms? has been helpful so far
As long as you don't mind requiring your user has Javascript, I would use AJAX. Let's say that you have 50 fields that you can logically combine into 4 different sets - the first may be about the person asking for name, email, etc., while the next set asks for historical information or employment information - like on an application.
Make one form for each set, and then present a new user with the first. When he completes the first page, instead of a "Submit" or "Register" button, use an AJAX call and a "Next" button to get the info and switch to the next page of the form with the next set of fields. You could use the AJAX calls to hold the information in a temp table in your database, and then, once the entire process is complete, you can write it to your member/users table.
You could do like other surveys or checkouts do and add a "title" for each page of the form above the form fields so that as a user moves through registration, they can monitor their own progress.
I'd recommend checking out the Amazon checkout, or really any multi-page survey (you may even be able to set one up yourself on Survey Monkey) to see how a large number of form fields can be broken down logically in a user friendly way.
Hope it helps.
Check out this link: http://www.smashingmagazine.com/2011/05/05/innovative-techniques-to-simplify-signups-and-logins/
It's talking about login- and registration-forms and how to make them more user-friendly. A suggestion which is also included in this article is as follows:
At registration don't ask the user to many questions. Only the basic data like their name for example. Then ask him about more detailed data when the user logs in the first time. This way the registration won't take too long.
Maybe this helps you out :)