Link to home
Start Free TrialLog in
Avatar of ellandrd
ellandrdFlag for Ireland

asked on

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!
ASKER CERTIFIED SOLUTION
Avatar of Mk3890
Mk3890

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ellandrd

ASKER

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');
}
?>
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
Avatar of Mk3890
Mk3890

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);

what is sid?
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.