Jump to content


Photo

Can a link set a session variable?


  • Please log in to reply
4 replies to this topic

#1 Leovenous

Leovenous
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 08 July 2006 - 01:00 AM

Howdy,

I've come across a few situation where, at least my tiny little mind thinks, that it would be useful for your typical link, like:

printf("<p><a href='index.php?emag=mvp05'>MVP Baseball '05 CP</a></p>");

...to be able to set a session variable either in addition to, or instead of the modifiers at the end of the URL. Is there any way to do this, or just keep working with the URL?

Thanks.

#2 micah1701

micah1701
  • Members
  • PipPipPip
  • Advanced Member
  • 613 posts
  • LocationEllington, CT USA

Posted 08 July 2006 - 02:29 AM

not sure i follow but...

only you load the page w/ that url, you can call that variable from the page at any point by just using:

$_GET['mvp05']

are you asking how to move that variable to the next page with out keeping it in the url?  then your session idea will also work.

$_SESSION['mvp05'] = $_GET['mvp05'];

then, as long as you are using start_session(); at the top of each page, all pages w/ have access to that session var.
"Confidence in the face of risk."

#3 Leovenous

Leovenous
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 08 July 2006 - 02:47 AM

That much I get. I guess I was hoping there was something like Flash Actionscripts onClick thing. Where clicking the link will perform code before the browser follows the new URL.

Like:

onClick() {
    do this
    do that
    do the other thing
    Go to link destination
}

Maybe thats just a pipe dream because, if I understand it right, php has no way to continue processing code (as javascript would) once the page is loaded and the initial scripts run.

#4 Kurt

Kurt
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts
  • LocationNew York

Posted 08 July 2006 - 02:50 AM

Maybe thats just a pipe dream because, if I understand it right, php has no way to continue processing code (as javascript would) once the page is loaded and the initial scripts run.

Yea, because php is server-side, unlike javascript which is client-side.

#5 micah1701

micah1701
  • Members
  • PipPipPip
  • Advanced Member
  • 613 posts
  • LocationEllington, CT USA

Posted 08 July 2006 - 03:06 AM

right. you could do it with .NET or using "AJAX" - but that isn't really the same. you still have to load another page, you're just doing it behind the sences.

you could use javascript to do this for you.  read up on AJAX.
on your link, add an "onClick" event that lauches a function that will open "anotherPage.php" behind the scences.

on that other page, have a php script that updates the session variable.  wholla.
"Confidence in the face of risk."




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users