Change value of session variable by clicking href

This is a discussion on Change value of session variable by clicking href within the PHP Language forums, part of the PHP Programming Forums category; Hi Like to change the value of a session variable by clicking a link ------------------------------ <?php session_start(); session_register("cat&...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-26-2006
sunnyboy@europe.com
 
Posts: n/a
Default Change value of session variable by clicking href

Hi

Like to change the value of a session variable by clicking a link

------------------------------
<?php
session_start();
session_register("cat");
?>
<a href="index.php" onMousedown=<? $_SESSION['cat']=1; ?>Set cat to
1</a>
<a href="index.php" onMousedown=<? $_SESSION['cat']=2; ?>Set cat to
1</a>
-----------------------------

Any ideas why this is not working and how I could do it?

Cheers
Sunnyboy

Reply With Quote
  #2 (permalink)  
Old 02-26-2006
Janwillem Borleffs
 
Posts: n/a
Default Re: Change value of session variable by clicking href

sunnyboy@europe.com wrote:
> Any ideas why this is not working and how I could do it?
>


You are making the mistake to mix client side (javascript) and server side
(PHP). Consider the following revision:

<?php
session_start();

if (isset($_GET['cat'])) {
$_SESSION['cat'] = $_GET['cat'];
}
print isset($_SESSION['cat']) ? "cat is {$_SESSION['cat']}" : 'cat is not
set<br />';
?>
<a href="index.php?cat=1">Set cat to1</a>
<a href="index.php?cat=2">Set cat to 2</a>


JW



Reply With Quote
  #3 (permalink)  
Old 02-26-2006
Drakazz
 
Posts: n/a
Default Re: Change value of session variable by clicking href

Hmm, what you are trying to do is to control php directly through
javascript. it doesn't work that way...
Here is an example that would work:

<?php
session_start();
if ( isset($_GET['cat']) ) { $_SESSION['cat'] = $_GET['cat'];
}
else {
$_SESSION['cat']=0;
}
?>
<a href="index.php?cat=1">et cat to 1</a>
<a href="index.php?cat=2">et cat to 2</a>
Cat is : <?php echo $_SESSION['cat']; ?>

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:19 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0