473,387 Members | 1,882 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,387 software developers and data experts.

how to switching session value base on id chosen?

how to change session value without need to produce a new session? I want to initialize session value on the display.php base on id on menu chosen as the following situation.

PAGE menu.php:
Expand|Select|Wrap|Line Numbers
  1. <a href="display.php?id=1"> menu1</a>
  2. <a href="display.php?id=2"> menu2</a>
  3. <a href="display.php?id=3"> menu3</a>
Sep 5 '07 #1
8 1739
Atli
5,058 Expert 4TB
Hi.

What do you mean 'change session value'?
Can you give us an example of what you are trying to achieve?
Have you tried this yourself? Can we see the code?
Sep 5 '07 #2
on PAGE display.php i want to initialize the session like below;

On the top html:

[PHP]<?
global $ids;
$ids = $_GET['ids'];
?>[/PHP]

On the body:
[PHP]<?
#some sql query here...

if(isset($_SESSION['ids']))
{
#take the $_SESSION['ids'] value to execute the query
}
else
{
#take the $ids value to execute the query
}
?>[/PHP]

After slash body tag:
[PHP]<?
$_SESSION['ids'] = $ids;
?>[/PHP]
Sep 5 '07 #3
Atli
5,058 Expert 4TB
Ok.

What exactly is the problem?
The code you posted would work, aside from the fact that you are missing the session_start() function.

P.S.
I would recommend using "<?php" instead of just "<?". The short-tag version only works on specially configured PHP servers and will most likely cause problems if you try to use your code on other servers.
Sep 5 '07 #4
Ya the code i sent just to visualised what i'm wanna to achieve.. I've already placed session_start() on the top of html. What the problem is the session will never change the value! For an example if i select the menu1 from the menu.php then i clicking again to switch to others menu it can't, why? I need your help... thanks

regard Fareast Adam
Sep 5 '07 #5
Atli
5,058 Expert 4TB
The problem could be that after the Session variable is set, you never actually use the new ID. Look at the structure of your code, you will see that you set the $ids variable at the top, then you check whether the Session variable is set and use that if it is and finally you reset the Session variable to the new ID passed through the GET protocol.

You should be setting the Session variable at the top of the page.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3.  
  4. # Checking if the 'ids' variable was passed.
  5. if(isset($_GET['ids'])) {
  6.   # Set the Session variable now, rather 
  7.   # than later as you did in your code.
  8.   $_SESSION['ids'] = $_GET['ids'];
  9. }
  10.  
  11. # Check if the Session has been set.
  12. if(isset($_SESSION['ids'])) {
  13.   # Do stuff here.
  14.   # Note that now the Session contains the 'ids'
  15.   # variable that was passed this time rather
  16.   # than the old one your code used.
  17. }
  18. else {
  19.   # No 'ids' variable was passed, nor 
  20.   # has it ever been passed before.
  21. }
  22. ?>
  23.  
Sep 5 '07 #6
I check first...

Thank Atli for ur replys
Sep 5 '07 #7
Thanks Atli, finally i got the result! thanks again...

Regard,
Fareast Adam
Sep 5 '07 #8
Atli
5,058 Expert 4TB
Glad to hear it :)

Please don't hesitate to start a new thread if you have any more questions or problems we can help with.
Sep 5 '07 #9

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

Similar topics

2
by: sky2070 | last post by:
#register variable session_register("product1"); session_register("product2"); $product1="Palm pilot"; $product2="Power mac 5"; #print variable from another page print "Your chosen products...
0
by: SAN CAZIANO | last post by:
My site has: - 1 frame in top where I have some images to change the language of the site if clicked - 1 frame at left for the menu - 1 frame at middle to load the...
3
by: Microsoft | last post by:
I am using Session variables in my ASP application. I have tested the application on a Win2k professional and it works fine. When the same web app is installed on a win2k advanced server from the...
4
by: HolaGoogle | last post by:
hi there, i've 2 questions for you guys.... 1: is there any way to "force" a session_onend(), session timeout or at least call my logout method when a user leaves the application window without...
4
by: Kurt | last post by:
Hi I am using CDO 1.21 from C# in order to iterate through the entries in a users outlook address book (as OOM was too slow). Basically I take the Name field from each "message" and insert it into...
1
by: Carl Gilbert | last post by:
Hi I would like to know that best way of adding data to the session state object. I have a page with a series of links such as: designs.aspx?categoryID=1 designs.aspx?categoryID=2 When I...
8
by: rgparkins | last post by:
Hi I am creating a sign-up process on a web site much like that of a wizard form. I have browsed many sites to look for examples of how to store the entry data, so that the user can go back and...
17
by: Control Freq | last post by:
Hi, Not sure if this is the right NG for this, but, is there a convention for the variable names of a Session variable? I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any...
4
by: edgy | last post by:
Hello, I am a beginner with PHP, and I have made a language switcher on a site that I am looking for your feedback on. First of all, the page is http://www.mankar.ca My question regarding...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.