I want to make my site multi langueage. I have seen in packages like prestashop, the translations are saved to a file like this:
<?php
$_lang['contact_header_steps'] = "Order whatever you like in 4 easy steps";
$_lang['contact_steps_1'] = "Fill out the form";
$_lang['contact_steps_2'] = "We will send you a payment link";
$_lang['contact_steps_3'] = "Pay online";
$_lang['contact_steps_3a'] = "";
?>
so this is what I did. I work with smarty and in my templates i use (expample): {$LANG.contact_header_steps}
and i use a global detection that stores the slected language in a cookie so my site knows wich language to show.
All work fine but now i want to build a easy management system.
I want to write to this file (like mentioned above) from the admin (without DB). I have seen this in prestashop but after looking in to the core i just got lost.
so when i open the translation page it must read this file and create 2 input fields. when i save it must save to this file
What is the best way to approach this?
Give every language a 'code name' ex: English:en ; France:fr ; etc.
Assuming you stored the language in cookie $_COOKIE['lang']
<?php
$mylang = $_COOKIE['lang']; //get the cookie
//define the translation here
$_lang['en']['contact_header_steps'] = "Order whatever you like in 4 easy steps";
$_lang['en']['contact_steps_1'] = "Fill out the form";
$_lang['en']['contact_steps_2'] = "We will send you a payment link";
$_lang['en']['contact_steps_3'] = "Pay online";
$_lang['en']['contact_steps_3a'] = "";
$_lang['fr']['contact_header_steps'] = "OTHER_LANG";
$_lang['fr']['contact_steps_1'] = "THAT_I";
$_lang['fr']['contact_steps_2'] = "HAVE_NO";
$_lang['fr']['contact_steps_3'] = "IDEA_OF";
$_lang['fr']['contact_steps_3a'] = "HERE";
echo $_lang[$mylang]['contact_header_steps']; //use it to call the language
?>
Related
I would like a simple PHP captcha script that would require the user so solve a captcha to load the website page. Preferably a captcha that doesn't need a third party such as reCAPTCHA, all done locally.
EDIT: Ended up making a text box to enter the link you would like to protect and it would automatically generate a captcha protected link, and a deletion link to delete the protected link.
You can look at the example here:
https://code.tutsplus.com/tutorials/build-your-own-captcha-and-contact-form-in-php--net-5362
I would also recommend using the timer on your page since bots are becoming better at passing capchas. By timer, I mean time between landing on the page and creating an account/submitting the form.
This is VERY simple. Usually no one is going to put any effort to bypass the captcha unless you have something worth while aka $$$$.
Just post an image with a question. Like What is 345 x 100,000 + 957?
The have an small form with a <input> for them to answer.
You could have any number of images and answers.
$captcha[] = array($answer,$image);
$captcha[] = array($answer,$image);
$captcha[] = array($answer,$image);
Then
$cnt = count($captcha) - 1;
$rec = rand(0,$cnt);
$answer= captcha[$rec][0];
$image = captcha[$rec][1];
echo '<img scr="$image"/>';
echo '<form action="$url" method="post">';
echo '<input type = "text" name="answer" /></form>';
$id = intval(str_replace('.','',$_SERVER['REMOTE_ADDR']));
file_put_contents("$id.txt",$answer);
The in the $url page:
$id = intval(str_replace('.','',$_SERVER['REMOTE_ADDR']));
$answer = intval(file_get_contents("$id.txt"));
unlink("$id.txt");
$pass = false;
if $answer == intval($_POST['answer']){$pass = true;}
I would like to create a wordpress user with contributor privelages, remotely. However, I would like to also create their wordpress account using an email that I manipulate by using their id (from login on my site) and #example.com. So it would essentially be: id##example.com. I am very new to programming. I have looked and looked and just continue to scratch my head. What would be best practice for doing this? Any examples, resources, explanations would be appreciated!
I was thinking of creating a link in their account page that when the logged in user clicks it it will redirect them to a page that will create their user account within wordpress framework. They would have to be logged into my site to access.
I am not sure how to do the email portion of your question. Although, I would like to know how to meld the two together. However, if you are needing unique emails for wordpress you can by-pass this required section (required if using wp dashboard to create user). I found this recently.
You could simply:
$user_name = //however you get your unique identifier this will be their screen name
$user_id = username_exists( $user_name );
if ( !$user_id and email_exists($user_email) == false ) {
$user_id = wp_create_user( $user_name, $user_email );
wp_update_user(array(
'ID' => $user_id,
'role' => 'contributor'
));
}
If your users actually do have an email account on your server and you want them to receive emails from wordpress.. this will not fix your situation.
there are many ways to do this. the cleanest would probably at the moment be to use the Wordpress API together with JWT authentication.
Here is an easier solution. On the Remote Wordpress Installation you stick something like this into your functions.php
function remote_create_user() {
$token = (isset($_GET['token'])) ? sanitize_text_field($_GET['token']) : '';
$action = (isset($_GET['action'])) ? sanitize_text_field($_GET['action']) : '';
//this is not particularly secure, but let's assume your wordpress page has https which should encrypt the url...
//im just setting some random string to compare to
if ($token != '712031ff105541219fcc741d99a9addd' || $action != 'createuser') {
return;
}
$username = sanitize_text_field($_GET['username']);
$email = sanitize_text_field($_GET['email']);
//making sure the user doesn already exist
$user_id = username_exists($username);
if (!$user_id and email_exists($email) == false) {
$random_password = wp_generate_password($length = 12, $include_standard_special_chars = false);
//creating the user
$user_id = wp_create_user($username, $random_password, $email);
if ($user_id) {
//here you could send the user a welcome mail. if you want, include the password in the mail or just make him press the "forgot password" button
//wp_mail($to, $subject, $message);
echo "User created";
}
} else {
echo "User already exists.";
}
}
add_action('init', 'remote_create_user');
On the system you want to send the command from, you can then do something like this (on the serverside, you can't to this from the browser, because the "authentication" token will be visible in the javascript...
$createuser = file_get_contents('https://yourdomain.com/?token=712031ff105541219fcc741d99a9addd&action=createuser&username=test3&email=test3#test.com');
//depending on the result in $createuser, give an error message or redirect him to your wordpress login page or something
i hope this gives you some ideas.
Edit: Aboves init function is missing a wp_die() at the end. we dont want the whole page rendered here. also, this is just a quick & dirty solution.
Look into Wordpress Rest API or also custom endpoints.
I would like to know if this is the best practice with CI or if there is some better way.
In my project I am sending a confirmation email during the registration process. I have a HTML and TXT template. They both consist of something like this:
Hello {USERNAME}, please click on the activation link below to finish the registration. Link: {LINK}
And in my method I open the templates using the file helper and then replace the {} strings with the actual values using the text helper's word_censor() method like this:
$tmpName = '{USERNAME}';
$tmpLink = '{LINK}';
$name = 'Jon' //retrieved from registration from
$link = 'mysite.com/activate/239dwd01039dasd' //runs the activate function providing the unique ID as an argument
$template = word_censor($template, $tmpName, $name);
$template = word_censor($template, $tmpLink, $link);
return $template
Then I just take the $template and put it inside the CI's mail helper like this:
$this->email->message($template);
What I would like to know is if this is the best way to replace contents of html/txt files with my own values or if there is any better and more efficient way to achieve the same result. I just don't like that I am using the word_censor() function to do something other than what it was intended for..
The better way is to store the email template as a view file.
view
Hello <?php echo $username; ?>, please click on the activation link below to finish the registration. Link: <?php echo $link; ?>
Controller
$data['username'] = 'Jon';
$data['link'] = 'mysite.com/activate/239dwd01039dasd';
$email_template = $this->load->view('myfile', $data, true);
$this->email->message($email_template);
Setting the third parameter on view() to true will return the template rather then echo it out.
I have a PHP Login using a flat file (.txt) system with a username and password this is in a file called users.txt and they are in the following layout e.g.
User1||Password1
User2||Password2
User3||Password3
Till now I managed to get users to login based on their username and paswords.
Now I would like a PHP code so that when users login using the above method, a custom comment is displayed based on the username. I would like this in a separate text file, and to be displayed according to how the user logged in e.g.
User1||Hello John, you look great
User2||Don't let the rain spoil your day
User3||Hooray for holidays
So if User1 logs in using his username and password - only they can see their associated comment, and the same for the others.
How can this be done please?
I was thinking of having a code similar to this
$name = $_SESSION["valid_user"];
$comments = $_POST['comments'];
$file = file_get_contents("comments.txt");
if(strstr($file, "$name||$comments"))
Umm.. I don't think you understand PHP/Login.
Passwords + Text files = Horrible. You should store the information in a database, like MySql.
Then, you can do a simple if statement/switch command to output a custom message for each user.
if($username == 'Alan') { echo "Welcome boss"; }
else if($username == 'Clara') { echo "you look great today"; }
else { echo "Welcome ".$username; }
A simple way to do it is just make an array where the keys are the user names and the values are the comments for each user.
$comments = array(
"user1" => "You smell funny.",
"user2" => "Your cat is annoying me.",
"user3" => "You're an okay person... for now.",
// So on and so on...
);
Not that I condone the way you're doing your login or content storage.
I am building a flash website and I want contact information sent to my gmail address.
The Lynda.com tutorial I am using says I need to "enter the php address." What is that and how do I do it?
This is my code edited
if (thename.text == "" || theemail.text == "" || thephone.text == "" || themessage.text =="") {
thefeedback.text = "*Please fill out all fields";
} else {
var allvars:URLVariables = new URLVariables()
allvars.name = thename.text;
allvars.email = theemail.text;
allvars.phone = thephone.text;
allvars.message = themessage.text;
// Send info to a new request
var mailAddress:URLRequest = new URLRequest("http://whatever goes here.php");
mailAddress.data = allvars;
mailAddress.method = URLRequestMethod.POST;
sendToURL(mailAddress);
thefeedback.text = "Thank You";
thename.text = "";
theemail.text = "";
thephone.text = "";
themessage.text = "";
}
Presumably they mean "A URL that resolves to the PHP script that they taught you to write", but "php address" is not a standard term.
When you press submit on any form it is taking that information (first name, last name, body text, etc) and then it needs to be sent somewhere so that it can be given to gmail or anther email service as an actual email.
Now PHP on a server can take the information, turn it into an email, and send it from you to them.
You can do this by using POST and the URL is to a PHP script that lives somewhere.
Now that script needs set up, you can learn how HERE
Good luck friend!
You can use Zend PHP to use PHP functions from Flash.
This tutorial is pretty good: http://www.flepstudio.org/forum/tutorials/3421-actionscript-3-0-zend-amf.html