Jump to content

sagnik

Members
  • Posts

    483
  • Joined

  • Last visited

  • Days Won

    1

sagnik last won the day on February 23 2018

sagnik had the most liked content!

About sagnik

  • Birthday 09/13/1996

Contact Methods

  • MSN
    sagnikganguly2012
  • Website URL
    http://www.sgnetworks.cf
  • Yahoo
    sagnikganguly0

Profile Information

  • Gender
    Male
  • Location
    Durgapur, West Bengal, India
  • Interests
    Traveling, Gaming, Listening to music, Programming, Exploring novel discoveries

Recent Profile Visitors

5,588 profile views

sagnik's Achievements

Proficient

Proficient (10/14)

  • Reacting Well Rare
  • First Post Rare
  • Collaborator Rare
  • Conversation Starter Rare
  • One Year In Rare

Recent Badges

4

Reputation

  1. Hi, I'm trying to log in to the FTP server of my account located at the Johnny server. But I'm getting an error saying "Unable to connect to the server". Can you provide the details of the FTP server? Username: sgn
  2. @wolstech Okay, I got your point. But I have a centralized login system for all the services/platforms which uses a database called "members" and the tables (specifically, "accounts") in it and a specific column of that table namely "uid" as a foreign key relation, i.e. if a row of that table is deleted this would delete all the information located throughout all other databases related to the "uid". Please let me know if there are any other ways to achieve this.
  3. Hi, is there any way to create a foreign key linked to another database? I can't see all the databases in PMA.
  4. @badrihippo Here is the code of SSO SignOn.php: <?php /* * Copyright (c) 2022-2023 SGNetworks. All rights reserved. * * The software is an exclusive copyright of "SGNetworks" and is provided as is exclusively with only "USAGE" access. "Modification", "Alteration", "Re-distribution" is completely prohibited. * VIOLATING THE ABOVE TERMS IS A PUNISHABLE OFFENSE WHICH MAY LEAD TO LEGAL CONSEQUENCES. */ session_start(); $SGNSSO = ['accounts.sgnetworks.net', 'accounts.sgnetworks.eu.org']; function is_base64(string $data): bool { $base64 = base64_encode(base64_decode($data, true)); return ($base64 === $data); } function is_base64URL(string $data): bool { $base64 = strtr($data, '-_', '+/'); $base64 = base64_encode(base64_decode($base64)); $base64 = strtr(rtrim($base64, '='), '+/', '-_'); return ($base64 === $data); } function Base64UrlEncode(string $data, bool $force = false): string { if($force) { return strtr(rtrim(base64_encode($data), '='), '+/', '-_'); } $base64 = (!is_base64($data)) ? base64_encode($data) : $data; return (!is_base64URL($base64)) ? strtr(rtrim($base64, '='), '+/', '-_') : $base64; } function Base64UrlDecode(string $base64, bool $strict = false): string|false { $data = (is_base64URL($base64)) ? strtr($base64, '-_', '+/') : $base64; return (is_base64($data)) ? base64_decode($data, $strict) : base64_decode($data); } function server(string $key, string|int|bool|array $default = null): array|bool|int|string|null { $server = $_SERVER; $null = ($default === null && !is_bool($default) && !is_array($default) && !is_integer($default) && !is_string($default)) ? null : $default; return (array_key_exists($key, $server)) ? $server[$key] : $null; } function session(string $key, string|int|bool|array $default = null): array|bool|int|string|null { $session = $_SESSION; $null = ($default === null && !is_bool($default) && !is_array($default) && !is_integer($default) && !is_string($default)) ? null : $default; return (array_key_exists($key, $session)) ? $session[$key] : $null; } function post(string $key, string|int|bool|array $default = null): array|bool|int|string|null { $post = $_POST; $null = ($default === null && !is_bool($default) && !is_array($default) && !is_integer($default) && !is_string($default)) ? null : $default; return ((array_key_exists($key, $post)) ? $post[$key] : $null); } function get(string $key, string|int|bool|array $default = null): array|bool|int|string|null { $get = $_GET; $null = ($default === null && !is_bool($default) && !is_array($default) && !is_integer($default) && !is_string($default)) ? null : $default; return (array_key_exists($key, $get)) ? $get[$key] : $null; } function buildURL(string $uri, ?string $params = null, ?string $args = null): string { $params = (!empty($params)) ? ltrim($params, '?' . '&') : ''; $args = (!empty($args)) ? ltrim($args, '?' . '&') : ''; if(!empty($params) && !empty($args)) { $url = (str_contains($uri, '?') || str_contains($params, '?') || str_contains($args, '?')) ? "$uri&$params&$args" : "$uri?$params&$args"; } elseif(!empty($params) && empty($args)) { $url = (str_contains($uri, '?') || str_contains($params, '?')) ? "$uri&$params" : "$uri?$params"; } elseif(empty($params) && !empty($args)) { $url = (str_contains($uri, '?') || str_contains($args, '?')) ? "$uri&$args" : "$uri?$args"; } else { $url = $uri; } $url_parts = parse_url($url); $qs = ''; if(array_key_exists('query', $url_parts)) { $qs = $url_parts['query']; parse_str($qs, $qo); $qs = (count($qo) > 0) ? http_build_query($qo) : ''; } $constructed_url = $url_parts['scheme'] . '://' . $url_parts['host'] . ($url_parts['path'] ?? ''); return (!empty($qs)) ? "$constructed_url?$qs" : $constructed_url; } function redirect(string $uri, string $vars = ''): void { $qm = (str_contains($uri, '?') || str_contains($vars, '?')) ? '&' : '?'; $url = buildURL($uri); if(!headers_sent()) { header("Location: $url"); exit(); } else { echo '<script>'; echo "window.location.href=('$url');"; echo '</script>'; echo "You will be redirected shortly. If you are not redirected automatically, please <a href='$url'>click here</a> to redirect"; } } function get_domain(string $url): string|false { $urlobj = parse_url($url); $domain = $urlobj['host']; if(preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z.]{2,6})$/i', $domain, $regs)) { return $regs['domain']; } return false; } if(server('REQUEST_METHOD') == 'POST') { $redirectTo = (!post('continue')) ? post('redirect') : post('continue'); $params = post('params', ''); $args = post('args', ''); $session = post('session'); $origin = post('origin'); } else { $redirectTo = (!get('continue')) ? get('redirect') : get('continue'); $params = get('params', ''); $args = get('args', ''); $session = get('session'); $origin = get('origin'); } $sc = explode('-', $session); $sessid = Base64UrlDecode($sc[0]); $uid = Base64UrlDecode($sc[1]); $uid_hashed = Base64UrlDecode($sc[2]); $ssoProcessed = false; $continueHost = $continue = ''; if(in_array($origin, $SGNSSO)) { $args = Base64UrlDecode($args); $redirectTo = Base64UrlDecode($redirectTo); $redirectTo = buildURL($redirectTo, $args); if(empty(session('sgn-login-sid'))) { if(empty($session)) { $continue = (!$redirectTo) ? $origin . server('REQUEST_URI') : $redirectTo; } else { $_SESSION['sgn-login-sid'] = $sessid; $_SESSION['sgn-login-uid'] = $uid; $_SESSION['sgn-login-uid_hashed'] = $uid_hashed; $_SESSION['sgn-login-expires'] = time() + 3600; $_SESSION['sgn-login-timestamp'] = time(); $_SESSION['sgn-login-ip'] = server('REMOTE_ADDR'); $ssoProcessed = true; $url = parse_url($redirectTo); $p = (array_key_exists('path', $url)) ? $url['path'] : ''; $q = (array_key_exists('query', $url)) ? '?' . $url['query'] : ''; $s = (!$q) ? "?sessid=$sessid" : "&sessid=$sessid"; unset($redirectTo); unset($_GET['session']); $continueUrl = $url['scheme'] . '://' . $url['host'] . $p . $q; $continue = "$continueUrl$s"; $continue = (!$continue) ? $_SERVER['HTTP_REFERER'] : $continue; $continueHost = $url['host']; $continueLocation = "{$url['scheme']}://$continueHost"; } } elseif(!empty($session)) { $_SESSION['sgn-login-sid'] = $sessid; $_SESSION['sgn-login-uid'] = $uid; $_SESSION['sgn-login-uid_hashed'] = $uid_hashed; $_SESSION['sgn-login-expires'] = time() + 3600; $_SESSION['sgn-login-timestamp'] = time(); $_SESSION['sgn-login-ip'] = server('REMOTE_ADDR'); $ssoProcessed = true; if(!empty($redirectTo)) { $url = parse_url($redirectTo); $p = (array_key_exists('path', $url)) ? $url['path'] : ''; $q = (array_key_exists('query', $url)) ? '?' . $url['query'] : ''; $s = (!$q) ? "?sessid=$sessid" : "&sessid=$sessid"; unset($redirectTo); unset($_GET['session']); $continueUrl = $url['scheme'] . '://' . $url['host'] . $p . $q; $continue = "$continueUrl$s"; $continue = (!$continue) ? $_SERVER['HTTP_REFERER'] : $continue; $continueHost = $url['host']; $continueLocation = "{$url['scheme']}://$continueHost"; } else { $continue = $_SERVER['HTTP_REFERER']; } } $params = (!empty($params)) ? Base64UrlDecode($params) : ''; $continue = buildURL($continue, $params); } else { echo 'The Origin Host is not allowed to make SSO Requests'; } if($_SERVER['REQUEST_METHOD'] == 'GET'): ?> <script> function crossDomainLogin() { const url = "<?=$continueLocation;?>/SGNSSO/SignOn"; const xhr = new XMLHttpRequest(); xhr.onerror = function() { if(xhr.status === 0) { console.log("Cross-Domain Request Failed"); } else { console.log("Cross-Domain Request Failed with the following Status: ", xhr.status); } }; xhr.onreadystatechange = function() { if(this.readyState === 4 && this.status === 200) { if(xhr.responseText === "done") { window.location.replace("<?=$continue;?>"); } else { console.log("SGNSSO is available only for SGNetworks and its Subsidiaries"); } } else { //console.log("Cross-Domain Request is not ready or the request has failed with status: ",this.status); } }; xhr.open("POST", url); xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhr.crossDomain = true; xhr.withCredentials = true; xhr.send("session=<?=$session;?>&origin=<?=$origin;?>&redirect=<?=Base64UrlEncode($continueUrl);?>"); } const sso = <?=($ssoProcessed) ? 'true' : 'false';?>; if(window.location.host !== '<?=$continueHost;?>') { crossDomainLogin(); } else { if(sso === true || sso === "true") { window.location.replace("<?=$continue;?>"); } } </script> <?php elseif($ssoProcessed): echo 'done'; else: echo 'failed'; endif;
  5. Those variables are changed when a user submits their login credentials and are validated. So, I need to pass the PHPSESSID cookie as well to the WS server, right?
  6. I use some keys namely "sgn-login-uid", "sgn-login-sessid", "sgn-login-ip", "sgn-login-timestamp" & "sgn-login-expires" to authenticate a user by setting $_SESSION variables for the aforementioned keys. So every time a new user is authenticated those values have to be changed.
  7. I want to replicate the exact UI that WhatsApp has for its status screen to show the count of statuses along with active and inactive contexts. See the image for reference:
  8. Yes, as I cannot start a session within WebSocket because it will replace the previous session whenever a new client is authenticated.
  9. The platform doesn't use any third-party service. The SSO is also its own which I've developed.
  10. Thanks for the advice, but the service has its login service, which uses SSO but the problem is handling the sessions within the WebSocket server for multiple clients.
  11. Hi, I'm creating a social media with a real-time chat application using PHP WebSocket, the basic functionalities are working properly but I need to implement some other features as well. So I need help with the following related to the chat application: Login to the WebSocket using the credentials users use to log into the social media. Allow users to chat with their friends only. Identify users from the database using their ID and fetch data from the database. Show online/offline status based on the WebSocket. Show if a message is pending/sent/delivered/seen status. Show typing notification to the other user. I'm attaching a screenshot of the chat screen:
  12. No, see, I'm currently trying to setup the WS server on my localhost using Apache & PHP on Windows
×
×
  • Create New...