Session variables are not working properly. Doesn't hold the values 'sometimes'

session variables are acting weird. I try to login the first time, it doens' let me, I try it second time, I can get in most of the time. But, seems like the session variables are not retaining the values properly.
Here' what I have...
page 1 ----------------------------------------------
        <form action="auth.php" method="post">
        <legend>Please Log In</legend>
        <label for="user_name">Username: </label>
        <input type="text" name="user_name" id="user_name" value="<?php echo $user_name; ?>"/>
        <label for="user_password">Password:</label>
        <input type="password" name="user_password" id="user_password" value="<?php echo $user_password; ?>" />
        <br class="clear" />
        <input type="submit" name="submit" id="submit" value="submit"  />

page 2 ---------------------------------------------------
<?php session_start();

$input_username = $_POST['user_name'];
$input_password = $_POST['user_password'];


$cn = mysql_connect($host, $userName, $pass);

mysql_select_db('dev_graphics', $cn);
$sql = "select * from admin where adm_username = '$input_username' and adm_password = '$input_password' ";
$rs = mysql_query($sql, $cn);
$num_rows = mysql_num_rows($rs);

if($num_rows == 1){
$_SESSION['authenticate'] = $input_username;

page 3 --------------------------------------
<? session_start();
if (!$_SESSION['authenticate']) header("Location:index.php");
echo $_SESSION['authenticate'];

The ODD thing is the first time I try to login (using correct user name/password, it stays on index.php page which means it finds the record but session variable is blank, the first time, second time it works sometimes. sometimes it doesn't
any idea?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

are you using IIS or apache? I had this trouble with IIS and not Apache. Let me know
awarraicAuthor Commented:
I am using IIS.
ok, I suspected so. This is what you need to do. make sure your temp directory within PHP folder has read and write permissions. Let me know .
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

awarraicAuthor Commented:
I 'll try that on Monday, 'll have to talk to the network guy. it's weekend now so 'll keep you updated after the weekend. thanks much.
Best regards and have a great weekend.
awarraicAuthor Commented:
I talked to the Network guy and it seems like something else is going on with session variables. Rest of all web sites are working fine. Still having the same problem, first time I log in, session variables are blank, second time it works fine. Any other suggesions?
Its the exact same problem I had. What version of PHP are you using. Because there is a problem with older version of PHP and IIS.
Also make sure that your php.ini has this value corrected

session.save_path = "C:\php\temp"

it shows the correct path to temp directory in your PHP folder

make sure you have read and write permission on your temp directory for internet guest account and other accounts that would use it sometime Network services if you are on server 2003


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
awarraicAuthor Commented:
Sorry, have no control over network, also, all rest of the sites are working fine so not sure why this one site will act ODD but thanks much for your help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.