473,324 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

PHP Sessions

2
I'm simply getting my feet wet in php so...

I need to set a session id in my 3 main templates and an if statement to check for the id of the page

OKAY - I've got 3 XHTML webpage templates that have the same top horizontal menu that has 3 tab links to different areas of the site. These 3 templates also have 3 different side menus called by an include in each one. The side menus have links to call via ajax the contents of a #div from a wiki into a #div in a 4th special template.

So this makes 4 templates: index1.php, index2.php, index3.php and wiki.php and 3 side menus called by php includes: menu1.php, menu2.php, menu3.php.

I want the special template to check and see which of the 3 main templates the user came from and therefore to insert the same sidemenu into the special template that inserts the contents via ajax.

Hope that was clear.

I see how I need to set the sessions id at the top of each index.php template

And then an if statement at the top of the wiki.php template

But I'm really quite lame beyond this and time is short....I'm more a designer than php programmer you see.

Any help on this out there tonight? Thanks /mark
Sep 25 '07 #1
6 1224
Heya,

I think i see what you're trying to accomplish. You might be able to set a session variable to the template you are coming from when you enter each template. so if you are going to include index1.php:

[PHP]
<?
//Session Variable 'template' is a string like "menu1" or "menu2"
session_start();
require_once("index1.php");
if(session_is_registered('template'))
{
$reqString = $_SESSION['template'].".php";
require_once($reqString);
}
else
{
session_register('template');
$template = "menu1";
}
[/PHP]

I have no Idea if that really helps but if you store the file name you want to include into the session variable "template" everytime you switch out menus, it will keep track of which one is current.

Hope this helps
Sep 25 '07 #2
Atli
5,058 Expert 4TB
Hi Mark. Welcome to The Scripts!

I'm not sure I fully understand what you are trying to do.
As I understood it... You have 3 PHP pages, each of them having it's own unique menu. Each of these 3 pages will have links to a fourth page, which is supposed to have the same menu as the page that linked to it?

Even if my understanding of your problem is way off this may be helpful.

First, each of the three main templates should have this at the very top:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.   # Create a session and set a variable so the fourth page knows
  3.   # where we were.
  4.   session_start();
  5.   $_SESSION['SentFrom'] = "page1"; # Or page2 or page3
  6.  
  7.   # Do whatever else you may want to do, like say include your menu.
  8.   (@include("menu1.php")) or die("Menu failed to load!");
  9.  
  10.   # Note, the @ is there to silence the PHP warning. I do this because
  11.   # the die() function will print a message if and error occurs and we
  12.   # don't want to see both of them.
  13. ?>
  14.  
The fourth page, would have to check which page the client came from and load the appropriate menu.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     # Check which page the user came from and load the menu
  3.     switch(@$_SESSION['SentFrom'])
  4.     {
  5.         case "page1":
  6.             (@include("menu1.php")) or die("Menu failed to load!");
  7.             break;
  8.         case "page2":
  9.             (@include("menu2.php")) or die("Menu failed to load!");
  10.             break;
  11.         case "page3":
  12.             (@include("menu3.php")) or die("Menu failed to load!");
  13.             break;
  14.         default
  15.             die("You came from nowhere!");
  16.     }
  17. ?>
  18.  
If this doesn't help please try explaining the problem again. You could include some examples of your pages to help us understand.
Sep 25 '07 #3
I concur with Atli, I probably shouldn't have spent time working on that script since I only have a vague concept of what you're trying to acheive.
Sep 25 '07 #4
Atli
5,058 Expert 4TB
Heya,

I think i see what you're trying to accomplish. You might be able to set a session variable to the template you are coming from when you enter each template. so if you are going to include index1.php:

[PHP]
<?
//Session Variable 'template' is a string like "menu1" or "menu2"
session_start();
require_once("index1.php");
if(session_is_registered('template'))
{
$reqString = $_SESSION['template'].".php";
require_once($reqString);
}
else
{
session_register('template');
$template = "menu1";
}
[/PHP]

I have no Idea if that really helps but if you store the file name you want to include into the session variable "template" everytime you switch out menus, it will keep track of which one is current.

Hope this helps
Hi.

You code will of course work. I would recommend, however, avoiding the session_is_registered() and session_register() functions if you are using the $_SESSION superglobal. They are relics of PHP 4.0.

As stated in the PHP manual
With $_SESSION, there is no need to use the session_register(), session_unregister(), session_is_registered() functions. Session variables are accessible like any other variables.
Sep 25 '07 #5
Hi.

You code will of course work. I would recommend, however, avoiding the session_is_registered() and session_register() functions if you are using the $_SESSION superglobal. They are relics of PHP 4.0.

As stated in the PHP manual
Atli, WOuld this work?
[PHP]
<?
session_start();
if(isset($_SESSION['template'])
{
//blah blah blah
}
else
{
require_once("menu1.php");
$_SESSION['template'] = "menu1";
}
[/PHP]
Damn RElics, I feel like INdiana Jones... Lost arc my ass... Probably at www.PHP.net with the rest of the treasure.
Sep 25 '07 #6
oceano
2
Wow, thank you all. I'll run some tests on these ideas and get right back to you.

So clarify however:

I have 3 templates(for three domains of the website) that each have a php include for a different side column menu. index1.php, index2.php, index3.php

In the side column menu there are (some) links that ajax in the contents of a div in our wiki into a wiki.php template.(please don't ask why this was done...)

So the task at hand is to simply track which of the three domains(index.php templates) the user has come from in the wiki.php so the correct side navigation is included in the final display of the wiki.php.

Based on my dangerous level of newbie knowledge only I'd say you've perhaps nailed it with the above scripts.

I'll let you know tonight /mark
Sep 25 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: The Plankmeister | last post by:
Hi... I'm trying my hardest to understand fully how sessions work and how best to use them. However, all I can find is information that doesn't tell me anything other than that sessions store...
13
by: jing_li | last post by:
Hi, you all, I am a newbee for php and I need your help. One of my coworker and I are both developing a webpage for our project using php. We have a copy of the same files in different location...
3
by: Maxime Ducharme | last post by:
Hi group We have a problem with sessions in one of our sites. Sessions are used to store login info & some other infos (no objects are stored in sessions). We are using Windows 2000 Server...
3
by: Will Woodhull | last post by:
Hi, I'm new here-- I've been reading the group for a couple of days. Nice group; I like the way n00b33 questions are handled. I've been using a Javascript routine in index.html to determine a...
2
by: Steve Franks | last post by:
According to the docs you tell ASP.NET to use cookieless sessions by setting a value in the config.web file. However, what if I wanted to determine at run time whether or not I wanted to use...
12
by: D. Shane Fowlkes | last post by:
This is a repost (pasted below). Since my original post, I've double checked the system clock and set all IIS Session Timeout values to 10 minutes. Still ...the problem occurs. I've also...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
22
by: magic_hat60622 | last post by:
Hi all. I've got an app that dumps a user id into a session after successful login. the login page is http://www.mydomain.com/login.php. If the user visits pages on my site without the www (i.e.,...
13
Frinavale
by: Frinavale | last post by:
One of the most fundamental topics in web design is understanding how to pass information collected on one web page to another web page. There are many different ways you could do this: Cookies,...
3
Atli
by: Atli | last post by:
Introduction: Sessions are one of the simplest and more powerful tools in a web developers arsenal. This tool is invaluable in dynamic web page development and it is one of those things every...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.