0

自分の名前が表示されない理由がわかりません。それはセッションであり、すべてが正しく設定されていると思います。もう一組の目が必要です。また、リンク1が正しい最後の部分を連結する方法がわかりません。毎回未定義のインデックスエラーがスローされます。とにかく、コードは以下にあり、事前に感謝します。

<?php
session_start();
//name
if(isset($_SESSION['name'])){
    echo "Session Set";
}
else if(!isset($_SESSION['name']) && isset($_COOKIE['name'])){
$_SESSION['name'] = $_COOKIE['name'];
}
else{
    $_SESSION['name'] = "Bill";
}

//picUrl
if(isset($_SESSION['picURL'])){
    echo "Session Set";
}
else if(!isset($_SESSION['picURL']) && isset($_COOKIE['picURL'])){
$_SESSION['picURL'] = $_COOKIE['picURL'];
}
else{
    $_SESSION['picURL'] = "http://www.mugshots.org/misc/bill-gates.jpg";
}

//bgColor
if(isset($_SESSION['bgColor'])){
    echo "Session Set";
}
else if(!isset($_SESSION['bgColor']) && isset($_COOKIE['bgColor'])){
$_SESSION['bgColor'] = $_COOKIE['bgColor'];
}
else{
    $_SESSION['bgColor'] = "black";
}

//txtColor
if(isset($_SESSION['txtColor'])){
    echo "Session Set";
}
else if(!isset($_SESSION['txtColor']) && isset($_COOKIE['txtColor'])){
$_SESSION['txtColor'] = $_COOKIE['txtColor'];
}
else{
   $_SESSION['txtColor'] = "green";
}

//hyperColor
if(isset($_SESSION['hyperColor'])){
    echo "Session Set";
}
else if(!isset($_SESSION['hyperColor']) && isset($_COOKIE['hyperColor'])){
$_SESSION['hyperColor'] = $_COOKIE['hyperColor'];
}
else{
    $_SESSION['hyperColor'] = "yellow";
}

//vHyperColor
if(isset($_SESSION['vHyperColor'])){
    echo "Session Set";
}
else if(!isset($_SESSION['vHyperColor']) && isset($_COOKIE['vHyperColor'])){
$_SESSION['vHyperColor'] = $_COOKIE['vHyperColor'];
}
else{
    $_SESSION['vHyperColor'] = "red";
}

//aHyperColor
if(isset($_SESSION['aHyperColor'])){
    echo "Session Set";
}
else if(!isset($_SESSION['aHyperColor']) && isset($_COOKIE['aHyperColor'])){
$_SESSION['aHyperColor'] = $_COOKIE['aHyperColor'];
}
else{
    $_SESSION['aHyperColor'] = "cyan";
}

//link1
if(isset($_SESSION['bgColor'])){
    echo "Session Set";
}
else if(!isset($_SESSION['bgColor']) && isset($_COOKIE['bgColor'])){
$_SESSION['bgColor'] = $_COOKIE['bgColor'];
}
else{
    $_SESSION['link1'] = "http://en.wikipedia.org/wiki/Bill_Gates";
}

//link2
if(isset($_SESSION['link2'])){
    echo "Session Set";
}
else if(!isset($_SESSION['link2']) && isset($_COOKIE['link2'])){
$_SESSION['link2'] = $_COOKIE['link2'];
}
else{
    $_SESSION['link2'] = "http://www.usdoj.gov/atr/cases/ms_index.htm";
}

//link3
if(isset($_SESSION['link3'])){
    echo "Session Set";
}
else if(!isset($_SESSION['link3']) && isset($_COOKIE['link3'])){
$_SESSION['link3'] = $_COOKIE['link3'];
}
else{
    $_SESSION['link3'] = "http://www.microsoft.com";
}

//link1Name
if(isset($_SESSION['link1Name'])){
    echo "Session Set";
}
else if(!isset($_SESSION['link1Name']) && isset($_COOKIE['link1Name'])){
$_SESSION['link1Name'] = $_COOKIE['link1Name'];
}
else{
    $_SESSION['link1Name'] = "Bill Gates Net Worth Page";
}

//link2Name
if(isset($_SESSION['link2Name'])){
    echo "Session Set";
}
else if(!isset($_SESSION['link2Name']) && isset($_COOKIE['link2Name'])){
$_SESSION['link2Name'] = $_COOKIE['link2Name'];
}
else{
    $_SESSION['link2Name'] = "United States v. Microsoft";
}

//link3Name
if(isset($_SESSION['link3Name'])){
    echo "Session Set";
}
else if(!isset($_SESSION['link3Name']) && isset($_COOKIE['link3Name'])){
$_SESSION['link3Name'] = $_COOKIE['link3Name'];
}
else{
    $_SESSION['link3Name'] = "Microsoft Home Page";
}

?>
<html>

<head>
<title>A05_SessionColors</title>
</head>

<body bgcolor="<?php echo $_SESSION['bgColor']?>" 
      text="<?php echo $_SESSION['txtColor']?>" 
      link="<?php echo $_SESSION['hyperColor']?>" 
      vlink="<?php echo $_SESSION['vHyperColor']?>" 
      alink="<?php echo $_SESSION['aHyperColor']?>">



<center>
<h1><?php echo $_SESSION['name'] ?>'s Home Page</h1>
<p><img border="0" src=<?php echo '"'.$_SESSION['picURL'].'"'?>/></p>
<h2>My Three Favorite Links</h2>
<ul>
  <li>
    <p style="line-height: 150%"><a href=<?php echo '"'.$_SESSION['link1'].'"'?>/><?php echo $_SESSION['link1Name']?></a></li>
  <li>
    <p style="line-height: 150%"><a href=<?php echo '"'.$_SESSION['link2'].'"'?>/><?php echo $_SESSION['link2Name']?></a></li>
  <li>
    <p style="line-height: 150%"><a href=<?php echo '"'.$_SESSION['link3'].'"'?>/><?php echo $_SESSION['link3Name']?></a>&nbsp;</li>
</ul>


</center>

<h3 align="center">Click <a href="optionsForm.php">HERE</a> to change display options.</h3>

<p>&nbsp;</p>

</body>

</html>
4

1 に答える 1