startsession php code example
Example 1: php string starts with
substr( $http, 0, 4 ) === "http";
substr( $https, 0, 5 ) === "https";
Example 2: php string ends with
function stringStartsWith($haystack,$needle,$case=true) {
if ($case){
return strpos($haystack, $needle, 0) === 0;
}
return stripos($haystack, $needle, 0) === 0;
}
function stringEndsWith($haystack,$needle,$case=true) {
$expectedPosition = strlen($haystack) - strlen($needle);
if ($case){
return strrpos($haystack, $needle, 0) === $expectedPosition;
}
return strripos($haystack, $needle, 0) === $expectedPosition;
}
echo stringStartsWith("Hello World","Hell");
echo stringEndsWith("Hello World","World");
Example 3: create session in php
<?php
session_start();
$_SESSION["color"]= "blue";
$_SESSION["animal"]= "dog";
echo "The session variable are set up.";
?>
Example 4: session start php
<?php
session_start([
'cookie_lifetime' => 86400,
]);
?>