0

In order to pass a variable between 2 .php files I used,

sender

<?php  
session_id('theSessionID'); 
session_start();
$_SESSION['theLOG'] = $theloginusername;
?>

receiver

<?php 
session_id('theSessionID'); 
session_start();
$theloginusername = $_SESSION['theLOG'];
?>

(BTW it only worked with the session_id)

and it worked but I noticed that on other pages which incorporated this code,

<?php
if (empty($_GET)) {echo "<script>window.location = 'http://www.myweb.com/'</script>";} 
$passToken = $_GET["recordID"];
?>

that the above conditional acted as if the variable was empty even when it was not.

Strangely, when I commented out the conditional statement the $passtoken variable was assigned the expected value from $_GET.

Why is it that when I use $_SESSION that $_GET responds in this way?

devpro
  • 16,184
  • 3
  • 27
  • 38
gungu
  • 161
  • 1
  • 1
  • 9

1 Answers1

0

it only worked with the session_id

I presume you mean that it only worked when you included the line

session_id('theSessionID'); 

(I also presume you are aware how silly using a literal value for the session id is on a production system).

If that's the case, then there's something wrong with your cookie generation and your error reporting (otherwise you would have seen the error message generated by PHP saying that the headers had already been sent).

Community
  • 1
  • 1
symcbean
  • 47,736
  • 6
  • 59
  • 94
  • 1. Yes, that's what I mean (what else could it mean?) 2. Yes, it would be silly but its there to illustrate the issue, just like the equally silly url, "www.myweb.com" is. 3. Please be kind to people with considerably less knowledge in this area than you who are sincere in their efforts to learn – gungu Jan 22 '16 at 12:54
  • This is a great explanation of "headers already sent" issues [http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php] – gungu Jan 22 '16 at 13:14