Help with IF and ELSE at session_start()

Asked

Viewed 65 times

0

I ask for the help of friends, because I’m having difficulty creating an IF/ELSE to determine which content of the variable $logo will enter first.

Here’s what I need when accessing the main page "http://www.efacil.com/", It’s easy to carry the logo (As this at the address mentioned for access) believing that SESSION has not yet been loaded. But after changing the image via Adm Panel.(Access by the mentioned address), the new image is loaded.

For this I tried to create PHP code (listed below) to determine when the session_start() must load the variable referring to the image that was changed, but as I mentioned at the beginning of the POST, without success, because even after the image exchange, it keeps loading the logo of Easy Easy.

<?php
if(!isset($_SESSION)) { // Se a Session não for iniciada
    $logo = 'img/logo_tipo.png'; // Carrega esse conteúdo
}else{ // Se não
@session_start(); // Inicia a session.
if(isset($_SESSION)) { // Se a Session for iniciada
    $logo = ''.$_SESSION['logo'].''; // Carrega esse conteúdo
}}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
    <title></title>
    <link rel="shortcut icon" href="" />
</head>

<body style="margin:0;">

    <div align="center" style=" margin-top:5px; width:100%;">

 <img  width="150" height="auto" src="<?php echo $logo; ?>" /><br />

    </div>

</body>
</html>

Well I thank the attention of the friends, and in the await of good tips to solve my problem, in case it has solution.

Hugs to all.

3 answers

1

You can do it like this, I’d do it like this:

When the Image is set:

session_start(); // isto existe sempre
$_SESSION['Logo'] = 'COLOCADA/ADMIN/IMAGEM.jpp'; // Definir uma imagem 'default', caso ainda não se tenha colocado uma nova entretanto

if(isset($_SESSION['iniciada'])) {
     $_SESSION['Logo'] = 'NOVA/IMAGEM.JPG';
}

....
<img  width="150" height="auto" src="<?php echo $_SESSION['Logo']; ?>" /><br />

0

<?php
session_start(); // Inicia a session.
if($_SESSION['logo']==FALSE) { // Se a Session não for iniciada
    $logo = 'img/logo_tipo.png'; // Carrega esse conteúdo
}else{ // Se não
    $logo = $_SESSION['logo']; // Carrega esse conteúdo
}
?>

I would do it this way

0

Try to start the section at the beginning of the code, and if checks...

          if(!isset($_SESSION['logo'])){}

If not right comment there, maybe I did not understand the question right...

  • Thanks to friends Miguel, André Baill and Localhost, for the tips and the solution was given with the tip of Localhost, because it was only add in the line of SESSION not started the variable ['logo'] to make it work perfect, but I also tested André Baill’s code, which worked perfectly exactly the way he posted it. Thanks Even, enter the address (http://www.efacil.com/) to see the result, because I will leave for some time on the air. Once again, my many thanks to friends, thanks even for the strength. Hugs to all.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.