Skip to content

Instantly share code, notes, and snippets.

@MaleXachi
Last active December 31, 2015 17:33
Show Gist options
  • Save MaleXachi/b27d564a6db8167b6ee2 to your computer and use it in GitHub Desktop.
Save MaleXachi/b27d564a6db8167b6ee2 to your computer and use it in GitHub Desktop.
This is a method to login with lightIRC, when you fill in your username and gender and about colours of genders. If you want to add more options, feel free to post a comment. Please click on star, if you like this!
Changes 2015-02-24:
Better Security for $_POST with Errormessages:
- If username is Empty
- If a username don't have legal characters (You can add more values in preg_match())
- If Length of username is longer/shorter than default values (You can change both length of username)
- If username have bad names (You can add more bad names in array of $badNames)
- If gender is Empty
- If gender value is other than default values
Extra Options (2015-02-24):
User Password
User Country: https://gist.github.com/MaleXachi/b27d564a6db8167b6ee2#comment-1400059
Note: I don't get any mails, if anyone comment me on my Gist, but u can send a mail to me, if u did comment
on my Gist, but do not send a mail to ask for help, but that you did comment, otherwise i will not help you.
Mail: i.own3d.th3.w0rld@gmail.com
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Welcome to our Chat!</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">jQuery.noConflict();(function($){$(function(){$(function(){$(".text").keyup(function(){var word=$(this).val();$(".word_preview").html(word);return false})})})})(jQuery);</script>
<link href='http://fonts.googleapis.com/css?family=Fontdiner+Swanky' rel='stylesheet' type='text/css'>
<style>
.error {color: red;text-align: center;}
body {font-family: Verdana;margin:50px 0px;padding:0px;text-align:center;}
div#lightForm {text-align: left;width:500px;margin:0px auto;text-align:left;padding:15px;border:1px dashed #333;background-color:#eee;-moz-box-shadow: 0 0 5px #600000;-webkit-box-shadow: 0 0 5px #600000;box-shadow: 0 0 5px #600000;}
div.formInput {text-align: left;width: 300px;margin-left: auto;margin-right: auto;font-size: 12px;color: #600000;}
input[type=text], input[type=password], input[type=submit] {margin: auto;display: block;width: 100%;}
select {margin: auto;display: block;width: 100%;}
.lightText {padding: 1px 1px 1px 1px;margin: 1px 1px 15px 1px;font-family: 'Fontdiner Swanky', cursive;text-align: center;color: #600000;}
.word_preview {color:#000000;}
</style>
</head>
<body>
<?php
$Message = 1;
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$Username = $_POST['username'];
$UserPassword = $_POST['userpassword'];
$Gender = $_POST['gender'];
$badNames = array('Hitler', 'Fuck', 'Asshole', 'Dickhead');
$Check = array();
$CheckFound = preg_match_all('/\b(' . implode($badNames, '|') . ')\b/i', $Username, $Check);
if (isset($Username, $UserPassword, $Gender))
{
if (empty($Username))
{
$Message = 2;
} elseif (preg_match('/[^A-Za-z0-9_-]/', $Username)) {
$Message = 4;
} elseif (strlen($Username) < 3) {
$Message = 5;
} elseif (strlen($Username) > 15) {
$Message = 6;
} elseif (empty($UserPassword)) {
$Message = 7;
} elseif (preg_match('/[^A-Za-z0-9_-]/', $UserPassword)) {
$Message = 8;
} elseif (strlen($UserPassword) < 3) {
$Message = 9;
} elseif (strlen($UserPassword) > 15) {
$Message = 10;
} elseif ($CheckFound) {
$Names = array_unique($Check[0]);
foreach ($Names as $Name) {
echo '<p class="error"><strong>' . $Name . '</strong> is not allowed. Please give a correct name.</p>';
}
} elseif (empty($Gender)) {
$Message = 3;
} elseif (!preg_match("/Male|Female|Trans/i", $Gender)) {
$Message = 11;
} else {
$Message = 12;
}
}
}
$Html =
'<div id="lightForm">
<h1 class="lightText">lightIRC</h1>
<div class="formInput">
<form action="" method="post">
<label for="username">Username:</label> <input type="text" class="text" name="username">
&lsaquo;<span class="word_preview"></span>&rsaquo; Hello, i am <span class="word_preview"></span><br /><br />
<label for="password">Password:</label> <input type="password" name="userpassword"><br />
<label for="gender">Gender:</label> <select name="gender">
<option>Male</option>
<option>Female</option>
<option>Trans</option>
</select>
<br /><br />
<input type="submit" name="submit" value="Chat now!">
</form>
</div>
</div>';
switch($Message)
{
case 1: $Message = $Html;
break;
case 2: $Message = '<p class="error">Username is required!</p>' . $Html;
break;
case 3: $Message = '<p class="error">Select your gender!</p>' . $Html;
break;
case 4: $Message = '<p class="error">Give a username with legal characters.</p>' . $Html;
break;
case 5: $Message = '<p class="error">Name is too short. Min length is 3.</p>' . $Html;
break;
case 6: $Message = '<p class="error">Name is too long. Max length is 15.</p>' . $Html;
break;
case 7: $Message = '<p class="error">Password is required.</p>' . $Html;
break;
case 8: $Message = '<p class="error">Give a password with legal characters.</p>' . $Html;
break;
case 9: $Message = '<p class="error">Password is too short. Min length is 3.</p>' . $Html;
break;
case 10: $Message = '<p class="error">Password is too long. Max length is 15.</p>' . $Html;
break;
case 11: $Message = '<p class="error">Please, don\'t try to change our values. Choose one of these options!</p>' . $Html;
break;
case 12: $Message = '
<script language="javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js" type="text/javascript"></script>
<script language="javascript" src="config.php?name='.$Username.'&amp;gender='.$Gender.'&amp;userpassword='.$UserPassword.'" type="text/javascript"></script>
<br /><div style="text-align: center;">
<div id="lightIRC" style="height:500px; text-align:center;"><p><a href="http://www.adobe.com/go/getflashplayer" title="Get flash player"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p></div>
<script type="text/javascript">swfobject.embedSWF("lightIRC.swf", "lightIRC", "100%", "500", "10.0.0", "expressInstall.swf", params);</script>
</div>';
break;
}
echo $Message;
?>
</body>
</html>
<?php
$name = strip_tags($_GET['name']);
switch($name) {
case preg_match('/[^A-Za-z0-9_-]/', $name):
break;
default:
$name = "Guest_%";
}
$userpassword = strip_tags($_GET['userpassword']);
switch($userpassword) {
case preg_match('/[^A-Za-z0-9_-]/', $userpassword):
break;
default:
$userpassword = "";
}
$gender = strip_tags($_GET['gender']);
switch($gender) {
case "Male":
case "Female":
case "Trans":
break;
default:
$gender = "Unknown";
}
?>
var params = {};
params.host = "YOUR IRC SERVER";
params.port = 6667;
params.policyPort = 843;
params.ident = "ident";
params.realname = "<?php echo $gender; ?>";
params.identifyPassword = "<?php echo $userpassword; ?>";
params.quitMessage = "See You Later";
params.targetFrame = "_blank";
params.showNickSelection = false;
params.fontSize = "16";
params.styleURL = "css/lightblue.css";
params.performContinousWhoRequests = true;
/* userListCustomFormatting - Fixed by Kin Kith: http://redmine.lightirc.com/issues/435#change-1042 */
params.userListCustomFormatting = "realname=(^|\\W)([Mm]ale|[Mm]an):userListMan,realname=[Ff]emale:userListWoman,realname=[Tt]rans:userListTrans";
params.showInfoMessages = false;
params.customSecurityErrorMessage = "There is an error. Please refresh the page!";
params.showNewQueriesInBackground = true;
params.webcam = true;
params.accessKey = "";
params.rtmp = "";
/* Language for the user interface. Currently available translations: ar, bd, bg, br, cz, da, de, el, en, es, et, fi, fr, hu, hr, id, it, ja, nl, no, pl, pt, ro, ru, sl, sq, sr_cyr, sr_lat, sv, th, tr, uk */
params.language = "en";
/* Nick to be used. A % character will be replaced by a random number */
params.nick = "<?php echo $name; ?>";
params.nickAlternate = "<?php echo $name; ?>_";
/* Channel to be joined after connecting. Multiple channels can be added like this: #lightIRC,#test,#help */
params.autojoin = "#chatroom";
/* Commands to be executed after connecting. E.g.: /mode %nick% +x */
params.perform = "";
/* Whether the server window (and button) should be shown */
params.showServerWindow = true;
/* Show button to register a nickname */
params.showRegisterNicknameButton = true;
/* Show button to register a channel */
params.showRegisterChannelButton = true;
/* Opens new queries in background when set to true */
params.showNewQueriesInBackground = false;
/* Position of the navigation container (where channel and query buttons appear). Valid values: left, right, top, bottom */
params.navigationPosition = "bottom";
.userListMan {
color:#1E90FF;
}
.userListWoman {
color:#FF00FF;
}
.userListTrans {
color: #009933;
}
@MaleXachi
Copy link
Author

If u want to show Country Code, u can do this:

Add this in chatlogin.php on line 29:

if (isset($_SERVER['HTTP_CLIENT_IP'])) {
    $userIP = $_SERVER['HTTP_CLIENT_IP'];
}
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $userIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
    $userIP = $_SERVER['REMOTE_ADDR'];
}

$Geo = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $userIP)); 
/* u can add more here (Like City, Region, Countryname, etc), see List */
$userCountryCode = $Geo["geoplugin_countryCode"];

Find this in chatlogin.php:

<script language="javascript" src="config.php?name='.$Username.'&amp;gender='.$Gender.'&amp;userpassword='.$UserPassword.'" type="text/javascript"></script>

Replace it to:

<script language="javascript" src="config.php?name='.$Username.'&amp;gender='.$Gender.'&amp;userpassword='.$UserPassword.'&amp;usercountry='.$userCountryCode.'" type="text/javascript"></script>

Add this in config.php:

$userCountry = strip_tags($_GET['usercountry']);
if(empty($userCountry)) {
    $userCountry = "Unknown";
}
params.ident                        = "<?php echo $userCountry; ?>";

If u want to add City, Region, etc, choose one of this list to add:

geoplugin_request 
geoplugin_status 
geoplugin_credit 
geoplugin_city 
geoplugin_region 
geoplugin_areaCode 
geoplugin_dmaCode 
geoplugin_countryCode
geoplugin_countryName 
geoplugin_continentCode 
geoplugin_latitude 
geoplugin_longitude 
geoplugin_regionCode 
geoplugin_regionName 
geoplugin_currencyCode 
geoplugin_currencySymbol 
geoplugin_currencySymbol_UTF8 
geoplugin_currencyConverter

Don't forgot to add it in the javascript too!

@HeRiNo
Copy link

HeRiNo commented Feb 24, 2015

Hello, can you please explain to me what to do here exactly?

Do not forgot to change your config.js to config.php and the path for lightIRC.swf and expressInstall.swf

I understand the config.php part but not the other 2.
And where exactly do I put the code you wrote under "LightIRC.css"?
And "chatlogin.php" is a file I need to create and then add the code?

Regards, Herman.

@MaleXachi
Copy link
Author

@HeRiNo

Default config file type of lightIRC is .js, but u need to change it to .php (config.php). I say this "Do not forgot to change your config.js to config.php", because some guys has already their own config and it's the most times .js, so they can change it to .php and add some php codes, but if u don't care, then u can download my gist, so not needed to create a file and then paste.

U only need to set path for lightIRC.swf and expressInstall.swf, if u did move both to other folder, but if u didnt, then not needed to set path.

U need to copy css code and paste it to one of css's of lightIRC (lightblue.css, yellow, css or which color you use).

@GHF2014
Copy link

GHF2014 commented Feb 25, 2015

@MaleXachi most of the idents of my users show FR, even mine is FR, and it should be AU, how can I fix this?

@MaleXachi
Copy link
Author

@GHF2014

Try this updated one: https://gist.github.com/MaleXachi/b27d564a6db8167b6ee2#comment-1400059

Note: Update ur whole chatlogin.php, except config.php

Please, click on star. if you like this script, because it's credit for me.

@GHF2014
Copy link

GHF2014 commented Feb 26, 2015

@MaleXachi
It is improved, but now most of the users have Unknown ident, and I believe that is as a result of the hostip.info,
If that can be replaced by any of these domain:

whatismyip.com/ip-address-lookup/
wq.apnic.net/apnic-bin/whois.pl
ip-adress.com/
iplocation.net/
ping.eu/ns-whois/

or if you can get any better one

Thanks in advance

@MaleXachi
Copy link
Author

@GHF2014

Can you try again to update ur chatlogin.php with the code above? If that does not work, i will write own code instead of using API then.

@GHF2014
Copy link

GHF2014 commented Feb 27, 2015

@MaleXachi
I wish it did work, but again, the idents show "Unknown"

@MaleXachi
Copy link
Author

@GHF2014,

It should be work, because i did test all and it works fine for me. Can you show me your chatlogin.php and config.php and link to your website? If you want to hold your website private, u can mail me the link.

"Unknown" happens only if you did wrong something in your php files, because if geoplugin does not know your county, then there is "XX" instead of "Unknown" and "Unknown" is only there, if a value is empty.

Example of Australia IP address: http://www.geoplugin.net/php.gp?ip=54.66.174.94 (Look to Country code ("geoplugin_countryCode")).

Demo's that it works:

Image of image

Image of image

@GHF2014
Copy link

GHF2014 commented Feb 27, 2015

@MaleXachi
After I updated the chatlog, I forgot to change

<script language="javascript" src="config.php?name='.$Username.'&gender='.$Gender.'&userpassword='.$UserPassword.'&usercountry='.$userCountryCode.'" type="text/javascript"></script>

I just edited the code once again and it did work perfect.

Thanks a lot

@MaleXachi
Copy link
Author

@GHF2014

You're welcome.

For some guys of u, u can find start.php of lightIRC here: https://gist.github.com/MaleXachi/660b45e06d685b1e8dc3

@legendsky
Copy link

is that possible, like nicklist appear in the right side same like that channel list appear in the left side??? if that possible please kindly guide it how is that possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment