LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-31-2002, 09:59 AM   #1
norbs
LQ Newbie
 
Registered: Jul 2002
Location: france
Distribution: redhat
Posts: 6

Rep: Reputation: 0
php:passing a var by a link by using session


in php

I want to make a link to another page
so
<A HREF="/smthg.php">blabla</A>

The problem is that i want to pass some variables to the smthg.php page

I have to open a session by session_start, and then using session_register : no problem w/ that, it works perfectly...

thanks for the master who can answer me.
 
Old 07-31-2002, 10:51 AM   #2
lackluster
Member
 
Registered: Apr 2002
Location: D.C - USA
Distribution: slackware-current
Posts: 488

Rep: Reputation: 30
I'm no master but depending on your environment, you need to pass sid from all your links :
Code:
<a href="this.php<?=sid?>">this</a>
Also, session_start() continues a session so call it on subsequent pages.
 
Old 08-01-2002, 04:10 AM   #3
norbs
LQ Newbie
 
Registered: Jul 2002
Location: france
Distribution: redhat
Posts: 6

Original Poster
Rep: Reputation: 0
ok for the SID.

for exemple:

<?php
session_start();
session_register("var");
?>

<A HREF="smthg.php?<? print SID; ?>">blabla</A>

I want for exemple that a variable $var take the value of 5 when clicking the link blabla
 
Old 08-01-2002, 02:41 PM   #4
lackluster
Member
 
Registered: Apr 2002
Location: D.C - USA
Distribution: slackware-current
Posts: 488

Rep: Reputation: 30
okay...... what's the problem then?

at the top of smthg.php put the following :
<?
session_start()
if (isset($var)) echo("Var is set to $var");
else $var = 5;?>
 
Old 08-02-2002, 02:57 PM   #5
norbs
LQ Newbie
 
Registered: Jul 2002
Location: france
Distribution: redhat
Posts: 6

Original Poster
Rep: Reputation: 0
But I want that $var have different value depending the link
I've read that I have to do smthg like :

<A HREF="smthg.php?<? print $var=5; ?>">link1</A>
<A HREF="smthg.php?<? print $var=10; ?>">link2</A>

The problem is that when i'm using the link1, i've got $var=10 ?!!
 
Old 08-02-2002, 04:50 PM   #6
lackluster
Member
 
Registered: Apr 2002
Location: D.C - USA
Distribution: slackware-current
Posts: 488

Rep: Reputation: 30
Okay, I get it now. Here's the deal ....

ASP, CFusion, PHP, CGI (Perl or whatever) all of this web language stuff have common properties. One of which whose concept you need to grasp is this : These languages run on the server and return HTML. Once the HTML is sent back, you cannot modify the script's variables. If you like we can get more in depth about this and why you can't do what you want to do, but hopefully this will suffice.

Here is an alternitive :
Use flags to tell the next page you want to set this variable. Like this : <a href = "page2.php?set_var=5">link</a> <a href = "page3.php?set_var=10">link2</a> and then on the other pages just do something like this :
<? if(isset($set_var)) {
$var = $set_var;
}?>

Cool?

Last edited by lackluster; 08-02-2002 at 04:52 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Are PHP session variables held in memory when you leave a PHP site? Locura Programming 11 11-16-2008 09:37 PM
PHP & MYSQL => session object using db link resource ldp Programming 2 03-19-2005 03:38 AM
PHP session_id passing kloppster Linux - Software 0 07-19-2004 01:19 PM
Passing variables in PHP???? vous Programming 3 03-20-2003 07:03 AM
PHP question (passing an operation via link) bkeating General 0 10-14-2002 12:18 AM


All times are GMT -5. The time now is 04:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration