Check If Session & Session Variable Exist
I'm setting up a basic "shopping cart" using a multi-dimensional array stored in a session. I want to check if the session exists & if the cart has anything in it to determine whether or not to display "view cart" or "nothing in cart" - easy enough to do. BUT, I don't want to just session_start and then check if my variable is registered - or count() the variable (I'm thinking - why start a session if there is no need to at that stage?).
Seeing as you can't session_start(); before sending headers to the browser, I thought I could run this function at the very top of every page that needs to know if the cart has items in it, while trying not to start a session if one DOESN'T exist: PHP Code:
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Trying To Unset Single Session Variable Unsets Entire Session
I have all the data being stored in session variables, so when the student puts in his student ID, it passes it from one page to the next. After the student votes, I use a function called logout that checks if the vote was counted, then uses session_unset($_SESSION['studentID']) and I also have a place that passes an error through session to let the user know of various problems with their login, such as if they have already voted. if voting is disabled, or if there are no candidates to vote on. The problem I am having is when I use session_unset, it unsets ALL session variables, not just the ones I want. php.net says not to use session_unregister if register_globals is disabled, which it is. What else can I do? I need to be able to unset only $_SESSION['error'] (the returned error message) and $_SESSION['studentID'], instead of unsetting the whole session.
Session Problem: Session Exists, But Session Variables Don't Lasts
I have some troubles with session variables. I can easily create a session, but the variable I append to global session array ( $_SESSION) lasts only until the end of current function. I prepared an example that can demonstrate the problem (see code bellow): The program flow is this: (1) It starts with "session_start()" and displays "login_form()". (2) When user enters his username and password, it goes to "login()" function which sets $_SESSION variables. (3) This function also "Echoes" session_id and user name to the screen. (4) Then it goes to "MyProgram()" function. It only "Echoes" the same variables to the screen. Strange is, that the session_id is the same in (3) and (4), but the user name ($_SESSION["username"]) is only in (3), but not in (4). By other words - $_SESSION["username"] variable filled up by "login()" function is immediately cleared. I don't know why. There must be something missing, but after 3 days of watching it, I can not find a problem here. =========================================== <? Function login($uzivatel, $heslo) { $_SESSION["username"] = $uzivatel; $_SESSION["pass"] = $heslo; $U_Name=$_SESSION['username']; echo "Login username: $U_Name<BR>"; echo "Login session ID: "; echo session_id(); echo "<BR>"; } Function login_form() { echo ("<DIV ALIGN='center'> <H1>Test</H1> <P>Please enter your username and password:</P> <form action='test.php' method='get'> <INPUT TYPE='HIDDEN' NAME='login' VALUE=TRUE> <TABLE BORDER=Ɔ'> <TR> <TD ALIGN='right'><U>U</U>ser name:</TD> <TD><INPUT NAME='uzivatel' SIZE=25 ACCESSKEY='U' TYPE='TEXT'></TD> </TR> <TR> <TD align='right'><U>P</U>assword:</TD> <TD><INPUT NAME='heslo' SIZE=25 ACCESSKEY='P' TYPE='PASSWORD'></TD> </TR> <TR> <TD COLSPAN=2 ALIGN='RIGHT'><INPUT NAME='OK' ACCESSKEY='O' TYPE='SUBMIT' VALUE='OK' TABINDEX=3></TD> </TR> </TABLE> </FORM></DIV></HTML>"); } Function MyProgram() { $U_Name=$_SESSION['username']; echo "Program username: $U_Name<BR>"; echo "Program session ID: "; echo session_id(); echo "<BR>"; } { session_start(); if ($_SESSION['username']): MyProgram(); else: { if (!$login): login_form(0); else: login($uzivatel, $heslo); MyProgram(); endif; } endif; } ?> ===========================================
Session Check Is Not Working
I have a session which bounce's out the user if the session doesn't contain their UserID. I aint even changed the code in any way the only substantial change i have done is copy n pasted the script to a different pc and now it won't work at this pc. But it still does on the other computer even though they are 100% the same. Code:
Check To See If IMG Exist At Amazon
Im trying to check if a textbook image exist at Amazon.com. I use the link below to display the textbook img by the particular isbn #. <img src="http://images.amazon.com/images/P/<?php echo "$isbn";?>.01.MZZZZZZZ.jpg"> I have tried using the code below but it does not work because Amazon's image server returns a 807 byte image (looks empty) when it is accessed. Unfortunately I think this code requires a 404 response. Any ideas? Thank for your help <?php //check if image exists if($img = @GetImageSize("http://images.amazon.com/images/P/echo '$isbn'.01.MZZZZZZZ.jpg")) { echo "image exists"; } else { echo "image does not exist"; } ?>
PEAR DB Check If Row Exist
I need to check that a row exist in table either do an update if it does or an insert if it doesn't. I have tried using numRows() but have not been able to get it to work. Could someone please post an example of an if statement that would accomplish this. I would perfer that it be done in a manner that would allow for DB abstraction.
How To Check If A Session Exists In PHP4?
$id = session_id(); if ($id == '') {... no session ...} If the $id is empty, then there is no session. But the problem is when I use the "session_id()" function from a different page than the page that contains the "session_start()" function, the returned $id is always empty. Do have I to pass the SID in the url or something? Is there a setup file that I should update?
How To Check If A Session Exists In PHP4?
To check if it exists, I do: $id = session_id(); if ($id == '') {... no session ...} If the $id is empty, then there is no session. But the problem is when I use the "session_id()" function from a different page than the page that contains the "session_start()" function, the returned $id is always empty. Do have I to pass the SID in the url or something? Is there a setup file that I should update?
Reality Check: Session Hijacking
The only way to prevent session hijacking is to NEVER store authentication information (such as name/password) in the session. Well, to never authenticate a user from information you got from the session. Each secure app on a site must challenge the user for name and password, each and every time the user accesses it (not just once and then store it in the session). If a secure app is multi-page, then you must only pass session data in hidden form fields between each page, on forms that POST over https. That's my assertion. Is that right? If you disagree, consider this scenario: 1. User goes to a web site's homepage, over http. The site remembers him, Welcome, Joe. In other words, there's his session ID, travelling over insecure http in a plain text cookie that anyone can read with a packet sniffer. 2. User goes to edit some private data, such as his name and address or cc number or whatever, over https, and IS NOT CHALLENGED for his name/password, because the site knows who he is from his session. 3. The above is security breach. Someone with a packet sniffer could see his session id, as well as everything else about his requests- browser, ip address, etc, in plain text, when he was making requests over http. Then with that, the sniffer could make an https request to the same application that displays his private information. The sniffer doesn't know the user's loginname/password, and he doesn't have to, he's never asked for it. All he needs is the sesid cookie. If you agree, then look at this from the zend site, and isn't it fundamentally wrong?:
Loop Through Array And Create Variable Session Variable Names
As part of my user authentication class I've written a method that sets session variables. I pass an array to the function by reference which contains elements populated with information from the users table in the DB (name, street, country etc) At the moment the function looks like this: /* Set the session variables for easy access to user data */ function _setSessionData(&$userData) { $_SESSION['loggedOn'] = true; // Logged on $_SESSION['userID'] = $userData['UserID']; $_SESSION['username'] = $userData['UserName']; $_SESSION['password'] = $userData['Password']; $_SESSION['firstName'] = $userData['FirstName']; $_SESSION['surname'] = $userData['Surname']; $_SESSION['email'] = $userData['Email']; $_SESSION['street'] = $userData['Street']; $_SESSION['city'] = $userData['City']; return true; } What I'm wondering is if it is possible to loop through the $userData array, and dynamically name and populate the session variables rather than listing them all and assigning like I have?
What? Assigning A Session Variable Also Assigns The Local Variable?
Alright, In the following code, I expect the printed result to be: DEBUG: frank's last name is burns. Instead, what I get is: DEBUG: frank's last name is burns. Here is the code: $frank = "burns"; $_SESSION['frank'] = "black"; echo "DEBUG: frank's last name is is $frank"; What is coming into play here? I thought of register_globals but I thought that only dealt with GET, POST, REQUEST, etc.
Session Variable Becoming Linked To Post Variable
Basically i have a user id stored in session variable eg user_id =1. I have a simple forum that i created myself that inserts this session variable into the db with the persons entry. eg insert into forum value (session[user_id],'$_post['content']); This is all working fine until i go to edit this post from say the moderator account. I set the user_id for the "replace into db" initially to my session value unless i have selected to edit someone elses post, then i set it to the value submited back from the <form action=self> i get as far as selecting the contents from db only for the session variable holding my id to change to the value of the user_id selected from the db. Code:
Session Variable...
In PHP, how do I make a session variable. Such as, the user types in his/her login name and it will display it across the whole site.
SESSION Variable
$_SESSION['value1'] = mysql_real_escape_string($_POST['dt']); $sql = "INSERT INTO $table (value1) VALUES ("$_SESSION['value1']")" Something like that doesnt work. Is my syntax incorrect?
Php Session Variable
I am stuck on something really stupid and simple. Here is what I am trying to do. Login, check the username and password against db and if it checks out then check the logged variable session and pass the user to the next page. Here is a sample of the login process page: $user = 'test' $pass = sha1('testpass'); //set the database connection variables $hostname = "localhost"; $dbusername = "newuser"; $dbpassword = "newpassword"; $dbh = mysql_connect($hostname, $dbusername, $dbpassword) or die("Unable to connect to the database"); mysql_select_db("seandb", $dbh); $result = mysql_query("select * from users where username='$user' AND password='$pass'", $dbh); //check that at least one row was returned $rowCheck = mysql_num_rows($result); if($rowCheck 0){ while($row = mysql_fetch_array($result)){ //start the session session_start(); session_register('sname'); $sname = $user; //successful login code will go here... header( "Location: main.php" ); } }else { include 'index.php' printf("Incorrect Login..."); } Then on the Main page I want to be able check the variable sname and if it is set then say hi. For some reason this doesn't happen. The variable gets assigned a variable but once it is passed over to main.php, the session variable is not there anymore. Here is the code for main.php: if (!empty($_SESSION['sname'])) { ?> <p>Welcome</p><?php echo($_SESSION['sname']);?> <?php }else{ printf("failed..."); //header( "Location: index.php" ); } For some reason I always get the "failed" message....
Session (variable)
Many people seems to have similar problem that I have but no answer has helped me. I'm using the superglobals ($_SESSION['some_variable']) and trying to check this array element after I have started a session. For example: calling login (see below) will print "Welcome Jim", but when I log out it says that I weren't logged in (even if I try to log out immediately). This is true for all other scripts that try to access any $_SESSION['variable']. ANd the setting for register_globals is on. Do I do something terribly wrong? function login(){ $userid = strtolower($_POST['userid']); if ($_POST['userid'] != "some_user"){ //Will of course be replaced to a more secure way $this->main(); }else{ session_start(); $_SESSION['userid'] = $userid; include('header.php'); if (isset($_SESSION['userid'])){ print("Welcome $userid! <br />"); }else{ print("Welcome<br />"); } } } function logout(){ if (isset($_SESSION['userid'])){ session_unset(); print("Logging out $userid"); } else{ print("You weren't logged in!"); } $this->main(); }
Session Variable?
I creating a page that will be getting refreshed multiple times. I'm running a database query and doing a fair bit of other processing, that will remain the same when the page gets refreshed. Instead of processing the same data over and over I'm wondering if I should be using session variables to save the data. I'm not too familiar with using them so I'm looking for some advice also is the following code proper usage? PHP Code:
Session Variable
I have following problem: I try to retrieve images from mysql and show it. I retrieve them in loop using getData.php. getData.php uses session variable ($_SESSION['num']) to get image. However $_SESSION['num'] seems to be always 0. why? //showAll.php <?php session_start(); $num=0; session_register('num'); ?> <html> <head><title>Show data from SQL Database</title></head> <body> <?php MYSQL_CONNECT("localhost","root","pw"); mysql_select_db("database"); $sql = "SELECT count(id) FROM store;"; $result = MYSQL_QUERY($sql); $count = MYSQL_RESULT($result,0,"count(id)"); //------------------------------------------------------------------- //here is loop where $_SESSION['num'] is set and getData.php called while($count >1) { $_SESSION['num']=$count--; echo $_SESSION['num']; ?> <IMG SRC="getData.php"> <?php } //------------------------------------------------------------------- ?> </body> </html> //------------------------------------------------------------------- //getData.php <?php session_start(); if(isset($_SESSION['num'])) { @MYSQL_CONNECT("localhost","root","pw"); @mysql_select_db("database"); $num=$_SESSION['num']; $query = "select FileData,filetype from store where id=$num"; $result = @MYSQL_QUERY($query); $data = @MYSQL_RESULT($result,0,"FileData"); $type = @MYSQL_RESULT($result,0,"filetype"); Header( "Content-type: $type"); echo $data; } ?>
Session Variable
how am i surpose to set a variable from the previous page check if its same as before if it is then leave the session variable at same value if not change it to $_post['text'] which is the new value to use . Code:
Session Variable
I am using session variables in order to insert the username into the database when the user submits a form. I was just wondering as I don't fully understand session variables could this cause any problems? For example if one user logs in and then another will the first users session vars be overwritten? (I am only making a localhost site which is run locally, so if I did this on my machine logging in two different users one in firefox one in ie would this also be ok?)
Session Variable
I'm new to php and am currently running php5 with a mysql. The program all runs except for one major issue, the session variable. The following is my session header: <?php session_start(); require "systemClasses.php"; if (!isset($_SESSION["basePage"])) {$_SESSION["basePage"] = new SemesterHandler ();}?> and for the rest of the program I just use $_SESSION["basePage"] to access my object. The program is set up in two files right now, one is index.php where you start and it reads out to a semesters.php. The object works and I have tested it the issue is the session variable. The error I'm getting is this: PHP Fatal error: main() [<a href='function.main'>function.main[/url]]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "SemesterHandler" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in C:Program FilesApache Software FoundationApache2.2htdocsUniversitySchedulerPHPsemesters.php on line 22
Use SESSION Variable?
How do I get a POST variable into a session variable so I can use it in any other page I want to use it in? Apparently posted variables are only available in the Form page in...
Overwriting Session Variable
I have a form that when a user clicks a button it sends the data from a hidden field to a session variable. When the user clicks again I want that new value to be added to the other one like with an array. When i do this though the first variable always get overwritten so I can only store 1 value.
Session Variable Calling
My main three questions here are: if I set a variable to be registered in the session, do i include the "$" in session_register?: I.E: if ($num != 0){ $verified_user = $username; session_register("verified_user"); header("Location: redirect.php"); This is part of my login script, basically if they match a person my my database, their name is registered in a variable "$verified_user" and then $verified_user" is registered as a session variable so I can call it from different pages. So my do I need to include a $? Second question: When calling the session variable "verified_user" on a different page, do I include a "$" in from on it? say I wanted to print their name, would "echo "$verified_user";" work assuming sessions were started on every page. Third Question: this ties in to the first, when I want to unregister "verified_user", do I include the "$" once again? So basically I wondering on the rules for the "$" sign and with variables.
The Missing Session Variable
I have a little problem. I have been writing some programs using PHP. All of them use "sessions". Many use "session variables". One day the programs are working fine. The next day – puff. Nothing works. I've done some testing and I believe I have narrowed the problem down. It seems that the "session variables" are being lost after a <FORM> is submitted. Below are the scripts from two simple programs which I believe illustrate my problem. Any help would be greatly appreciated……..Bill Below are two scripts – two distinct files. The first one simply sets the session variable and branches to the second file. Please understand that all the <HTML> and <BODY> statements are present but have been eliminated from here to save space. ------- first script or file begins here ---------
Session Variable Seems Not Work
concerning three session variables, it can work in PHP Version 4.0.4pl1, However it seems not OK in PHP Version 4.3.1 with only two of three variables valid when debug the program. Why? Please give me possible solution,
SESSION Variable Gets Cleared
I have two files login.php and loggedin.php. If I understand $_SESSION correctly, its values should stay in place when I go from login.php to loggedin.php, right? They won't, $_SESSION gets cleared in loggedin.php. Have I done anything wrong? Here are my test files: login.php <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title> PHP: Log In </title> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> </head> <body> <div id="pageheader"> <h1> Pot Head Pixie: PHP </h1> </div> <div id="main"> <!-- short_open_tag = Off --> <?php echo '<p>Hello World</p>' echo $_SERVER['HTTP_USER_AGENT']; echo str_replace('','/',getcwd()); @session_destroy(); @session_start(); unset($adminlogin); unset($adminpass); unset($adminip); $_SESSION['adminlogin']=md5('adm'); $_SESSION['adminpass']=md5('pass'); unset($adminlogin); unset($adminpass); unset($adminip); echo '<br />' echo '$_SESSION['adminlogin']: ' echo $_SESSION['adminlogin']; echo '<br />' if (isset($_SESSION['adminlogin'])) { echo "adminlogin is set"; } else { echo "adminlogin is not set"; } ?> <form action="loggedin.php" method="post"> <p> <input type="text" value="user" /> </p> <p> <input type="password" value="password" /> </p> <p> <input type="submit" value="OK" /> </p> </form> </div> </body> </html>........
Why Is My Session Variable Not Already Set The First Time
If I run the following PHP script the session variable auth_ok changes to true resp. false only if I press the button 1 resp. 2 twice. =================== <?php session_start(); if (!isset($_SESSION['auth_ok'])) { $_SESSION['auth_ok'] = false; } echo "Username: " . $_POST['user'] . "<br>"; echo "Password: " . $_POST['pass'] . "<br>"; echo "Button 1: " . $_POST['button1'] . "<br>"; echo "Button 2: " . $_POST['button2'] . "<br>"; echo "Authentication: " . $_SESSION['auth_ok'] . "<br>"; if (isset($_POST['button1'])){ echo "Button 1 has been pressed<br>"; $_SESSION['auth_ok'] = true; } if (isset($_POST['button2'])){ echo "Button 2 has been pressed<br>"; $_SESSION['auth_ok'] = false; } ?> <html> <body> <form name="loginform" method="post" action="mytest.php"> Username: <input type="text" name="user" size="30" maxlength="30"><br> Passwort: <input type="password" name="pass" size="30" maxlength="30"><br> <input type="submit" name="button1" value="Button 1"> <input type="submit" name="button2" value="Button 2"> </form> </body> </html> =================== The PHP error logs says [24-Apr-2005 21:48:09] PHP Notice: Undefined index: button1 in D:WWWphp\_login-sisimytest.php on line 10 or [24-Apr-2005 21:48:28] PHP Notice: Undefined index: button2 in D:WWWphp\_login-sisimytest.php on line 11 depending on the button I pressed. What's wrong with my PHP script?
Session Variable Problem
This is my script test.php: <? session_start(); if($_SERVER["REQUEST_METHOD"] == "POST") check_form(); if(session_is_registered("ok")) { echo "it is ok"; //here's the problem session_unregister("ok"); } ?> <form action="test.php" method="post"> <input type="submit" value="OK"> </form> <? function check_form() { $ok = TRUE; session_register("ok"); header("location:test.php"); } ?> The problem is that when I send form and refresh page with header, the sentence "it is ok" doesn't show but it should because session variable $ok is registered. What's wrong ? When I'm not using header, it works ok. My PHP version is 4.3.1-dev.
Why Does A Session Variable Return To Its Old Value?
I have a problem in my application I have not been able to reproduce completely with a simpler set of files. I know this is a crime, but here goes: In a file I have these instructions: echo 'before: '.$_SESSION['classtitle'].'<br />' require_once 'test3.php' echo 'after: '.$_SESSION['classtitle'].'<br />' echo '<p><a href="test.php">test</a></p>' They display on the screen: before: b test3 before: b test3 after: a after: a So far, so good. But, when I click the link to test.php, this is displayed: test: b I don't understand how $_SESSION['classtitle'] goes back to its old value. Here are test3.php and test.php: test3.php: <?php session_start(); echo 'test3 before: '.$_SESSION['classtitle'].'<br />' $_SESSION['classtitle'] = 'a' echo 'test3 after: '.$_SESSION['classtitle'].'<br />' ?> <?php session_start(); echo 'test: '.$_SESSION['classtitle'].'<br />' ?>
Changing Session Variable
I hope this is a simple question...... I need to be able to change a session variable when a wondow closes. Does anyone have any idea how this could be accomplished?
Session Variable Problem
I am having a problem with session vars being propagated between pages on this site: If you enter any user id and password and click Log In (no actual validation is performed), and then move around the other pages and/or keep refreshing the pages it will eventually display something that is incorrect i.e. saying your logged in when you aren't or vice versa. The exact same code here http://ccgi.gnosis.free-online.co.uk/index.php works fine implying a problem with the first PHP installation. Here is the code for the 3 files: =========== index.php ============= <?php session_start(); if (isset($_POST['userid']) && isset($_POST['password'])) { // if the user has just tried to log in $userid = $_POST['userid']; $password = $_POST['password']; //assume valid login so set session var $_SESSION['loggedinusername'] = $userid; } ?> <html> <body> <h1>Home page</h1> <? if (isset($_SESSION['loggedinusername'])) { echo 'You are logged in as: '.$_SESSION['loggedinusername'].' <br / Quote:
Creating New Session Name Variable!!!
Have anybody heard of creating new session variable. Not $_SESSION["one"] and $_SESSION["two"] I mean after logging into my site if the user click on a link it will opens a popup so he can have different session there and if he logs out then it just close the session in that popup not in the parent window. Why I need this is because the application in the popup is an integrated with some outer software.
Did I Get My SESSION Variable Coding Right?
Here is the code that i've written: <snip> Made an image so it's easier to read. When I visit my page it seems to set the SESSION variable every time. Even when I visit the page without sending a querystring and the SESSION variable is already set.. What have I done wrong in my code? //set SESSION colour variable. If I've passed a "querystring" to change the colours then change SESSION colour. //extract SESSION colour variable. If SESSION variable exists then extract it otherwise choose to set SESSION variable to orange. //setup PAGE colors. Use SESSION variable to setup my page colours.
Session Variable In An Embedded JS
I have a php page, index.php, that calls a JS in the following manner: Code: <script language="JavaScript1.2" src="script1.js" type='text/javascript'> Now, script1.js calls a php page to dynamically insert content to script1.js. script1.js has this: Code: document.write("<SCR" + "IPT LANGUAGE='JavaScript1.2' SRC='script2.js.php' TYPE='text/javascript'></SCR" + "IPT>"); These scripts work together as far as they go. However, I need to do one more thing. I need to use a session variable in script2.js.php. How do I do that? I put session_start() in the index.php page and echoed the variable, so I know that it has gotten passed that far. I tried using session_start() in the script2.js.php page, and that doesn't work. It also doesn't work to simply refer to the variable.
PHP Session And Variable Question...
I have a really easy (I hope) question but have come you a blocking point and need some help... My web page contains both standard HTML and PHP code. No problem there... On one page after the user logs in I set a session variable $_SESSION['fName'] = $fName // $fName is passed to the function. When I draw this page the variable in $_SESSION['fName'] echo's correctly and I can go to other pages and it will still be there correctly. However, I need more than one variable $_SESSION['account']=$eMailAddr where $eMailAddr = their email address. If I add this to the code where I set $_SESSION['fName] it all echoes correctly on the first page, however, if I got to another page only the ['fName] echoes, ['account] does not. Any suggestions? Remember this php code is imbedded in an HTML page.
How Can I Get Session Variable Names
Is there any way through which I can get what session variables are created in the session. Suppose there are two pages. Page A and page B Page A has a link for page B When a person clicks link of Page B on Page A, he should get the list of all session variables and there values. Is this possible? Also is it necessary that Page A should also be in php. Will it work if it is java.
Receiving Variable From Session
After I register variable in session : session_start(); session_register($var); new page opens include("register2.php"); At the page I fill some forms and send variables from forms to another page - with GET method. And now at the 3rd page I need to receive a variable from the session but it's empty. Interesing is that on the second page receiving $var from session works without any complications just by using: session_start(); print ($var); I have no idea what I did wrong and I would be grateful for advices, maybe there is some other method of posting variables from "1st page to 3rd".
Session Variable Getting Setting Itself?
I have a page that does no assigning to the session variable and it prints out nothing for $_SESSION[myvar] at the bottom of the page. Then I go to a page with ONLY this code: session_start(); session_register("myvar"); echo "myvar is:" . $_SESSION[myvar]; it prints out 138, a value I used in the previous page, but did not assign to the session var. So how did it get set?? Once again, so I don't sound too stupid: I displayed the session var at various points throughout my first page. It was always blank. Then I type in the url of the second page (with minimal code) and it prints out a value for that session var right after I "session_register("myvar");" it.
Problem With Session Variable
I am building a site and i want to password protect some pages. In order to do this i use this variable: $_SESSION['validated'] and i set it to true when a user has logged in. So in one file when a user has logged in i have the following: <?php @session_start(); $_SESSION['validated']=true; ?> I am trying to check if this variable is set to true in some other file like this: <?php @session_start(); if ( isset($_SESSION['validated']) && $_SESSION['validated']==true ) { /*Something*/ } else { /*Do something else*/ } ?>
Session Variable Problem
I am having a problem with session vars being propagated between pages on this site: If you enter any user id and password and click Log In (no actual validation is performed), and then move around the other pages and/or keep refreshing the pages it will eventually display something that is incorrect i.e. saying your logged in when you aren't or vice versa. The exact same code here http://ccgi.gnosis.free-online.co.uk/index.php works fine implying a problem with the first PHP installation. Here is the code for the 3 files: =========== index.php ============= <?php session_start(); if (isset($_POST['userid']) && isset($_POST['password'])) { // if the user has just tried to log in $userid = $_POST['userid']; $password = $_POST['password']; //assume valid login so set session var $_SESSION['loggedinusername'] = $userid; } ?> <html> <body> <h1>Home page</h1> <? if (isset($_SESSION['loggedinusername'])) { echo 'You are logged in as: '.$_SESSION['loggedinusername'].' <br / Quote:
Session Variable Problem
I'm getting a little frustrated w/ PHP. I have the following sequence: page 1 gets input from user, calls script 1 script 1 sets session variables from page 1 POST with: $_SESSION['email'] = $_POST['EMAIL'] $_SESSION['link'] = [mysql link] script 1 calls page 2 page 2 takes in more data and calls script 2 script 2 gets session variables set in script 1 but errors out with: Notice: Undefined variable: _SESSION in p1info.php on line 30
Arrays In A Session Variable
What I am attempting to do is create an expanding array, and call a function that pulls a record from a database table. Then search the aray for a value. The problem is the array will have to be in a session variable. I have tried the following without success. Code:
One Session Variable Not Being Destroyed
I have a system which uses three session variables; 'rank', 'username' and 'userid'. I was doing the following on 'sign-out' to get rid of these variables: Code:
Session Variable Problem
i can sucessfully register session variables as long as i do everything right after my session_start(). below is my file directory and the scripts i am using (there are two pages called login.php sorry for the poor naming convention) Code:
|