PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old November 13th, 2002, 05:02 AM
shivabharat shivabharat is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: India
Posts: 6 shivabharat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to shivabharat
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

Reply With Quote
  #2  
Old November 13th, 2002, 11:00 AM
bob0099 bob0099 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: manchester,n.h.,usa
Posts: 172 bob0099 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 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.


Reply With Quote
  #3  
Old November 13th, 2002, 01:24 PM
shivabharat shivabharat is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: India
Posts: 6 shivabharat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to shivabharat
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

Reply With Quote
  #4  
Old November 13th, 2002, 11:33 PM
Lizardman Lizardman is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 113 Lizardman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Again ----

Try just PHPSESSID outside quotes:

"Your PHPSESSID is " . PHPSESSID;

And then for the bgcolor, use:

$_SESSION['bgcolor']

Reply With Quote
  #5  
Old November 14th, 2002, 02:43 AM
sethadam1 sethadam1 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Orlando, FL
Posts: 223 sethadam1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
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.

Reply With Quote
  #6  
Old November 14th, 2002, 02:51 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Again ----

If you plan on using an array variable inside quotes, make sure you place curly brackets around it:

php Code:
Original - php Code
  1. echo "Just some text to {$_SESSION['varname']} wrap around this var.";


Reply With Quote
  #7  
Old November 14th, 2002, 01:40 PM
bob0099 bob0099 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: manchester,n.h.,usa
Posts: 172 bob0099 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
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

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Again ----


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway