Forum Moderators: coopster

Message Too Old, No Replies

Session not working :( any help?

         

KRMwebdesign

6:56 am on Sep 6, 2010 (gmt 0)

10+ Year Member



Hi All,
I have a session script but it's not holding the session and I keep kicking back to the main page after I login. I wonder can anybody see anything wrong with my code here:

<?session_start();
if($_SESSION['admin'] == "")
{?>
<script language=javascript>
top.location.href="index.php?table=4"
</script>
<?}


if (!empty($HTTP_POST_FILES))
{
reset($HTTP_POST_FILES);
while (list($k,$v) = each($HTTP_POST_FILES))
{
${$k} = $v['tmp_name'];
${$k._name} = $v['name'];
${$k._type} = $v['type'];
${$k._size} = $v['size'];
${$k._error} = $v['error'];
}
}
error_reporting("E_All");
?>

Matthew1980

7:36 am on Sep 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there KRMwebdesign,

Firstly: Use full tags, not all servers support/use the short form tags (<?>) this has the potential to stop a script dead. So always use full tags: <?php?> to avoid headaches later on.

Secondly: $HTTP_POST_FILES has been deprecated for a while now, in favour of $_FILES since version 4.1.0

Thirdly: error_reporting(E_ALL); should be placed at the top (opening) of the script.

Hope that helps a little.

Cheers,
MRb

KRMwebdesign

9:24 am on Sep 6, 2010 (gmt 0)

10+ Year Member



Thanks very much for the reply Matthew1980. I'm a novice php developer but I am using a system that was built by someone else.

I have made those changes but unfortunately they haven't fixed my issue. I think the problem is that the session isn't being picked up so it keeps kicking back to the login page.

My code now looks like this:

<?php
error_reporting("E_All");
session_start();
if($_SESSION['admin'] == "")
{?>
<script language=javascript>
top.location.href="index.php?table=4"
</script>
<?php }


if (!empty($_FILES))
{
reset($_FILES);
while (list($k,$v) = each($_FILES))
{
${$k} = $v['tmp_name'];
${$k._name} = $v['name'];
${$k._type} = $v['type'];
${$k._size} = $v['size'];
${$k._error} = $v['error'];
}
}
?>

It keeps kicking back to this page "index.php?table=4" shown in the javascript above.

Any other ideas?

Matthew1980

9:52 am on Sep 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there KRMwebdesign,

Try doing this just under the session_start():-

echo "<pre>";
print_r($_SESSION);
echo "</pre>";

use this to see if the session array actually holds a value, from there you can see what's working and what's not.

Although, I am unsure as to why you need to have the reset() function there, because the loop starts from the first instance to the last, there is no need to reset the array to it's first index place, unless I have missed something, also the use of $_FILES implies that your uploading a file, to me it just looks as if you are listing whatever is present in the $_FILES array and assigning that to some vars...

Sorry I'm not much help other than that!

Cheers,
MRb