b.php
<?php function getClientIP()
{
if (getenv("HTTP_CLIENT_IP"))
$ip = getenv("HTTP_CLIENT_IP");
else if(getenv("HTTP_X_FORWARDED_FOR"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if(getenv("REMOTE_ADDR"))
$ip = getenv("REMOTE_ADDR");
else $ip = "Unknow"; return $ip;
} session_start(); $_SESSION['id'] = getClientIP(); // 将客户端ip传入session, 在c.php中取 $sessionid = $_SESSION['id']; var_dump($sessionid);
c.php
<?php session_start(); $clientIp = $_SESSION['id']; // 取session出来用
var_dump($clientIp);