Languages :: PHP :: Link and session |
|||
| By: mbarka |
Date: 19/06/2003 00:00:00 |
Points: 300 | Status: Answered Quality : Excellent |
|
I have a code like this <?php session_start(); global $Login,$Logout; session_register("Login"); session_register("Logout"); ......some code if ($HTTP_SESSION_VARS[login] == "1") { echo "You are inlogged "; echo 'Klick<a href="side2.php?logout=1">here</a>'; } ?> /////Side2.php <?php session_start(); if ($HTTP_SESSION_VARS[logout] == "1"){ session_unset(); session_destroy(); echo 'Du är utloggad' ; ?> the problem is i get a white side with the right adress <A HREF="http://webbfk.tk.ah.com/~txxeu0bb/side2.php?logout=1">http://webbfk.tk.ah.com/~txxeu0bb/side2.php?logout=1</a> my question how to use $HTTP_SESSION_VARS when using <a href |
|||
| By: Wubbie | Date: 19/06/2003 08:01:00 | Type : Answer |
|
| I think you need to put quotes around your session variables -- as it is, they're not actually being looked up. So instead of $HTTP_SESSION_VARS[logout] use $HTTP_SESSION_VARS['logout'] Also, if you have a newer version of PHP (4.0+ maybe?) try using $_SESSION['logout'] instead. Post again if this does not solve your problem. |
|||
| By: sumotimor | Date: 19/06/2003 08:06:00 | Type : Assist |
|
| Looks like you've got case-sensitive issues with your variable names. $logout != $Logout. Change all occurences of "Logout" to "logout" and I think it will work. By default, PHP uses cookies to store the sessionID for the client, so you don't have to worry about propagating the sessID in your <a> links. |
|||
| By: mbarka | Date: 19/06/2003 08:30:00 | Type : Comment |
|
| When i use the code like this if ($HTTP_SESSION_VARS[Login] == "1") { echo "You are inlogged "; $Logout=1; echo 'Klick<a href="side2.php">here</a>'; } ?> this code works <?php session_start(); if ($HTTP_SESSION_VARS[Logout] == "1"){ session_unset(); session_destroy(); echo 'Du är utloggad' ; ?> but i doesnt work like this if ($HTTP_SESSION_VARS[Login] == "1") { echo "You are inlogged "; //$Logout=1; echo 'Klick<a href="side2.php?Logout=1">here</a>'; } ?> |
|||
| By: Wubbie | Date: 19/06/2003 08:32:00 | Type : Assist |
|
| sumotimor is correct. :) One more thing to remember is that == does not do type comparison, this usually still works but CAN still get you in trouble. You need to use === for type and value comparison. |
|||
| By: Wubbie | Date: 19/06/2003 08:33:00 | Type : Assist |
|
| You do need the session_start() in there to reinitialize your session. |
|||
| By: VGR | Date: 20/06/2003 05:40:00 | Type : Assist |
|
| sumotimor is 100% right here's a fixed code : <?php session_start(); global $Login,$Logout; // useless, even without register_globals=On in php.ini // personally, I affect values BEFORE session_registering ; it works better session_register("Login"); // so you use "old-style" registration : you thus can't use afterwards $_SESSION['Login'] session_register("Logout"); ......some code if ($Login == "1") { // you CAN NOT MIX styles to access session variables ! echo "You are inlogged "; // indent code echo 'Klick <a href="side2.php?logout=1">here</a>'; // double quotes are useless if no space possible inside the link } // if login=1 ?> /////Side2.php <?php session_start(); if (isset($_GET['logout'])) $Logout=$_GET['logout']; // beware of the case // else $Logout remains it's session value (register_globals=On) if ($Logout == "1"){ session_unset(); session_destroy(); echo 'Du är utloggad' ; } else echo "no logout provided"; ?> |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








