Switch or conditional statment help

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!

Moderator: General Moderators

Post Reply
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Switch or conditional statment help

Post by a94060 »

Hi, I have this code which i took from one of my other codes:

Code: Select all

<?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*/
$you = $_POST['you'];
$me = $_POST['me'];
/*After this is all code*/
if(isset($_POST['Submit'])) {
	if(($you == '***') && ($me == '***)) {
	$_SESSION['in'] = 1;
	echo 'Just making sure my sessions work ';
	print_r($_SESSION);
	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/?action=add">Add An Offer</a>';
	echo '<br>';
	echo '<a href="http://avi.aerohostale.com/admin/?action=view">View Pending and Completed Offers</a>';
	echo '<br>';
	echo '<a href="http://avi.aerohostale.com/admin/?action=pay">Make a Payment to Someone</a>';
	}//closes the password check
	}//closes the isset post submit
	elseif ($_SESSION['in'] != 1) {
	include "actions/login.php";
	}	
if(isset($_GET['action'])) {	
$action= $_GET['action'];
  	if(($_SESSION['in'] == 1) && (isset($action))) {
		
		switch($action) {
			case 'add'://if the link contains add as the action
			{
			include "/actions/add.php";
			}//close the case add
			case 'view'://if the action is set to view the payed and unpayed
			{
			include "/actions/view.php";
			}//close the switch $action
	}//close the actions if statment
}//close $_SESSION['in'] == 1) && (isset($action)))
}
	?>
The problem i am having is that once i clik one of the links that come up when i login:
echo '<a href="http://avi.aerohostale.com/admin/?action=add">Add An Offer</a>';
echo '<br>';
echo '<a href="http://avi.aerohostale.com/admin/?action=view">View Pending and Completed Offers</a>';
echo '<br>';
echo '<a href="http://avi.aerohostale.com/admin/?action=pay">Make a Payment to Someone</a>';
It brings me to the admin login. Why is this?
User avatar
nathanr
Forum Contributor
Posts: 200
Joined: Wed Jun 07, 2006 5:46 pm

Post by nathanr »

you sure your sessions are working?

do this:
testsession1.php

Code: Select all

session_start()
$SESSION['IN'] = 1;
testsession2.php

Code: Select all

session_start()
print_r($_SESSION);

view it script 1 then script 2 inthe browser, see if its saving session data
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

the sessions i tried before. I seem to always be having session problems. i just want to know why i am having so many session problems. Is there any directive in the php.ini file i can change/look at that i could increase the time for?
i also tried to work around that problem of passing the session by jsut keeping it all onto one page.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

Try doing this:

Make a the page say

Code: Select all

<?php
require('admin.php');
?>
and then put this stuff on the admin.php page.

Code: Select all

<?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*/ 
$you = $_POST['you']; 
$me = $_POST['me']; 
/*After this is all code*/ 
if(isset($_POST['Submit'])) { 
        if(($you == '***') && ($me == '***')) { 
        $_SESSION['in'] = 1; 
        echo 'Just making sure my sessions work '; 
        print_r($_SESSION); 
        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/?action=add">Add An Offer</a>'; 
        echo '<br>'; 
        echo '<a href="http://avi.aerohostale.com/admin/?action=view">View Pending and Completed Offers</a>'; 
        echo '<br>'; 
        echo '<a href="http://avi.aerohostale.com/admin/?action=pay">Make a Payment to Someone</a>'; 
        }//closes the password check 
        }//closes the isset post submit 
        elseif ($_SESSION['in'] != 1) { 
        include "actions/login.php"; 
        }        
if(isset($_GET['action'])) {    
$action= $_GET['action']; 
        if(($_SESSION['in'] == 1) && (isset($action))) { 
                
                switch($action) { 
                        case 'add'://if the link contains add as the action 
                        { 
                        include "/actions/add.php"; 
                        }//close the case add 
                        case 'view'://if the action is set to view the payed and unpayed 
                        { 
                        include "/actions/view.php"; 
                        }//close the switch $action 
        }//close the actions if statment 
}//close $_SESSION['in'] == 1) && (isset($action))) 
} 
        ?>
Post Reply