I need to set timeout on client.recv in TCP server.
last parameter of fsockopen
resource fsockopen ( string $hostname [, int $port = -1 [, int &$errno [, string &$errstr [, float $timeout = ini_get("default_socket_timeout") ]]]] )
Related
From the PHP's setcookie documentation the function signature is
bool setcookie ( string $name [, string $value = "" [, int $expire = 0 [, string $path = "" [, string $domain = "" [, bool $secure = false [, bool $httponly = false ]]]]]] )
If I only want to set the $name, $value and $httponly params, and allow the defaults to take effect for the other params. will I still have to lookup the default values for all the other optional params and set them in order to "reach" the $httponly param? e.g:
<?php
setcookie('double_track', '1234567890', 0, '', '', false, true);
^ ^ ^ ^
(do I have to look
up and specify these
values?)
Is there any way around this?
Native PHP methods are specified like that and you can do nothing about it.
However, you can specify your own wrapper method around the native one:
function setMyCookie($name, $value, $httpOnly)
{
setcookie($name, $value, 0, '', '', false, $httpOnly);
// ^ ^ ^ ^
// (specify default values)
}
Now, you may just use setMyCookie as this:
setMyCookie('double_track', '1234567890', true);
I am creating a cookie from this URL "/component/user" in this way:
setcookie("isLogged", $options['user']->name);
I know it will be removed when the browser close, but doing in this way the cookie will be set up only for the "/component/user" URL instead the whole website, so I did this other one with the intention to make it work for whole the website:
setcookie("isLogged", $options['user']->name, "", "/");
but the cookie is not created, what I need is a cookie that expire when the browser close and also set it up for whole website. What am I doing wrong?
From the docs:
bool setcookie ( string $name [, string $value = "" [, int $expire = 0 [, string $path = "" [, string $domain = "" [, bool $secure = false [, bool $httponly = false ]]]]]] )
Use $expire = 0, as it's a timestamp not a string
setcookie("isLogged", $options['user']->name, 0, "/");
Is it possible to set the path and domain one time at the beginning of the script and have all future sets conform to the same?
From the docs:
bool setcookie ( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] )
sure:
function own_setcookie($name, $value, $expire=0) {
setcookie($name, $value , $expire, 'myPath', 'myDomain');
}
then use:
own_setcookie('myName', 'myValue');
While looking at someone's code today, I saw this:
public $setCookieFunction = 'setcookie';
$setcookie = $this->setCookieFunction;
Anyone knows how this works?
Thanks!
It's likely invoked like this, with the same parameters as setcookie():
$setcookie( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] );
Or:
$this->$setCookieFunction( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] );
The benefit here is that you can change $this->setcookie to whatever function name you want, and that function will get called across the class.
What is Delphi equivalent to "fsockopen" function in php?
in PHP Manual:
resource fsockopen ( string $hostname [, int $port = -1 [, int &$errno [, string &$errstr [, float $timeout = ini_get("default_socket_timeout") ]]]] )
Initiates a socket connection to the resource specified by hostname.
My code is fully:
function accountcreate($username, $password, $connection, $bandwidth, $disabledate, $disabletime)
{
$adminpassword='';
$adminport=82;
$proxyaddress='127.1.1.1';
$fp = fsockopen($proxyaddress, $adminport, &$errno, &$errstr, 1000);
if(!$fp)
{
echo "$errstr ($errno)<br>\n";
}
else
{
$url_ = "/account";
$url = "add=1"."&";
.
.
$url = $url."userid=-1";
$len = "Content-Length: ".strlen($url);
$auth = "Authorization: Basic ".base64_encode("admin:".$adminpassword);
$msg = "POST ".$url_." HTTP/1.0\r\nHost: ".$proxyaddress."\r\n".$auth."\r\n".$len."\r\n"."\r\n".$url;
fputs($fp,$msg);
echo $msg;
fclose($fp);
}
that code make a new account in ccproxy.
Perhaps have a look at the Indy Components that ship with Delphi (assuming at least Delphi7). You would need :
TIdTCPConnection Documentation
which contains an IOHandler property (TIdIOHandler) where you specify the parameters used in fsockopen:
TIdTCPConnection.IOHandler Property
TIdIOHandler Documentation
As others have noted, however, you probably would be well served by looking at the bigger picture in your PHP code and perhaps implementing its functionality with a higher level tool like TIdHTTP :
TIdHTTP Documentation