• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

SESSIONS

at the top of my page i have this:

<?php
session_register();

if($_SESSION['username'] == '')
{
      $_SESSION['username'] = trim($_GET['username']);
      header("Location:http://192.168.0.2:7810");
}
?>

what im trying to do is when the page loads, check if $_SESSION['username'] has been registered.  if YES just show the page else register the session and refresh the page...

but it isnt working... no errors BTW!
0
ellandrd
Asked:
ellandrd
  • 3
  • 3
1 Solution
 
Mk3890Commented:
Did you run session_start() at the top of the page?
0
 
ellandrdAuthor Commented:
no, but it still inst working and sessions do work as they work for another page...

im trying this to test ....

<?php
session_start();

if(isset($_SESSION["username"]))
{
      echo "already set<br><br>";

      echo $_SESSION['username'];
}
else
{
      $username = trim($_GET['username']);

      $_SESSION['username'] = $username;

      header('Location:http://192.168.0.2:7810/index.php');
}
?>
0
 
ellandrdAuthor Commented:
see if i remove the header and not redirect it works fine, but since im using GET user can change username value in address so i need to redirect after session is set...

any idea's
0
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!

 
Mk3890Commented:
After doing a little Googling this seems to be a common problem.

try using

header('Location:http://192.168.0.2::7810/index.php?' . sid);

0
 
ellandrdAuthor Commented:
what is sid?
0
 
Mk3890Commented:
I'm assuming it's session id. It was posted in serveral places as a solution, but I find it odd that it's not treated as a varible. Give it a try if it doesn't work there might be another way.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now