Jump to content

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.
Link to comment
https://forums.phpfreaks.com/topic/13994-can-a-link-set-a-session-variable/
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.
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.
[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.
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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.