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

Passing a session variable from page 1 to page 2 via a hyperlink.

348 100+
Hi all..

I'm back with another problem that I just can't seem to solve. I have dynamically generated hyperlinks that are created from a while loop in tabular format.

Each hyperlink should take the user to the next page by way of a session with THAT generated link. (I really don't want to use GET for this) That links generated value must be used to pass to the next page. Depending on what that number is will determine what will be displayed on the next page.

It finally dawns on me that I need an array to do this so I started looking for an example and came up with this:

Page 1 (the hyperlinks)
[PHP] $theArray = array();
$theArray['incident_Number_Id'] = 'incident_Number_Id';
$_SESSION['incident_Number_Id'] = $theArray; [/PHP]

I put this into the tabular page that the user can choose from.

From here, I am lost.. Can someone shed some light or point me in the direction in which I need to go please.

Thanks,

Frank
Jun 29 '07 #1
14 2629
ronnil
134 Expert 100+
Let me get this right

You want to display lets say 3 hyperlinks depending on what the user selects, you want to store a variable saying "he clicked on number 2"

I don't see why passing this as a GET variable, but you probably got your reasons.

How bout making 3 seperate pages choice1.php choice2.php choice3.php, you then make a fourth page containing whatever code you wish to be executed. on choice1,choice2 and choice3 you first store "he clicked on me" to later use.

example:

execute.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $sql = "INSERT INTO steps (step,choice) VALUES ('step1','" . $mychoice . "')";
  3. $result = mysql_query($sql);
  4. ?>
  5.  
choice1.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $mychoice='you clicked on one';
  3. include('execute.php');
  4. echo $mychoice
  5. ?>
  6.  
choice2.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $mychoice='you clicked on two';
  3. include('execute.php');
  4. echo $mychoice;
  5. ?>
repeat with choice 3

By including the file that does the execution, you spare yourself alot of "twice writing" code, making it easier to update.

you can ofcourse save it in $_SESSION or whatever

If it's a matter of making your querystring look clean, might i suggest using an iframe for the job instead?
Jun 29 '07 #2
ak1dnar
1,584 Expert 1GB
fjm,

Could you please explain it little bit.

You are saying that those links to the users are stored in a array.
From where did you assign the elements to that array.(Array Variables)
Is it from a Database Table or Some Other Way.?

How could your Application determine which user to which link.
Is there any relationship with the LINKS and USERS.?


Thanks.
Jun 29 '07 #3
fjm
348 100+
fjm,

Could you please explain it little bit.

You are saying that those links to the users are stored in a array.
From where did you assign the elements to that array.(Array Variables)
Is it from a Database Table or Some Other Way.?

How could your Application determine which user to which link.
Is there any relationship with the LINKS and USERS.?


Thanks.
Hey Ajax,
the links are stored in this fashion:

[PHP] $result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count >= 1) { html......

then my while loop to gather my data

while($data = mysql_fetch_assoc($result)) {
[/PHP]

The output from this loop will produce my id keys from my db. I need to have those keys as hyperlinks but each hyperlink must be unique, in other words, if the id key in the database for row 1 is 1 then when the user clicks 1 that same number needs to be stored in a session for the next page. and if row 2 has an id key of 44, then if the user clicks 44 that same number must go to the next page.

Thanks
Jun 29 '07 #4
fjm
348 100+
Let me get this right

You want to display lets say 3 hyperlinks depending on what the user selects, you want to store a variable saying "he clicked on number 2"

I don't see why passing this as a GET variable, but you probably got your reasons.

How bout making 3 seperate pages choice1.php choice2.php choice3.php, you then make a fourth page containing whatever code you wish to be executed. on choice1,choice2 and choice3 you first store "he clicked on me" to later use.

example:

execute.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $sql = "INSERT INTO steps (step,choice) VALUES ('step1','" . $mychoice . "')";
  3. $result = mysql_query($sql);
  4. ?>
  5.  
choice1.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $mychoice='you clicked on one';
  3. include('execute.php');
  4. echo $mychoice
  5. ?>
  6.  
choice2.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $mychoice='you clicked on two';
  3. include('execute.php');
  4. echo $mychoice;
  5. ?>
repeat with choice 3

By including the file that does the execution, you spare yourself alot of "twice writing" code, making it easier to update.

you can ofcourse save it in $_SESSION or whatever

If it's a matter of making your querystring look clean, might i suggest using an iframe for the job instead?
Hi Ronnil,

Thanks for the reply. This system can't use GET because of the sensitive nature of the data. It must use a session.

I wish it were as easy as just static hyperlinks. Sometimes there may only be one hyperlink and sometimes maybe as many as 40. It depends on how many rows are in the database.
Jun 29 '07 #5
ak1dnar
1,584 Expert 1GB
Hey Ajax,
the links are stored in this fashion:

[PHP] $result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count >= 1) { html......

then my while loop to gather my data

while($data = mysql_fetch_assoc($result)) {
[/PHP]

The output from this loop will produce my id keys from my db. I need to have those keys as hyperlinks but each hyperlink must be unique, in other words, if the id key in the database for row 1 is 1 then when the user clicks 1 that same number needs to be stored in a session for the next page. and if row 2 has an id key of 44, then if the user clicks 44 that same number must go to the next page.

Thanks
OK,
That means you are going to list some hyperlinks on page-1.links values are getting from database.
page-1.php

<a href="page-2.php">Link 1</a> // This is ID 44
<a href="page-2.php">Link 2</a> // This is ID 25
<a href="page-2.php">Link 3</a> // This is ID 10

Once User clicks 44 link, page redirect to page-2.php, Correct?

page-2.php

When comes to this page,that 44 should be in Session variable.
and you need to re use it another process.
Am i correct or not?

Now the issue is you are not going to Dispaly this 44 in Page-1.
seems like a tough one ha? :)
Jun 29 '07 #6
ronnil
134 Expert 100+
hmmm have you thought about encrypting the data and passing it with GET instead?

PEAR for instance offers great possibilities with encryption/decryption of data

http://pear.php.net/packages.php?cat...ame=Encryption

this way, your sensitive data shouldn't be so obvious to read.
Jun 29 '07 #7
fjm
348 100+
OK,
That means you are going to list some hyperlinks on page-1.links values are getting from database.
page-1.php

<a href="page-2.php">Link 1</a> // This is ID 44
<a href="page-2.php">Link 2</a> // This is ID 25
<a href="page-2.php">Link 3</a> // This is ID 10

Once User clicks 44 link, page redirect to page-2.php, Correct?

page-2.php
When comes to this page,that 44 should be in Session variable.
and you need to re use it another process.
Am i correct or not?

Now the issue is you are not going to Dispaly this 44 in Page-1.
seems like a tough one ha? :)
Yes sir, Mr. Rand... You got it !! :)

When the user clicks ID 25 by your example then 25 should register in the session and so on..

Remember, I am using a while loop and I think I need an array to complete this..

Yes, it really does seem like a tough one.. I just can't for the life of me figure it out and its the last page before the app comes to life. The suspense is killing me. :)
Jun 29 '07 #8
fjm
348 100+
hmmm have you thought about encrypting the data and passing it with GET instead?

PEAR for instance offers great possibilities with encryption/decryption of data

http://pear.php.net/packages.php?cat...ame=Encryption

this way, your sensitive data shouldn't be so obvious to read.
Hey Ronnil. Hmmm.. no I havent but if it could be encrypted, that would be just fine too. As long as the user couldn't mess with the url..

Gonna check out your link. Thanks!

Frank
Jun 29 '07 #9
ak1dnar
1,584 Expert 1GB
Yes sir, Mr. Rand... You got it !! :)

When the user clicks ID 25 by your example then 25 should register in the session and so on..

Remember, I am using a while loop and I think I need an array to complete this..

Yes, it really does seem like a tough one.. I just can't for the life of me figure it out and its the last page before the app comes to life. The suspense is killing me. :)
You can Use MD5() for the values that you do not wish to display in the client side.
[PHP]
<html>
<head>
<script language="JavaScript" type="text/javascript">
function CallJSFunc(id)
{
window.location='next_page.php?SES='+id;
}
</script>

</head>
<body>
<?php
include 'dbcon.php';
$query = 'Select p_id,p_name from products LIMIT 5';
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
{
echo '<a href="#" onclick="CallJSFunc(\''.md5($row['p_id']).'\')">'.$row['p_name'].'
';
}

?>
</body>
</html>[/PHP]

Make sure if you need the to Get the relavant records from the next_page.php related to the encrypted ID, your Table records must be in MD5 format inside the table.

On next_page.php Create the Session by using the encrypted ID and re use anywhere.
Jun 29 '07 #10
fjm
348 100+
Thanks for the reply Ajax.. Is there no other way to do this without using javascript? I mean, couldn't I save the output from the while loop into a variable and then echo the output into hyperlinks, then using POST go to the next page with the value. Is this not possible?
Jun 29 '07 #11
Hi

Why not include the array index number for each row of information into your page links as a get. Then as long as your array is saved as a session variable, the get can be processed against the array to extract and process the correct data.

That way, no confidential data is passed, just an arbitary number pointing to the relevant array field.

Paul
Jun 30 '07 #12
kovik
1,044 Expert 1GB
Yeah, what you want to do is not possible with sessions alone. We have the GET method, the POST method, and SESSIONS because each has it's own individual purpose and use. If one could do everything the others could, we'd only need one.

In order to determine the link a user pressed, you'll have to use the GET method. It's pretty much your only option. You're URL variables shouldn't be long enough to carry any "sensitive information" in the first place. If you want to hide the information, you'll need to post it through a form which doesn't look like an option in your case.
Jun 30 '07 #13
fjm
348 100+
Hi

Why not include the array index number for each row of information into your page links as a get. Then as long as your array is saved as a session variable, the get can be processed against the array to extract and process the correct data.

That way, no confidential data is passed, just an arbitary number pointing to the relevant array field.

Paul
Hi Bigbloke. Thanks for the reply. This seems like what I need to do but I don't know how to implement it. A lot of other people seem to think that there is no other way to do this unless accompanied by javascript or something else. A session is what I prefer to use.

Could you please provide an example for me.

Does anyone know if what Bigbloke is suggesting will work or not? I have no idea myself..

If it is what it is, I can certainly accept that but I want to make sure that I am being clear on what it is I am trying to accomplish. I am thinking that maybe I am being misunderstood because I lack the proper terminology.

Thanks.
Jul 1 '07 #14
fjm
348 100+
Yeah, what you want to do is not possible with sessions alone. We have the GET method, the POST method, and SESSIONS because each has it's own individual purpose and use. If one could do everything the others could, we'd only need one.

In order to determine the link a user pressed, you'll have to use the GET method. It's pretty much your only option. You're URL variables shouldn't be long enough to carry any "sensitive information" in the first place. If you want to hide the information, you'll need to post it through a form which doesn't look like an option in your case.
Hi [size=3]volectricity,[/size]
[size=3][/size]
[size=3]Thanks for the reply. Thats fine.. I understand what you are saying. Do you have any idea what the post by Bigbloak is talking about?[/size] vbmenu_register("postmenu_2667370", true);
Jul 1 '07 #15

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

Similar topics

5
by: Paul | last post by:
I want to use sessions to cover myself in case the user switches off cookies so I am passing the session ID manually through a hidden input field. This is what I have so far. index.php page...
1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
1
by: Newbie | last post by:
OK, this may be impossible since I'm using 3rd party shopping cart ASP software, but I've been able to finagle a lot of other stuff I thought wouldn't work, so here we go: I'm using a form in...
4
by: hansen | last post by:
hi all, I am creating online quiz (10 questions) with radio buttions (Yes/No). When the user clicks on the submit button i do some calculation and based on that calculation i display result.aspx...
4
by: opt_inf_env | last post by:
Hello, I know three ways to pass variables form one page to another. The first one is to declare and set session variable. In this case if one goes to another page (by clicking on hyperlink or...
4
by: Gibs | last post by:
Hi I have two aspx pages in a frame and in the top page i am creating the controls dynamically and putting in a place holder. I have a hyperlink in this page to populate the data in the bottom...
3
by: Wayne Wengert | last post by:
I have an application where a session variable is set in an ASPX page, The process calls an ASP page and when in that page the session variable appears to be null. How can I pass a session variable...
2
by: Al Wilkerson | last post by:
Hey guys, I'm having problems with creating/storing a value in a session variable for later retrieving on another page. Here is the aspx page where I create/store the value ...
4
by: T Ralya | last post by:
I am told that ASP.NET controls the session ID and session variables, but that does not fit my symptoms. I am posting here as directed. I'm hoping that someone can at least recommend something to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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$) { } ...
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...

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.