ClanKiller.com https://forums.clankiller.com/ |
|
global variables and sessions... https://forums.clankiller.com/viewtopic.php?f=8&t=552 |
Page 1 of 2 |
Author: | Satis [ Sun Nov 02, 2003 1:54 am ] |
Post subject: | global variables and sessions... |
Author: | Satis [ Sun Nov 02, 2003 2:11 am ] |
Post subject: | |
Author: | Pig [ Sun Nov 02, 2003 11:40 am ] |
Post subject: | |
Author: | Satis [ Sun Nov 02, 2003 1:19 pm ] |
Post subject: | |
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. |
Author: | Pig [ Sun Nov 02, 2003 2:02 pm ] |
Post subject: | |
Try echoing $_GET['flash'] instead of just $flash and see what you get. |
Author: | Satis [ Mon Nov 03, 2003 1:21 am ] |
Post subject: | |
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. |
Author: | Pig [ Mon Nov 03, 2003 7:08 am ] |
Post subject: | |
Author: | Satis [ Mon Nov 03, 2003 4:47 pm ] |
Post subject: | |
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. |
Author: | Pig [ Mon Nov 03, 2003 6:25 pm ] |
Post subject: | |
Author: | Satis [ Mon Nov 03, 2003 7:46 pm ] |
Post subject: | |
Author: | Pig [ Mon Nov 03, 2003 8:02 pm ] |
Post subject: | |
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. |
Author: | Satis [ Mon Nov 03, 2003 10:10 pm ] |
Post subject: | |
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. |
Author: | Satis [ Tue Nov 04, 2003 12:26 am ] |
Post subject: | |
Author: | Pig [ Tue Nov 04, 2003 7:31 am ] |
Post subject: | |
Author: | Satis [ Tue Nov 04, 2003 8:07 am ] |
Post subject: | |
Page 1 of 2 | All times are UTC - 6 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |