PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Ok, I may have posted this many times,but i still cannot get sessions to work!!!!!!!!! I have tried almsot all of the ways people have posted back to me,none of them work. This is what i hve so far:
<?PHP
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Main Admin Page</title>
</head>
<body>
<?PHP
print_r($_SESSION);
error_reporting(E_ALL);
if(!isset($_SESSION['in']) || $_SESSION['in'] != 1) {
echo 'You are not logged in,please go to <a href="http://avi.aerohostale.com/admin">Here</a> to login';
}
else {
echo 'Welcome to the admin page. This is the basic layout so far.<br>Please use one of the links below to do what you would like to.';
echo '<br>';
echo '<br>';
echo '<a href="http://avi.aerohostale.com/admin/addoffer.php">Add An Offer</a>';
echo '<br>';
echo '<a href="http://avi.aerohostale.com/admin/tabview.php">View Pending and Completed Offers</a>';
echo '<br>';
echo '<a href="http://avi.aerohostale.com/admin/pay.php">Make a Payment to Someone</a>';
}
?>
</body>
</html>
this is really killing me. please someone give me a way to make this work. print_r tellsme Array() and then gives me my error message.
a94060 wrote:all of them have session start in them.
lol - Well, then I guess that idea is out
I always seem to run into issues with sessions when I try the multiple condition if statements for some reason. I have you tried just going without the || clause on your check?
should i try OR? or ill just try one of them? because one post i read said to do both of them with if isset && so that the "session would exist" but that still did not work.
Have you determined that sessions are working at all? For example, two simple pages: 1) start session and set session var, 2) start session and echo same session var.
i jsut tested that and on the second page(miraculously) it showed the value i set for the session.But,those original pages i posted still do not work. It is pretty weired,i have error reporting to all and nothing is ocming out. Only thing i get is Array()
You know that in the code you posted that you are only going to get a session var ($_SESSION['in']) if there is a $_POST value to assign to $you and $me?
Try using a brief session test without interactin with a form at first. I'd bet the issue your having has something to do with the form post data not matching what is set in your if conditional. Just a thought.
You all were basically right. After some time,i read into the switch statement and made my script a heck a lot easier. i did it so the sessions would all stay on the same page since i could not pass around. Since i saw the sessions worked on 1 page,i just used it liek that.
<?PHP
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Admin PAge</title>
</head>
<body>
<?PHP
/*DEfine All or most variables here*/
$do = $_POST['Submit'];
$you = $_POST['you'];
$me = $_POST['me'];
/*After this is all code*/
switch($do) {
case 'Login'://if the form is submitted
if(($you == '***') && ($me == '***')) {
$_SESSION['in'] = 1;
echo 'Welcome to the admin page. This is the basic layout so far.<br>Please use one of the links below to do what you would like to.';
echo '<br>';
echo '<br>';
echo '<a href="http://avi.aerohostale.com/admin/addoffer.php">Add An Offer</a>';
echo '<br>';
echo '<a href="http://avi.aerohostale.com/admin/tabview.php">View Pending and Completed Offers</a>';
echo '<br>';
echo '<a href="http://avi.aerohostale.com/admin/pay.php">Make a Payment to Someone</a>';
}//closes the case submit
break;//stop here if the username and password matches
default://if none are set
?>
<div align="center" class="style1">
<h1 align="center" class="style4">Admin Login</h1>
<form id="form1" name="form1" method="post" action="<?PHP echo $_SERVER['PHP_SELF'];?>">
<p align="center">Username
<input name="you" type="text" id="you" />
</p>
<p align="center">Password
<input name="me" type="text" id="me" />
</p>
<p align="center">
<input type="submit" name="Submit" value="Login" />
<input type="reset" name="Submit2" value="Reset" />
</p>
</form>
<p> </p>
<div align="center" class="style1"></div>
<?PHP
}//closes the switch
?>
</body>
</html>
Since i had a little of time,i just did this. Thanks all though.I still kinda do have the problem because i think that i i add some more things,it will start to get slower and i will need to make another script.
jsut an update,i finally solved the problem. I think it was because i was going between directories. If i set a session in the /this directory,it would not work in the /this/is or /this/is/cat directory.
a94060 wrote:jsut an update,i finally solved the problem. I think it was because i was going between directories. If i set a session in the /this directory,it would not work in the /this/is or /this/is/cat directory.
That doesn't sound right If the domain name changes across the pages then it will break however (http://www.sitename.com --> sitename.com).
Just a suggestion to see if it is the session rather than the code...
For every session var you plan to set, initialize it to an empty type of what it will be (either array(), 0, or '') before ever approaching it in your script. Then, where you plan on setting the var, set it. After all the checking and setting, echo the var out. If it is the empty type value then you are not setting the session vars right, if the script errors about undefined indexes, then sessions are hosing. The only other possibility is the correct setting of session vars which would render correctly.
<?php
session_start();
$_SESSION['arrayvar'] = array();
$_SESSION['intvar'] = 0;
$_SESSION['strvar'] = '';
// Run you code for checking and setting
// Then echo out the session var
printr($_SESSION['arrayvar']);
echo $_SESSION['intvar'];
echo $_SESSION['strvar'];
?>