$_SESSION Issue

1 reply · opened Sep 7, 2022

DdoyooneeSep 7, 2022

After a session start, I want to make a different show to the user when the user clicks again.

So at first I coded like below;

$main_message1 = "Good morning!";
$main_message2 = "Good afternoon!";
switch ($_SESSION["uSlide"]) {
case "a": $main_image = "mainbg4.jpg"; $main_message = $main_message1; $_SESSION["uSlide"] = "b";break;
case "b": $main_image = "mainbg5.jpg"; $main_message = $main_message2; $_SESSION["uSlide"] = "c";break;
case "c": $main_image = "mainbg6.jpg"; $main_message = $main_message1; $_SESSION["uSlide"] = "d";break;
case "d": $main_image = "mainbg7.jpg"; $main_message = $main_message2; $_SESSION["uSlide"] = "a";break;
default: $main_image = "mainbg4.jpg"; $main_message = $main_message1; $_SESSION["uSlide"] = "b";
}

But it didn't work. It only showed mainbg4 and mainbg6. So I tried to find the reason but failed.

And I coded like below and it works now.
switch ($_SESSION["uSlide"]) {
case "a": $main_image = "mainbg4.jpg"; $main_message = $main_message1; $_SESSION["uSlide"] = "b";break;
case "b": $main_image = "mainbg4.jpg"; $main_message = $main_message1; $_SESSION["uSlide"] = "c";break;
case "c": $main_image = "mainbg5.jpg"; $main_message = $main_message2; $_SESSION["uSlide"] = "d";break;
case "d": $main_image = "mainbg5.jpg"; $main_message = $main_message2; $_SESSION["uSlide"] = "e";break;
case "e": $main_image = "mainbg6.jpg"; $main_message = $main_message1; $_SESSION["uSlide"] = "f";break;
case "f": $main_image = "mainbg6.jpg"; $main_message = $main_message1; $_SESSION["uSlide"] = "g";break;
case "g": $main_image = "mainbg7.jpg"; $main_message = $main_message2; $_SESSION["uSlide"] = "h";break;
case "h": $main_image = "mainbg7.jpg"; $main_message = $main_message2; $_SESSION["uSlide"] = "a";break;
default: $main_image = "mainbg4.jpg"; $main_message = $main_message1; $_SESSION["uSlide"] = "b";
}

I feel the website loaded twice at time.... But I can't see the exact behind scene.. my code is very simple and clean I think..
Can you help me to solve this problem?

SSemicolon WebSTAFFSep 8, 2022

Hello,

This is definitely not related to Canvas, and we currently do not provide Customization related Support according to the Item Support Policy: https://themeforest.net/page/item_support_policy . You will need to manually code customizations or Hire a Freelancer to help you out.

You might consider using this code instead:
[ch_pre type="php"] "mainbg4.jpg",
'main_message' => $main_message1,
);

    break;

  case "b":
    $_SESSION["uSlide"] = "c";

    return array(
        'main_image' => "mainbg5.jpg",
        'main_message' => $main_message2,
    );

    break;

  default:
    $_SESSION["uSlide"] = "b";

    return array(
        'main_image' => "mainbg4.jpg",
        'main_message' => $main_message1,
    );
}

}

if ( !isset( $_SESSION['uSlide'] ) ) {
$_SESSION['uSlide'] = "a";
}

$current_session = choose_session();

var_dump( $current_session );[/ch_pre]

It's more modular and easier to understand. Hope this Helps!

Let us know if we can help you with anything else or if you find any further issues.

Have the same question, or something new?

Sign in to the Canvas dashboard to reply or open your own topic. Canvas owners get direct help from the SemiColonWeb team.

Reply on the dashboard