Jump to content

php session problem


gazuraz

Recommended Posts

Basically I am using this code:

if (isset($_SESSION['user'])){

$miloica="logout.php";

$pantelija = "logout";

$sesija =$_SESSION["user"];

}else{

$miloica="login.php";

$pantelija = "login/register";

}

 

When user clicks on log in button, log in form opens in a tick box. After the log in confirmation, script redirects user to its control panel which is also in same tick box. After the user finishes his work, or close tick box the button log in remains the same. And it should be Log out..(by the way my boss wants tick box and I cant trow it out)

Link to comment
https://forums.phpfreaks.com/topic/168660-php-session-problem/
Share on other sites

Basically I am using this code:

if (isset($_SESSION['user'])){

$miloica="logout.php";

$pantelija = "logout";

$sesija =$_SESSION["user"];

}else{

$miloica="login.php";

$pantelija = "login/register";

}

 

When user clicks on log in button, log in form opens in a tick box. After the log in confirmation, script redirects user to its control panel which is also in same tick box. After the user finishes his work, or close tick box the button log in remains the same. And it should be Log out..(by the way my boss wants tick box and I cant trow it out)

have you started session in the top of the script?? like session_start(); ??

Link to comment
https://forums.phpfreaks.com/topic/168660-php-session-problem/#findComment-889767
Share on other sites

Basically  :facewall: there is no problem whit session, but there is a huge problem  with my boss :facewall:

 

Session works excellent and I have no problem what so ever with her.

 

/*this code only reads if session is set so it can dynamically format the  button*/ 

 

session_start();

if (isset($_SESSION['user'])){

$miloica="logout.php";

$pantelija = "logout";

$sesija =$_SESSION["user"];

}else{

$miloica="login.php";

$pantelija = "login/register";

}

I have this code on every page beceuse I have one button which is dynamic and if session is set its link shoul be $miloica="logout.php"; and its text should be $pantelija = "logout";

If session is not set its link should be $miloica="login.php"; and its text should be  $pantelija = "login/register". That worked OK, until my boss got an idea to  open a log in form in tick box (another window). So when user logs in and close that new window the main page dose not refresh so the button link remains  $miloica="login.php"; and its text $pantelija = "login/register";

 

So, actual problem lays in impossibility of php to perform a setInterval() function which I could use to determine the session data and perform the button formatting, whit out using some meta refresh function which will only confuse the user.

 

Now my boss heard that that could be done whit AJAX and he persists, but that will set me back for 5 or six days... So my question is - Is it possible to do it using only php. If not, I would rather use AS button whit loadVars() and setInterval() function than AJAX.

Link to comment
https://forums.phpfreaks.com/topic/168660-php-session-problem/#findComment-889831
Share on other sites

So what is the problem? As a psudeo code it would be ...

 

if (user_is_logged)
{
    $button = '<a href="page.php?logout">Logout</a>';
}
else
{
    $button = '<a href="login.php">Login</a>';
}

// echo where ever you want your button
echo $button;

 

just change the link in the button accordingly on every page load if needed..

 

edit: added links as a buttons here but you should get the idea.

Link to comment
https://forums.phpfreaks.com/topic/168660-php-session-problem/#findComment-889841
Share on other sites

You did not understood me. I already done that. :shrug: The problem is that user must manually refresh the page from which he used the log in button. Because the log in form opens on another window and not "_self".  So the actual session setting dose not reflect the first page which remains opened. If user clicks on another page button, everything is OK. But if user stays on previous  page...

Link to comment
https://forums.phpfreaks.com/topic/168660-php-session-problem/#findComment-889866
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.