Follow along with the video below to see how to install our site as a web app on your home screen.
Бележка: This feature may not be available in some browsers.
<?php
session_start();
function connect_site($url, $mode = 'GET', $post_args = array())
{
global $_SESSION;
$info = parse_url($url);
$s = md5(strtolower($info['host']));
if (!array_key_exists('path', $info))
{
$parts['path'] = '/';
}
if (!array_key_exists('port', $info))
{
$info['port'] = 80;
}
if (!array_key_exists('scheme', $info))
{
$info['scheme'] = 'http';
}
$ret = array();
$fp = @fsockopen($info['host'], $info['port'], $errno, $errstr, 30) or die('connection failed');
$headers = array();
$out = $mode . ' '.$info['path'].(isset($info['query']) ? '?' . @$info['query'] : '')." HTTP/1.1\r\n".
'Host: '.$info['host'].($info['port'] <> 80 ? ':'.$info['port'] : '')."\r\n";
if ( isset($_SESSION[$s]['cookie']) && is_array($_SESSION[$s]['cookie']) )
{
foreach($_SESSION[$s]['cookie'] as $k => $v)
{
$cookies[] = $k .'='.$v;
}
$out .= 'Cookie:' . implode("; ", $cookies) . "\r\n";
}
if ( $mode == 'POST')
{
$out .= 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
}
$out .= 'Connection: Close'."\r\n";
if ( $mode == 'POST' && is_array($post_args) && sizeof($post_args))
{
$args = array();
foreach ($post_args as $k => $v )
{
$args[] = urlencode($k) . '=' . urlencode($v);
}
$out .= implode('&', $args);
unset($args);
}
fwrite($fp, $out);
while (!feof($fp) && $line = fgets($fp, 1024))
{
if ( $line == "\r\n" )
{
break;
}
list($k, $v) = explode(":", $line, 2);
$headers[strtolower(trim($k))] = $v;
}
foreach( $headers as $k => $v )
{
switch ( $k )
{
case 'set-cookie':
$v = explode(";", $v, 2);
list($cookie_name, $cookie_value) = explode("=", $v[0], 2);
$_SESSION[$s]['cookie'][$cookie_name] = $cookie_value;
break;
case 'location':
$redirect = $v;
$newinfo = parse_url($redirect);
if (!array_key_exists('host', $newinfo))
{
$redirect = (strpos($redirect, '/') !== 0) ? '/' . $redirect : $redirect;
$redirect = $info['host'] ( $info['port'] <> 80) ? ':' . $info['port'] : '') . $redirect;
}
if (!array_key_exists('scheme', $newinfo))
{
$redirect = $info['scheme'].'://'.$redirect;
}
connect_site($redirect, 'GET');
break;
default:
continue;
}
}
}
connection_site('site', 'POST', array('username' => 'lqlq', 'password' => 'flqflq'));