sorsha Posted December 11, 2010 Share Posted December 11, 2010 Hello I am trying to encorporate this php script into my login only section of my project. When you first go in and go to the page this session is still there, but when you select any letter to play the game it looses the session id and essentially logs you out. Can any one help. I cant figure this out iv been staring at it for days Thanks in advance ! <?php session_name ('YourVisitID'); ini_set('session.use_cookies', 0); // Don't use cookies. session_start(); include ('./includes/header.inc'); /* ##################################################################### # PHP Hangman Game # # Version 1.2.0 # # ©2002,2003 0php.com - Free PHP Scripts # ##################################################################### ##################################################################### # # # Author : 0php.com # # Created : July 12, 2002 # # Modified : March 22, 2004 # # E-mail : [email protected] # # Website : http://www.0php.com/ # # License : FREE (GPL); See Copyright and Terms below # # # # Donations accepted via PayPal to [email protected] # # # ##################################################################### >> Copyright and Terms: This software is copyright © 2002-2004 0php.com. It is distributed under the terms of the GNU General Public License (GPL). Because it is licensed free of charge, there is NO WARRANTY, it is provided AS IS. The author can not be held liable for any damage that might arise from the use of this software. Use it at your own risk. All copyright notices and links to 0PHP.com website MUST remain intact in the scripts and in the HTML for the scripts. For more details, see http://www.0php.com/license_GNU_GPL.php (or http://www.gnu.org/). >> Installation Copy the PHP script and images to the same directory. You can optionally edit the category and list of words/phrases to solve below. You can also add additional characters to $additional_letters and/or $alpha if you want to use international (non-English) letters or other characters not included by default (see further instructions below for those). To prevent Google from playing hangman, add the line below between <HEAD> and </HEAD>: <META NAME="robots" CONTENT="NOINDEX,NOFOLLOW"> =======================================================================================*/ $Category = "Favorite Movies"; # list of words (phrases) to guess below, separated by new line $list = "GONE WITH THE WIND STAR WARS BIODOME HOW TO TRAIN A DRAGON IRON MAN TOMBSTONE DANCES WITH WOLVES BIG TROUBLE IN LITTLE CHINA MR AND MRS SMITH GONE IN SIXTY SECONDS EVER AFTER BEAUTY AND THE BEAST ANNA AND THE KING CONTACT ROBIN HOOD LABYRINTH SUPERMAN MONSTERS INC SAVE THE LAST DANCE THE LAST AIRBENDER THE A TEAM DESPICABLE ME THE EXPENDABLES THE SORCERERS APPRENTICE CHARLIE ST CLOUD INCEPTION SALT MACHETE DEAR JOHN JULIE AND JULIA THE MEN WHO STARE AT GOATS ANGELS AND DEAMONS THE DAVINCI CODE SHERLOCK HOLMES PIRATES OF THE CARRIBEAN THE CORE EAGLE EYE PUSH BOURNE IDENTITY THE ILLUSIONIST TOTAL RECALL ENEMY OF THE STATE MEN IN BLACK BAD BOYS MISS CONGENIALITY UNDERWOLRD NIGHT AT THE MUSEUM ALIENS PREDATOR"; # make sure that any characters to be used in $list are in either # $alpha OR $additional_letters, but not in both. It may not work if you change fonts. # You can use either upper OR lower case of each, but not both cases of the same letter. # below ($alpha) is the alphabet letters to guess from. # you can add international (non-English) letters, in any order, such as in: # $alpha = "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝŸABCDEFGHIJKLMNOPQRSTUVWXYZ"; $alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; # below ($additional_letters) are extra characters given in words; '?' does not work # these characters are automatically filled in if in the word/phrase to guess $additional_letters = " -.,;!?%&0123456789"; #========= do not edit below here ====================================================== echo<<<endHTML <HTML><HEAD><TITLE>Play PHP Hangman Game</TITLE> <META NAME="DESCRIPTION" CONTENT="A Free PHP Script © www.0php.com"> <meta content="text/html; charset=windows-1252" http-equiv=content-type> <meta http-equiv="Content-Style-Type" content="text/css"> <style type="text/css"> <!-- H1 {font-family: "Courier New", Courier, monospace; font-size: 18pt;} P {font-family: Verdana, Arial, sans-serif; font-size: 12pt;} A:link {COLOR: #0000FF; TEXT-DECORATION: underline;} A:visited {COLOR: #0000FF; TEXT-DECORATION: underline;} A:active {COLOR: #0000FF; TEXT-DECORATION: underline;} A:hover {COLOR: #FF0000; TEXT-DECORATION: underline;} --> </style> </HEAD> <BODY bgColor="#CCCCCC" link="navy" vlink="navy" alink="navy"> <DIV ALIGN="center"> endHTML; $len_alpha = strlen($alpha); if(isset($_GET["n"])) $n=$_GET["n"]; if(isset($_GET["letters"])) $letters=$_GET["letters"]; if(!isset($letters)) $letters=""; if(isset($PHP_SELF)) $self=$PHP_SELF; else $self=$_SESSION["PHP_SELF"]; $links=""; $max=6; # maximum number of wrong # error_reporting(0); $list = strtoupper($list); $words = explode("\n",$list); srand ((double)microtime()*1000000); $all_letters=$letters.$additional_letters; $wrong = 0; echo "<P><B>Play PHP Hangman Game</B> - Category: <B>$Category</B><BR>\n"; if (!isset($n)) { $n = rand(1,count($words)) - 1; } $word_line=""; $word = trim($words[$n]); $done = 1; for ($x=0; $x < strlen($word); $x++) { if (strstr($all_letters, $word[$x])) { if ($word[$x]==" ") $word_line.=" "; else $word_line.=$word[$x]; } else { $word_line.="_<font size=1> </font>"; $done = 0; } } if (!$done) { for ($c=0; $c<$len_alpha; $c++) { if (strstr($letters, $alpha[$c])) { if (strstr($words[$n], $alpha[$c])) {$links .= "\n<B>$alpha[$c]</B> "; } else { $links .= "\n<FONT color=\"red\">$alpha[$c] </font>"; $wrong++; } } else { $links .= "\n<A HREF=\"$self?letters=$alpha[$c]$letters&n=$n\">$alpha[$c]</A> "; } } $nwrong=$wrong; if ($nwrong>6) $nwrong=6; echo "\n<p><BR>\n<IMG SRC=\"count_$nwrong.jpg\" ALIGN=\"MIDDLE\" BORDER=0 WIDTH=100 HEIGHT=100 ALT=\"Wrong: $wrong out of $max\">\n"; if ($wrong >= $max) { $n++; if ($n>(count($words)-1)) $n=0; 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"; echo "The $term was \"<B>$word</B>\"<BR><BR>\n"; echo "<A HREF=$self?".SID."n=$n>Play again.</A><BR><BR>\n\n"; echo "<IMG SRC=\"frown.jpg\"> \n<br><br>\n"; echo "Please Try again. Better luck next time!\n\n"; } else { echo " That letter is not in the movie title. # of 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"; } } else { $n++; # get next word if ($n>(count($words)-1)) $n=0; echo "<BR><BR><H1><font size=5>\n$word_line</font></H1>\n"; echo "<P><BR><BR><B>Congratulations!!! You win!!!</B><BR><BR><BR>\n"; echo "<A HREF=$self?".SID."n=$n>Play again</A>\n<br><br>\n"; echo "<IMG SRC=\"congrats.jpg\"> \n<br><br>\n"; } echo<<<endHTML <p align="center"><BR><BR><font face="Verdana" size="1">PHP Hangman Game - Version 1.2.0<br> <a href="http://www.0php.com" target="_top">Free PHP Scripts</a> - Copyright © <a href="http://www.0php.com" target="_top">0php.com</a> 2002-2004.</font> </DIV></BODY></HTML> endHTML; ?> Quote Link to comment https://forums.phpfreaks.com/topic/221274-loosing-session-id/ Share on other sites More sharing options...
Pikachu2000 Posted December 11, 2010 Share Posted December 11, 2010 What makes you think the value is being lost, rather than not getting set in the first place? Quote Link to comment https://forums.phpfreaks.com/topic/221274-loosing-session-id/#findComment-1145625 Share on other sites More sharing options...
sorsha Posted December 11, 2010 Author Share Posted December 11, 2010 Well the way I am using this is after you log in your able to get to this game. You click on this link for Hangman and it goes to the game, You can see your session Id in the address bar, and it still shows you as logged in, but as soon as you click on the letter, you have to log in again and start over, and there is no session id in the bar any more Quote Link to comment https://forums.phpfreaks.com/topic/221274-loosing-session-id/#findComment-1145644 Share on other sites More sharing options...
PFMaBiSmAd Posted December 11, 2010 Share Posted December 11, 2010 A) You need to put the SID constant into those links as well (did you do a 'view source' of the page to see what you were getting?) B) You need to turn off session.use_only_cookies as well. C) Your session_name is apparently too long (at least on my system.) D) Why aren't you using a cookie for the session id? Quote Link to comment https://forums.phpfreaks.com/topic/221274-loosing-session-id/#findComment-1145647 Share on other sites More sharing options...
sorsha Posted December 11, 2010 Author Share Posted December 11, 2010 I did do the page source and I saw the links had a session Id before you click on the letter. I tried putting the ".SID." in the link but ever where I seem to put it doesnt work. The reason I am not using cookies was the project was that he gave us he did a couple of pages for us to use after the person is logged in, and I as using those as a model, but I cant seem to make it right with this page... He did not do a very good job of teaching this in my opinion. Pretty much look at my code for a different page and make it work with this one Quote Link to comment https://forums.phpfreaks.com/topic/221274-loosing-session-id/#findComment-1145812 Share on other sites More sharing options...
sorsha Posted December 11, 2010 Author Share Posted December 11, 2010 Im pretty sure its something to do with these lines of code but I dont know where to put the .SID. if (strstr($words[$n], $alpha[$c])) {$links .= "\n<B>$alpha[$c]</B> "; } { $links .= "\n<A HREF=\"$self?letters=$alpha[$c]$letters&n=$n\">$alpha[$c]</A> "; } Quote Link to comment https://forums.phpfreaks.com/topic/221274-loosing-session-id/#findComment-1145814 Share on other sites More sharing options...
PFMaBiSmAd Posted December 11, 2010 Share Posted December 11, 2010 { $links .= "\n<A HREF=\"$self?".SID."&letters=$alpha[$c]$letters&n=$n\">$alpha[$c]</A> "; } Quote Link to comment https://forums.phpfreaks.com/topic/221274-loosing-session-id/#findComment-1145821 Share on other sites More sharing options...
sorsha Posted December 11, 2010 Author Share Posted December 11, 2010 THank you thank YOU When I had tried putting the code in there I had it before the ? now it worked using the letters, but as soon as I hit play again it looses it again..do I have that in the wrong spot as well? echo "<A HREF=$self?".SID."n=$n>Play again.</A><BR><BR>\n\n"; I also get this error printed out at the top of the screen Warning: session_start() [function.session-start]: The session id contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in /var/www/html/final/hangmanrev.php on line 8 Quote Link to comment https://forums.phpfreaks.com/topic/221274-loosing-session-id/#findComment-1145827 Share on other sites More sharing options...
PFMaBiSmAd Posted December 11, 2010 Share Posted December 11, 2010 The other links correctly have the SID in them. As to the error message, just read what it is telling you and someone already posted about it - C) Your session_name is apparently too long (at least on my system.) Quote Link to comment https://forums.phpfreaks.com/topic/221274-loosing-session-id/#findComment-1145828 Share on other sites More sharing options...
sorsha Posted December 12, 2010 Author Share Posted December 12, 2010 got it Thanks so much for the help Quote Link to comment https://forums.phpfreaks.com/topic/221274-loosing-session-id/#findComment-1145989 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.