|
It is currently Sun Nov 24, 2024 12:04 am
|
global variables and sessions...
Author |
Message |
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16662 Location: On a slope
|
global variables and sessions...
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Sun Nov 02, 2003 1:54 am |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16662 Location: On a slope
|
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Sun Nov 02, 2003 2:11 am |
|
|
Pig
Duke
Joined: Mon Mar 31, 2003 8:59 am Posts: 1358 Location: right behind you
|
|
Sun Nov 02, 2003 11:40 am |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16662 Location: On a slope
|
erm, sure. I guess you mean about the sesssion_start() and stuff, right? Anyway...
here's my index.php (the only part that matters);
<A href="index2.php?flash=1">Flash version</a>&<a href="index2.php">NonFlash Version</a>
So, selecting the first one sets $flash=1, while the second leaves $flash unset.
On the second page, if I do a;
echo $flash;
after clicking the first link, I get a 1. However, if I do this;
session_start();
echo $flash;
I get nothing. Somehow doing the session_start(); wiped out the $flash variable. So instead I was forced to used an if/else statement which starts the session and manually assigns $_SESSION["flash"] instead of it being automatic like it should be.
I have tried putting a session_start(); in index.php, but it didn't make any difference.
Ermm...if you want, I can post up the actual pages. What I'm trying to accomplish is, of course, a bit more complex than a simple echo. Anyway, lemme know.
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Sun Nov 02, 2003 1:19 pm |
|
|
Pig
Duke
Joined: Mon Mar 31, 2003 8:59 am Posts: 1358 Location: right behind you
|
Try echoing $_GET['flash'] instead of just $flash and see what you get.
|
Sun Nov 02, 2003 2:02 pm |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16662 Location: On a slope
|
hmmm..ok, I'm really kinda confused as to what precisely was going on, but I think I've (finally) got it.
The $_GET['flash'] does work, but when I was testing it $flash worked also. This is when I call the session_start(); immediately. I was probably doing something wrong before. Bleh.
My biggest problem was when people would refresh the page, or hit index2 from some place other than index (thereby not carrying the variable in the url). I think I've solved that by doing
extract ($_SESSION['flash']);
I tried a bunch of ways to try and confuse it and I've failed to break it so far.
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Mon Nov 03, 2003 1:21 am |
|
|
Pig
Duke
Joined: Mon Mar 31, 2003 8:59 am Posts: 1358 Location: right behind you
|
|
Mon Nov 03, 2003 7:08 am |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16662 Location: On a slope
|
can you pass $_SESSION variables through a URL (GET, I guess)? I couldn't get this to work any other way, but if you have a viable alternative that represents 'good' programming, please, let me know.
That's one of the reasons I'm asking so many questions. I want to groom good programming habits from the start.
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Mon Nov 03, 2003 4:47 pm |
|
|
Pig
Duke
Joined: Mon Mar 31, 2003 8:59 am Posts: 1358 Location: right behind you
|
|
Mon Nov 03, 2003 6:25 pm |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16662 Location: On a slope
|
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Mon Nov 03, 2003 7:46 pm |
|
|
Pig
Duke
Joined: Mon Mar 31, 2003 8:59 am Posts: 1358 Location: right behind you
|
2 questions there.
1st:
current page: $_SERVER['PHP_SELF']
previous page: $_SERVER['HTTP_REFERRER']
2nd:
Having a status check on every page is standard design. The best design is not to send your peeps to a different page, and then send them back, but rather include a file that does the checking, and processing.
Let me give you an example. On my site, I have a file that is included on every page before anything else (because of the issue with sending header()'s). This page looks for cookies, and will send cookies if I tell it to.
On "member only" sections of the site, I merely include another file. This second file checks the data gathered in the first file, and checks the db to see if they have appropriate permissions. If they do, the rest of the page displays. If they do not have the cookie, or are not in the database, then the page displays a form for them to log in with, and kills the rest of the page (see die() ).
The form they are given has the action=$_SERVER['PHP_SELF']. The first file then processes the information, sends a cookie, and then sends a header("Location:" . $_SERVER['PHP_SELF']); No matter what page they are at, all the processing is done on that page, and they have never actuallly left it. Make sense? My script is actually more complicated than this, but you get the concept.
|
Mon Nov 03, 2003 8:02 pm |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16662 Location: On a slope
|
I understand what you're saying with the cookie check/login thing. Though I could do that with the flash thing, I don't want to. Most of my hits are from search engines, and I don't want to force people to go anywhere other than what they were looking for. If they decide to browse further, they can, and if they decide they want the flash version rather than the default html version, they can do that too.
The way I'm conceptualizing it is a link at the bottom of the menu that sends them to flashchoice.php (or maybe nonflashchoice.php as well), which then sets the cookie and immediately redirects them back to the page they came from. I don't want to force any of my visitors to do anything at all before reaching the content they're looking for. Additionally, I don't want to screw up any spiders.
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Mon Nov 03, 2003 10:10 pm |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16662 Location: On a slope
|
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Tue Nov 04, 2003 12:26 am |
|
|
Pig
Duke
Joined: Mon Mar 31, 2003 8:59 am Posts: 1358 Location: right behind you
|
|
Tue Nov 04, 2003 7:31 am |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16662 Location: On a slope
|
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Tue Nov 04, 2003 8:07 am |
|
|
Who is online |
Users browsing this forum: No registered users and 5 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|