0

I've been doing a deep research in the web, looking for a solution for this error, but I couldn't fix it yet. Let me introduce you the situation:

SCRIPT1.php:

if(isset($_SESSION['LoadFile'])){
    echo "<span>";
    $MsgId = 91;
    $Msg = GetMsg($language, $MsgId);
    echo $Msg . " ";
    echo "<input name=\"Fleet\" id=\"Fleet\" type=\"file\" />";
    echo "</span>";
}else{
echo "<span>";
    $MsgId = 169;
    $Msg = GetMsg($language, $MsgId);
    echo $Msg . " ";
    $MsgId = 22;
    $Msg = GetMsg($language, $MsgId);
    echo "<a href=\"".$linkpath."inc_load_file.php\">".$Msg."</a>";
echo "</span>";
}

The inc_load_file.php contents:

<?php
$_SESSION["LoadFile"] = "Load, please";
$_SESSION["ShowLoadingOpt"] = "Show";
//echo $_SESSION["LoadFile"] <---This works correctly, the variable is being properly created.
header("Location: ".$_SESSION["PrevLoc"]);
exit;
?>

Note that if I do print_r($_SESSION) in the begging of the Script1, it shows the following result:

Array ( [UID] => 1 [UName] => Santi [USurname] => Márquez [ULvl] => 1 [ULang] => en_Gb [Logged] => 1 [UEmail] => [email protected] [User] => smarquez [UCreationDate] => 2015-10-14 [UAccessTimes] => 162 [UALDesc] => Administrator [CountryCodeKPIReportsGenerator] => 2 )

My webpage should show a message like:

"File loaded. If you want to load a new file click here."

If you click in the link, the inc_load_file.php is executed. It creates the session variables and goes back to the script1.php. After doing it, the webpage should show a file input, but actually, it's still showing the link. The session variable is not set.

Can you please help me to check why the session variables created in inc_load_file.php are not being properly returned after executing the header() function?

Thank you very much in advance for your help.

2
  • looks like you forgot session_start(). no session_start, any changes to $_SESSION are simply lost. Commented Jul 18, 2016 at 15:07
  • Please, have a look in my answer, and thank you! Commented Jul 19, 2016 at 7:54

2 Answers 2

1
  1. Add session_start() at the beginning of your script, before you try to access $_SESSION and before you output anything to the browser.
  2. Where is $_SESSION["PrevLoc"] set? You use it in the Location header, but we don't see you set its value.
Sign up to request clarification or add additional context in comments.

Comments

1

Thank you for your answers :) I'm currently using wamp and the session is starting automatically. It's correctly started, that's why I'm able to save all this data in the $_SESSION array:

[UID] => 1
[UName] => Santi 
[USurname] => Márquez 
[ULvl] => 1 
[ULang] => en_Gb 
[Logged] => 1 
[UEmail] => [email protected] 
[User] => smarquez 
[UCreationDate] => 2015-10-14 
[UAccessTimes] => 162 
[UALDesc] => Administrator 
[CountryCodeKPIReportsGenerator] => 2

So, the problem is not the session creation. It's properly created, but $_SESSION["LoadFile"] and $_SESSION["ShowLoadingOpt"] are being unset after the Header().

By the other hand, $_SESSION["PrevLoc"] contents the previous page where the user has been. I deleted some variables from the print_r result due a security reason. Anyways, I tried using $_SERVER['HTTP_REFERER'] too but it didn't work neither.

Thank you very much again for all your support :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.