Jump to content

Archived

This topic is now archived and is closed to further replies.

Leovenous

Can a link set a session variable?

Recommended Posts

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:

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

...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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote author=Leovenous link=topic=99837.msg393413#msg393413 date=1152326847]
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.
[/quote]
Yea, because php is server-side, unlike javascript which is client-side.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.