|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Again ----
Hi,
I got this example code form a site and I have problem executing this. Can anyone chekc this code and say if its ok! I get an error in the 1-2.php page saying $PHPSESSID and $bgcolor undefined. --------------------------- file 1-1.php ----------------------------- <? // create a new session session_start(); // register a session-variable session_register("bgcolor"); // Assign a value to the session-variable $bgcolor = "#8080ff"; ?> <html> <head> <title>Session Example #1</title> </head> <body bgcolor="<?=$bgcolor?>" text="#000000" link="#000000" vlink="#000000" alink="#000000"> Welcome to a session-enabled page! The background color on the next page will be set to a stylish blue.<p> <a href = "1-2.php">Go to another session-enabled page</a>. </body> </html> ----------------------------------- file 1-2.php ----------------------------------- <? // Resume session created in Listing 1-2 session_start(); ?> <html> <head> <title>Session Example #1</title> </head> <body bgcolor="<?=$bgcolor?>" text="#000000" link="#808040" vlink="#606060" alink="#808000"> <? // Retrieve SID from cookie. print "Your SID is $PHPSESSID <br>"; ->>>>>> Error here // Display the value of the $bgcolor variable. print "The persistent background color is: $bgcolor."; ->>>>>> Error here ?> </body> </html> ------------------------------------- Shiva |
|
#2
|
|||
|
|||
|
RE: Again ----
Instead of this: print "Your SID is $PHPSESSID <br>"; ->>>>>> Error here try this: print "Your SID is".$PHPSESSID."<br>"; ->>>>>> Error here Instead of this: print "The persistent background color is: $bgcolor."; ->>>>>> Error here Try this: print "The persistent background color is:".$bgcolor."."; ->>>>>> Error here And why are you using substraction to name a file?. you should not be using dashes in file names. |
|
#3
|
|||
|
|||
|
RE: Again ----
I still get the error
Notice: Undefined variable: PHPSESSID in c:inetpubwwwrootsess1-2.php on line 14 Notice: Undefined variable: bgcolor in c:inetpubwwwrootsess1-2.php on line 18 |
|
#4
|
|||
|
|||
|
RE: Again ----
Try just PHPSESSID outside quotes:
"Your PHPSESSID is " . PHPSESSID; And then for the bgcolor, use: $_SESSION['bgcolor'] |
|
#5
|
|||
|
|||
|
RE: Again ----
Don't worry about taking variables out of the quotes. In PHP as is today
echo "You are in a $mood mood"; is the same as echo "You are in a " . $mood . " mood."; They should be the same. Also, using dashes in filenames is really not an issue either. 1-2.php is a completely valid filename in Windows and UNIX, so that's not an issue. The key here, as said above, is calling the session vars with $_SESSION['varname'] In fact, you should get used to using $_GET['varname'], $_POST['varname'], $_COOKIE['varname']and $_SESSION['varname'] for all form, cookie, and session data. |
|
#6
|
|||||
|
|||||
|
RE: Again ----
If you plan on using an array variable inside quotes, make sure you place curly brackets around it:
php Code:
|
|
#7
|
|||
|
|||
|
RE: Again ----
Sorry about the comment on the dashes in the file names. I was thinking variables when I wrote that/too much coffee I guess
|
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Again ---- |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|