Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

PHP session only works after a refresh

Posted on 2005-04-07
2
Medium Priority
?
628 Views
Last Modified: 2006-11-18
I am using sessions with multiple php pages.  The session variables do not work until The second time I view the page (i.e. refresh)

I tried a simple version of sessions and had the same results.

<?PHP
session_start();
$_SESSION ["var"] = "val";
echo $var;
echo $PHPSESSID;
?>

the echo for both the $var and the $PHPSESSID do not show up until I refresh the page.  How do I use sessions without refreshing?
0
Comment
Question by:jimfrith
  • 2
2 Comments
 
LVL 7

Accepted Solution

by:
minnirok earned 2000 total points
ID: 13729897
<?php
refer to your session variables through the $_SESSION[] superglobal array.  And use session_id() to echo out the session's ID:

session_start();
$_SESSION ["var"] = "val";
echo $_SESSION["var"] . "<br />\n";
echo session_id() . "<br />\n";
?>
0
 
LVL 7

Expert Comment

by:minnirok
ID: 13729902
and put your opening <?php tag in the right place ;)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question