I’m making a simple php login script and I’m running into some problems… Let me know if you know what the problem is… Basically, when I check for a session variable while in a directory other than the one which I created it in… php doesn’t find the session variable… here it is… thanks
THIS WORKS – /login.php – a simple form that passes values to “verify.php”
<form action="verify.php" method="post">
<table width="282" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="165" class="content">Username:</td>
<td width="103"><input name="username" type="text" class="content" id="username" /></td>
</tr>
<tr>
<td class="content">Password:</td>
<td><input name="password" type="password" class="content" id="password" /></td>
</tr>
<tr>
<td><input name="Submit" type="submit" class="content" value="Submit" /></td>
<td> </td>
</tr>
</table>
</form>
THIS WORKS – /verify.php – verifies the user input matches the text file. If it does, IT SETS A SESSION VARIABLE… THE SESSION VARIABLE CAN BE VIEWED AT “sess_024d8fab658c183c72f4ce0ac88318a7”… HOLDING A VALUE “yes” in $my_var. It the forwards you to index.php
<?php
if ($Submit) {
// process form
$filename = 'D:\hshome\iprovo15\universaltelcomgroup.com\test\astf.txt';
$fp = fopen($filename, "r"); //open the file for read
$guts = fread($fp, filesize($filename)); //read the entire file and assign it to $guts
fclose($fp);
$pieces = explode(",",$guts);
if ($pieces[0] == $username)
{
if ($pieces[1] == $password)
{
session_start();
session_register("my_var");
$my_var = "yes";
?>
<script>
window.location.replace("index.php");
</script>
<?
}
else
{
echo "The password was incorrect";
}
}
else
{
echo "I'm Sorry, the username was not found";
}
}
?>
THIS WORKS— /index.php
<?php session_start(); ?>
<?php
if ($my_var != "yes")
{
?>
<script>
window.location.replace("login.php");
</script>
<?php } ?>
<html>…<<<rest of the file>>>…</html>
Now, if I go to a different directory… the $my_var does not hold any value…
THIS DOES NOT WORK!!! – /new_directory/letmesee.php – checks for $my_var… since there is no value… it ALWAYS kicks you out.
<?php session_start(); ?>
<?php
if ($my_var != "yes")
{
?>
<script>
window.location.replace("login.php");
</script>
<?php } ?>
<html>….rest of the page </html>