John T Posted February 20, 2011 Share Posted February 20, 2011 Hi, I am creating a genealogy website using The Next Generation Software. Access to the site will require the users to log in, they will also be assigned a tree. It will have two family history trees. At the moment it is on a local wamp server. My question is: I have two custompages, page1.php and page2.php. I only want users assigned to tree1 to be able to see page1.php and users assigned to tree2 only to be able to see page2.php. I think I need an if else statement on each of the two pages or, they could be directed there from a welcome.php page. but as I have no knowledge of php I am clueless as to how or what to put in the if else statement and where it should go. I have googled php syntax and seen lots of code but they all seem to use “echo” but I do not need print anything just, go to certain pages. I have seen the following in various pages of code used in the program if it helps- include($cms['tngpath'] ."checklogin.php"); $assignedtree = $_SESSION['assignedtree']; $currentuser = $_SESSION['currentuser']; Any help would be appreciated many thanks for reading this. Regards, John. Link to comment https://forums.phpfreaks.com/topic/228319-help-withsyntax-for-if-else-statement/ Share on other sites More sharing options...
Rifts Posted February 21, 2011 Share Posted February 21, 2011 you need a database Link to comment https://forums.phpfreaks.com/topic/228319-help-withsyntax-for-if-else-statement/#findComment-1177379 Share on other sites More sharing options...
John T Posted February 21, 2011 Author Share Posted February 21, 2011 Thanks for the reply Rifts, sorry I should have said I am using my SQL that comes with wamp server. any other ideas would be appreciated. John Link to comment https://forums.phpfreaks.com/topic/228319-help-withsyntax-for-if-else-statement/#findComment-1177557 Share on other sites More sharing options...
Veteah Posted February 21, 2011 Share Posted February 21, 2011 Do you mean something like: $assignedtree = $_SESSION['assignedtree']; $currentuser = $_SESSION['currentuser']; if($assignedtree == 'tree1') { echo $currentuser . ' is looking at tree 1'; } elseif($assignedtree == 'tree2') { echo $currentuser . ' is looking at tree 2'; } else { echo $currentuser . ' did not match either tree'; } Replacing the tree1 and tree2 with whatever you're storing in the session. Link to comment https://forums.phpfreaks.com/topic/228319-help-withsyntax-for-if-else-statement/#findComment-1177678 Share on other sites More sharing options...
John T Posted February 21, 2011 Author Share Posted February 21, 2011 Hi Veteah thanks for the reply. I think you are on the way to fixing this. The only thing is I do not need the echo part. Insted I would like the specific page to open, either page1.php or page2.php It is so frustrating not knowing php. Link to comment https://forums.phpfreaks.com/topic/228319-help-withsyntax-for-if-else-statement/#findComment-1177823 Share on other sites More sharing options...
Veteah Posted February 21, 2011 Share Posted February 21, 2011 In that case, all you have to do is add include('file_path'); ... where the echo is. Link to comment https://forums.phpfreaks.com/topic/228319-help-withsyntax-for-if-else-statement/#findComment-1177826 Share on other sites More sharing options...
John T Posted February 21, 2011 Author Share Posted February 21, 2011 Veteah, I am not used to getting replies this quick from a forum, thanks so much.http://www.phpfreaks.com/forums/Smileys/nrg_alpha/happy-01.gif I will give this a try and let you know. Might be tomorrow as I am just off out. Regards, John Link to comment https://forums.phpfreaks.com/topic/228319-help-withsyntax-for-if-else-statement/#findComment-1177844 Share on other sites More sharing options...
John T Posted February 22, 2011 Author Share Posted February 22, 2011 Hi Veteah, I tried the echo statement first to see the result and it was as expected, showed who was logged in and their tree. Then I tried the include statement and got parse errors. The below is the start of my page up to your code. It shows different things I have tried and the parse errors. Thanks, John <?php include( "../begin.php"); if( !$cms['support'] ) $cms['tngpath'] = "../"; include($cms['tngpath'] ."genlib.php"); include($cms['tngpath'] ."getlang.php"); include($cms['tngpath'] ."$mylanguage/text.php"); include ($cms['tngpath'] ."checklogin.php"); include($cms['tngpath'] . "log.php" ); tng_db_connect($database_host,$database_name,$database_username,$database_password) or exit; $logstring = "<a href=\"extrapgs/welcome.php\"welcome</a>"; writelog($logstring); preparebookmark($logstring); // ****************************** NEW CODE FROM Veteah ******************** $assignedtree = $_SESSION['assignedtree']; $currentuser = $_SESSION['currentuser']; if($assignedtree == 'tree1') { echo $currentuser . ' is looking at tree 1'; // echo is showing who is signed in and which tree is being looked at. // include ($cms['tngpath'] . 'cuttingshome.php'}; // If I add ($cms['tngpath'] results in parse error line 22 (this line) // include . ('cuttingshome.php'}; // if I use single quotes results in parse error line 23 (this line) // include . ("cuttingshome.php"}; // if I use double quotes results in parse error line 24 (this line) } elseif($assignedtree == 'tree_2') { echo $currentuser . ' is looking at tree 2'; // echo is showing who is signed in and which tree is being looked at. } else { echo $currentuser . ' did not match either tree'; // This also works } /*In that case, all you have to do is add include('file_path'); ... where the echo is. */ // ************************* END OF NEW CODE FROM Veteah ****************************** Link to comment https://forums.phpfreaks.com/topic/228319-help-withsyntax-for-if-else-statement/#findComment-1178172 Share on other sites More sharing options...
John T Posted March 3, 2011 Author Share Posted March 3, 2011 Hi Veteah and thanks for pointing me in the right direction All is now sorted with this, the echo statement only needed a page link. For those interested in the result the code is below. $assignedtree = $_SESSION['assignedtree']; $currentuser = $_SESSION['currentuser']; <?php if ($assignedtree == 'tree1') { echo '<a href=\'page1.php\'>Page Title</a>'; } elseif ($assignedtree == 'tree_2') { echo '<a href=\'page2.php\'>another page title</a>'; } else { echo 'You don\'t have a user account Please register'; } ?> Link to comment https://forums.phpfreaks.com/topic/228319-help-withsyntax-for-if-else-statement/#findComment-1182328 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.