This, as per your initial/original post and not marking it as an edit, including all other edits you've made.
which your edit still contains a quote $'_SESSION["favcolor"] between $ and _
You see these '$'_SESSION they can't contain quoted dollar signs.
All of those need to read as $_SESSION in one go, which is why you're getting those warnings.
Read up on this superglobal
These superglobal variables are:
$GLOBALS
$_SERVER
$_GET
$_POST
$_FILES
$_COOKIE
$_SESSION
$_REQUEST
$_ENV
Also, in your first file, you have
<?php//opening of php
that alone will throw an error, had you error reporting set. Either remove the //opening of php or put it in a second line:
<?php
//opening of php
The error in question:
Parse error: syntax error, unexpected '$_SESSION' (T_VARIABLE)...
While testing your code and after fixing all of those errors, did in fact post
Favorite color is green.
Favorite animal is cat.
in the second file.
You should make it a habit not to have comments so close to executable code, especially the opening <?php tag.
Another being session_start();//where session start it won't throw/cause an error, but it's just confusing.
You could also check if both sessions are set:
if(isset($_SESSION["favcolor"]) && isset($_SESSION["favanimal"])){
echo "Favorite color is " . $_SESSION["favcolor"] . ".<br>";
echo "Favorite animal is " . $_SESSION["favanimal"] . ".";
}
else{
echo "Sessions are not set.";
}
Plus, since you said you were doing this via localhost, make sure that the sessions/tmp folder(s) are writeable and have proper write permissions set.
Use:
<?php
phpinfo();
in a seperate file to see what your sessions settings are set to.
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Error reporting should only be done in staging, and never production.
'$'just remove them! Also The comment style://only works in php tags in html use:<!-- ... -->