Hi everyone.

I'm thiiis close to losing my wits over this. I'm working on carrying Session ID via the url (not secure, I know, but it's not meant to be) and I cannot for the life of me get this to work.

This is a hangman script (pre-written by someone else) that I need to carry the session id from the alphabet letters through the rest of the game and through both play again links. I think the trouble I'm having is the rest of my session ID links were neat ___.php links, rather than what these are, and I've tried every way I can think of to pass the SID without luck.

<?php
session_name ('YourVisitID');
ini_set('session.use_cookies', 0); // Don't use cookies.
session_start();

$Category = "Animals";
# list of words (phrases) to guess below, separated by new line
$list = "
Dog
Cat
Mouse
Lion
Bear"; 

    # if the current alphabet NOT found in the selected letters
    # at the link, add the currently selected letter
    else
    { $links .= "\n<A HREF=\"$self?letters=$alpha[$c]$letters&n=$n\">$alpha[$c]</A> "; }
  }
  # update the number of wrong choices
  # display a corresponding image
  $nwrong=$wrong; 
  if ($nwrong>6) $nwrong=6;
  echo "\n<p><BR>\n<IMG src=\"hangman_$nwrong.gif\" ALIGN=\"MIDDLE\" BORDER=0 WIDTH=100 HEIGHT=100 ALT=\"Wrong: $wrong out of $max\">\n";
  # if reached the max wrong trials
  if ($wrong >= $max)
  {
    $n++; # get the next word
    if ($n>(count($words)-1)) $n=0; # if the last, back to the first
    echo "<BR><BR><H1><font size=5>\n$word_line</font></H1>\n";
    echo "<p><BR><FONT color=\"red\"><BIG>SORRY, YOU ARE HANGED!!!</BIG></FONT><BR><BR>";
    if (strstr($word, " ")) $term="phrase"; else $term="word"; #check if phrase
    echo "The $term was \"<B>$word</B>\"<BR><BR>\n";
    echo "<A HREF=$self?n=$n".SID.">Play again.</A>\n\n";
  }
  
  # if not reached the max wrong trials 
  else
  {
    echo " &nbsp; # Wrong Guesses Left: <B>".($max-$wrong)."</B><BR>\n";
    echo "<H1><font size=5>\n$word_line</font></H1>\n";
    echo "<P><BR>Choose a letter:<BR><BR>\n";
    echo "$links\n";
  }
}

# if all the letters are matched ($done is true (1)) 
else
{
  $n++; # get next word
  if ($n>(count($words)-1)) $n=0; # if the last, back to the first
  echo "<BR><BR><H1><font size=5>\n$word_line</font></H1>\n";
  echo "<P><BR><BR><B>Congratulations!!! &nbsp;You win!!!</B><BR><BR><BR>\n";
  echo "<A HREF=$self?n=$n".SID.">Play again</A>\n\n";
}
?>

Any help is very much appreciated!

Recommended Answers

All 2 Replies

Any particular reason why you're disabling cookie functionality, that would solve your problem right there.

ellabean, I think in PHP.ini there is a directive that tell's PHP whether appending sessions in the URL is allowed or not. It may have been added later, or the default changed in later PHP versions. I'm just recalling from reading the php session docs, so take a look, I might be wrong...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.