Creating a referral link on CodeIgniter - php

I have a membership site where people can sign up for an account using their name, phone number and password of choice. The information entered during registration is stored in a MySQL database table called users. The primary key in the users table is the phone number. During sign up, the user has the option to type the phone number of his referrer into the referrer field. have all these set up and working fine, but I want to enhance the site some more, by:
Creating a unique referral link for users which will have their phone number appended to their link. I want to track which user referred others to my site so I can reward them.
When they share this link, and people click on it, it will take them to the registration page (register.php). On that page he phone number of the referrer will be set (and locked) in the referrer field.
I did some digging on the internet and found this code on github:
<?php
//check for referal links
function referal()
{
$CI =& get_instance();
$cookie_value_set = $CI->input->cookie('_tm_ref', TRUE) ? $CI->input->cookie('_tm_ref', TRUE) : '';
if ($CI->input->get('ref', TRUE) AND $cookie_value_set == '') {
// referred user so set cookie to ref=username
$cookie = array(
'name' => 'ref',
'value' => $CI->input->get('ref', TRUE),
'expire' => '7776000',
);
$CI->input->set_cookie($cookie);
return TRUE;
}elseif ($cookie_value_set == '') {
$cookie = array(
'name' => 'ref',
'value' => 'sso',
'expire' => '15552000',
);
$CI->input->set_cookie($cookie);
return TRUE;
}elseif ($cookie_value_set != '') {
//already referred so ignore
return TRUE;
}else{
return TRUE;
}
}
//end of hooks file
?>
The owner of the gist only mentioned saving the file as referral.php inside the hook folder. This is not helping me with what I want to achieve, I don't know how to use the code:
1. How do I pass the referrer field to the variable username from the users table?
2. How do I load the hook file to view (register.php)?
3. How and where do I call the hook file?
So can anybody give me an insight?

Well you are new to CodeIgniter and php. This will help you to get start with codeIgniter. Start coding with CodeIgniter using PhpStorm on Ubuntu 16.04 Merge Bootstrap to your current codeIgniter project in PhpStorm on ubuntu 16.04. Even these says about ubuntu os, it can use in other os as well. I think it's better to use id otherthan phone number for the primary key and make phone number as unique. It is not good to put phone number to the url. Because it is something personal for a user. You can use the id to the url. You can add it by as QueryString. To track users who use your site, you can add Google search console and Google analytic.

Related

Restrict content elements with IP in TYPO3

My requirement is to restrict a content element with IP of a specific country (Eg: Austria). That means people visiting the website from Austrian IPs should be visible the content element and for all other users, it should be hidden. I am using geoip solution to check the country. I wrote a user function to implement this feature. I wrote a small extension and set hidden flag 1 and 0 based on countries. But due to TYPO3 caching, I want to clear the cache everytime to reflect the changes in frontend. I included the extension as USER_INT, and extension is non-cachable. But unfortunately not working. Functionality working, but due to caching changes not reflect in realtime.
$uid = 175; // uid of the content element needs to be hidden
$geoplugin = new \geoPlugin();
$geoplugin->locate();
$countryCode = $geoplugin->countryCode;
if( $countryCode == 'AT' ){
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tt_content', 'uid IN ('.$uid.')', array('hidden' => 0));
}else{
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tt_content', 'uid IN ('.$uid.')', array('hidden' => 1));
}
Is there any method available in TYPO3 to restrict content element for specific IP / Countries? or can you guys suggest a solution to fix this please?
The solution of Jost is much less dirty than hiding the element in the database depending on the visitors country. By your way the database probably changed on every user visit.
Just create a micro extension.

How to to implement a forgot password feature using the Google Identity Toolkit in php

I am trying to add google identity toolkit in php. Signin option is working correctly but when i am clicking on problem in sign in link it is showing capthca after submitting captcha it is not navigating to any url.
email.php
<?php
include "identity-toolkit-php-client-master/src/GitkitClient.php";
$gitkitClient=new Gitkit_Client();
$oob_response = $gitkitClient->getOobResults($_POST);
$oob_link = $oob_response['oobLink'];
echo json_encode($oob_response);
?>
email.php is the oobactionurl file. when i am using this code I am getting this error .image
You need to create a php file to retrieve and send the reset link to the user. Make sure the oobActionUrl widget option points to this file. Within the file, you'll get the generated link and additional information by calling $gitkitClient->getOobResults($_POST). It should also work if you exclude $_POST, as the function will check the post contents if no arguments are passed. Then, you can get the link itself like this:
$oob_response = $gitkitClient->getOobResults($_POST);
$oob_link = $oob_response['oobLink'];
From there, you can use your email function of choice to send it to the user. The returned array should contain the following.
'email' => email of the user,
'oldEmail' => old email (for ChangeEmail only),
'newEmail' => new email (for ChangeEmail only),
'oobLink' => url for user click to finish the operation,
'action' => 'RESET_PASSWORD', or 'CHANGE_EMAIL',
'response_body' => http response to be sent back to Gitkit widget
Let me know if you have any further questions.

How to integrate Mailerlite API on my registration form?

I'm a total noob at programming. I'm currently creating a website where a user can register.
What I want to happen is the following:
When the user registers, he/she will be added to my MailerLite subscriber list.
All the information will also be saved to my website's database.
I played around with the MailerLite documentation but I can't seem to get anything to work.
I installed all the libraries found here: https://github.com/mailerlite/mailerlite-api-php-v1#installation using composer then I created a php file with this code:
`
<?php
require_once 'vendor/autoload.php';
$ML_Subscribers = new MailerLite\Subscribers("*my API*");
$subscriber = array(
'email' => 'first#example.com',
'name' => 'First name'
);
$result = $ML_Subscribers->setId( *my GROUP ID* )->add($subscriber);
?>'
but it appears to do nothing, once I submit the form, it will load the php file that I created and shows nothing, I check my subscriber list in MailerLite and nothing is added.
Please check what does the script return - add var_dump($result); in the end of the file.
And MailerLite doesn't accept "#example.com" emails, so be sure to change this

Sort "contact info" fields in Wordpress user profile

I can add and remove fields in the user profile section with:
function add_remove_contactmethods($contactmethods ) {
// Remove AIM
unset($contactmethods['aim']);
//add Phone
$contactmethods['phone'] = 'Phone';
return $contactmethods;
}
add_filter( 'user_contactmethods', 'add_remove_contactmethods' );
When I view this screen in the backend, the "Phone" field comes last, after some other fields like "Email" and "Website". I guess this is because my added field was added after the default Wordpress fields. How do I sort this, for instance alphabetically, so that my "Phone" field comes in alphabetical order instead of after the default fields? How do I sort the output of $contactmethods without messing it up?
try using ksort
function add_remove_contactmethods($contactmethods ) {
// Remove AIM
unset($contactmethods['aim']);
//add Phone
$contactmethods['phone'] = 'Phone';
ksort($contactmethods);
return $contactmethods;
}
add_filter( 'user_contactmethods', 'add_remove_contactmethods' );
re
UPDATE: So I guess the answer to my original question, is to explain why and how "Website" and "Email" are stored, and how the output is controlled in the backend when you view a profile. Maybe it's an ordered action? I guess "Website" and "Email" are just user meta, but how is the output order controlled. I accept that I might have to write a custom script to sort the output, I just don't know where to begin.
Your right about that, all the new contact fields were added into user_meta table. user_email and user_url are in the users table. The problem you are going to have doing this, is that a filter does not exist to modify the information. You can check the main filters here:
http://codex.wordpress.org/Plugin_API/Filter_Reference
and also you can look at core itself. All the admin templates are in wp-admin so you can look at the variable you need to modify in user-edit.php ($profileuser). Im in no way recommending this, but you could modify the template there, it will be overwritten on the next update of course so thats a drawback to it.
There may be a hook somewhere in admin in the load template process, if you could find one, you could relocate the template location to a theme file and recreate it with the changes you want. But all this seems like a lot of work to include just 2 fields to reorder?
Another approach is to use a higher priority the other when adding the fields. For example, Yoast adding 3 contact methods, and if you want your 'phone' appear before those, set the filter to:
add_filter('user_contactmethods', 'my_contactmethods', -5, 1);
Email and Website cant be re-ordered unless deep PHP coding or javascript re-order or advanced CSS.
if you know the key(s) (check the name fields in the source code), you can add other plugin fields by yourself, and choose exact appearance. A field is only added once if they added twice (!) This is how we use:
function entex_author_contactmethods($contactmethods){
$contactmethods['mail'] = __('Public email', 'entex-theme');
$contactmethods['phone'] = __('Phone', 'entex-theme');
$contactmethods['googleplus'] = __('Google+', 'wordpress-seo');
$contactmethods['youtube'] = __('YouTube URL', 'wordpress-seo');
$contactmethods['facebook'] = __('Facebook profile URL', 'wordpress-seo');
$contactmethods['instagram'] = __('Instagram URL', 'wordpress-seo');
$contactmethods['twitter'] = __('Twitter username (without #)', 'wordpress-seo');
$contactmethods['linkedin'] = __('LinkedIn URL', 'wordpress-seo');
$contactmethods['myspace'] = __('MySpace URL', 'wordpress-seo');
$contactmethods['pinterest'] = __('Pinterest URL', 'wordpress-seo');
return $contactmethods;
}
add_filter('user_contactmethods', 'entex_author_contactmethods', -5, 1);
Happy contact-ing!

Sugarcrm magento common login

I'm integrating SugarCRM and Magento. My requirement is when I click on a link in SugarCRM it should redirect to the Magento admin panel order creation. Moreover when I redirect to Magento it should not ask me for Login.
How can I do that?
Seamless login into Sugar is pretty straight forward. Below is an example that creates a link that bypasses Sugar login. When you login to Magento, you can login to Sugar and store the Sugar session variable in a server session variable or a Global variable. Here's the format of a SugarCRM URL
'http://localhost:8080/XXX/index.php?module=Accounts&action=DetailView&record=927e722c-0d8a-e6b1-c590-4c9bb6c4e34b$MSID
http://localhost:8080/XXX/index.php - URL
module=Accounts (Module name you want to link to
action=DetailView (You can go to either the DetailView or EditView)
record=927e722c-0d8a-e6b1-c590-4c9bb6c4e34b (Sugar ID record number)
MSID=3979359348 (Session variable obtained after the seamless login)
You will have to extend Magento to add this information to a link. If you store the MSID in a session variable, then you could always append $_SESSION['MSID'] to the URL
$user_name="admin";
$user_password="admin";
$soapClient = new SoapClient(NULL,
array(
"location" => 'http://localhost:8080/XXX/soap.php',
"uri" => 'http://localhost:8080/XXX',
)
);
try {
$info = $soapClient->login(
array(
'user_name' => $user_name,
'password' => md5($user_password),
)
);
}
catch (SoapFault $fault) {
die("Sorry, the service returned the following ERROR: ".$fault->faultcode."-".$fault->faultstring.".");
}
$session = $info->id;
$canlogin = $soapClient->seamless_login($session);
$MSID='';
if ($canlogin == 1)
$MSID = "&MSID=" . $session;
//echo "Successful Login! Session ID {$session}<br>";
echo "<a href='http://localhost:8080/XXX/index.php?module=Accounts&action=DetailView&record=927e722c-0d8a-e6b1-c590-4c9bb6c4e34b$MSID'>Account Name</a>";
Kaz
I haven't used SugarCRM in particular before, but the general gist of these solutions are to keep the two user databases in sync (same usernames and passwords). Then, when the user logs into one system, send a request to the other system to log in at the same time.

Categories