Assign Userid To A Session Variable
When a user logs into my system, i assign their userid to a session variable
[php]
$_SESSION['userid'] = $myrow[0];
[php]
and then a user logs out, i do the following
[php]
$_SESSION['userid'] = ''
session_write_close();
[php]
so, when a user clicks on a link to a page they should only see when logged in, i do the following test
[php]
if (isset($_SESSION['userid']))
{
header('Location: members.php3');
}
[php]
but the logout does not seem to work for some reason? userid still seems to be set after running the logout script, any ideas? am i doing something silly?
View Complete Forum Thread with Replies
Related Forum Messages:
Ways To Assign A Value To A Session Variable.
I am wandering which way to assign a value to a session variable exist. Which of the following examples will work. Example #1: session_start(); session_register("ex"); $ex = 2.0; Example #2: In first.php: session_start(); session_register("ex"); In second.php: $ex = 2.0; Example #3: In first.php: session_start();...
View Replies !
Get Field Using UserID Session
i have this script: Quote$GetEXP = "SELECT userregistration GET CrimeExp WHERE UserID='{$_SESSION['Current_User']}'"; $EXP = $GetEXP["CrimeExp"]; Echo $EXP; but its not echoing it correctly it should display the crimeexp for the user but its not working ... what have i got wrong?
View Replies !
Assign Value To Variable
Is there any way I can use a function to create a variable and assign a value to it? I have a Perl script that returns some LDAP information: sn=Shore givenname=Mike logintime=20041008153445Z logindisabled=FALSE Instead of parsing this text and assigning the values, I was wondering if a function exists where I can pass a variable name and a value, and the variable would be created. ie. somefunc("sn", "Shore") Would create the variable $sn and assign the value "Shore" to it.
View Replies !
Assign To Variable
I am trying to take data from the database and assign it to a variable but i'm not sure how this is the code ive been trying $sql = "SELECT Name FROM Names WHERE Name = 'Peter'"; while($row = @mysql_fetch_array($sql)) { $var == $row['Name']; }
View Replies !
Assign Table Value As A Session??
someone logs into my application - a login function runs from a pinc file. What is suppose to happen is if the username and password match - it is suppose to assign a session to the username - which is being passed from form and to the first and last name which are in the table for the user. Can I assign a session variable to value in a mysql table? It does properly set the cookie I am assigning on the setCookie line but is is not setting any of the three sessions. Here is the function I am using: Code:
View Replies !
$sql = "SELECT * FROM Invites WHERE USERID = " . $_SESSION['userid'];
PHP Code: //This works great $sql = "SELECT * FROM invites WHERE USERID = " . $_SESSION['userid']; //This works as well $sql = "SELECT invites.*, users.email, users.lastlogin FROM invites JOIN users ON invites.email = users.email"; //But when I add the WHERE so I see only the records of the person that is logged in, it does not work. $sql = "SELECT invites.*, users.email, users.lastlogin FROM invites JOIN users ON invites.email = users.email WHERE USERID = " . $_SESSION['userid'];
View Replies !
Is It Possible To Assign A Whole Function Or Block To A Variable ???
Is it possible to assign a whole function or block to a variable ??? eg. <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre> <? if (db_num_rows($qid_p) == 0) { ?> <li>No <? } ?> <? while ($prod = db_fetch_object($qid_p)) { ?> <p><b><a href="product_details.php?id=<?=$prod->id?>"><? pv($prod->name) ?></a></b> <br><? pv($prod->description) ?> <br>$<? pv($prod->price) ?> <br>[<a href="cart_add.php?id=<?=$prod->id?>">+ Add to Cart</a>] <? } ?> How to assign this code to a unique variable ???
View Replies !
Assign Function Output To Variable??
I've found some references to this topic at : http://forums.devshed.com/showthrea...ion+to+variable but it does not seem to be working for me. here's a snippet... <? PHP function listPeople ($getArray) { foreach ( $getArray as $val ) { echo "$val, "; } } $foo = listPeople($splitDirector); ?> The function works, and as you can see i'm simply trying to assign the output of the function to $foo. But instead, the output is written to the page where I assign it... like a print or echo statement, and the variable $foo is empty.
View Replies !
Assign Variable From Database Field
Is there a way to assign a variable from a database field? I'm thinking along the lines of $make = $row_rsList['make']; $model = $row_rsList['model']; then they'll switch out based on my SQL WHERE statement. This valid syntax?
View Replies !
Assign A New Value To A Variable Passed From An Html Form
I'm trying to assign a new value to a variable passed from an html form to a php3 script. I'm using an if statement to evaluate variable 3 to see if it is equal to a specific string, if it is I'm reassigning variable 2 to be variable2+variable 3. if ($question3!="select days") { $question2=$question2+$question3; } This is the statement. It keeps giving me a parse error and I can't seem to find the right documentation to show me how to combine two string variables.
View Replies !
Multi-Dimensional Arrays - Assign Variable
It's a simple question, but I'm just not getting it. I have two files: <?php $precinct = array ( array ( number=>2324, centerlat=>-122.31705665588379, centerlong=>47.710367959402525, etc... <?php include ("precinctdata.php"); $filename = $_GET['id']; $number = $precinct[filename-1][number]; etc... I want to assign the value of "2324" to the variable $number. I've done this with arrays that start with number=>1, 2, 3, etc., but not successfully with specific values. What am I missing?
View Replies !
Assign MySQL Function Result To PHP Variable
I know to use: mysql_fetch_row($result) to convert a row from a SQL query result set into an array for use with PHP. but in the case of SQL queries that return one value, such as calls to MySQL functions, is there another PHP mysql api function I should use. For example, right now I use a "workaround" technique from PHPBuilder: $result=mysql_query("SELECT COUNT(*) FROM tablename"); list($numrows)=mysql_fetch_row($result); Rather than using this "workaround" code is there a way to simply assign the result of the MySQL function query to a variable. $result=mysql_query("SELECT COUNT(*) FROM tablename"); $numrows=mysteryfunction($result);
View Replies !
Assign Variable To A Block Of Html Code
Is it possible to assign variable to a block of html code? Something like this : $myblokvar = "<table width="487" border="0" cellspacing="0" cellpadding="0"> <tr> <td><table width="487" border="0" cellspacing="0" cellpadding="0"> <tr> <td><img src="images/bartitle_login.gif " alt="Login" width="475"...
View Replies !
Assign Variable Name As Variable
I want to be able to create a foreach loop that will go through all the intended POST variables and then assign it as a standard variable. For example, I want to have $username = $_POST['username'] without even knowing username exists in the context of the foreach loop. Code:
View Replies !
Set The Session Variable To Read The Session Variable In The Next Page.
I have a PHP web app, that runs with Register global off. It sets $_SESSION variables that are used in other pages. The script works fine on my server that runs Apache2 and PHP 5.0.1. But when I move the scrip to my hosting company that runs , IIS and PHP5.0.2, they don't work. It seems that its not able to set the session variable to read the session variable in the next page. cvWhat should I be checking ? Has anybody faces this situation before ?
View Replies !
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.
View Replies !
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?
View Replies !
Losing Session Data - Setting A Session Variable
What I have basicaly established for myself is that when setting a session variable, and then redirecting or going to another page, that the data is lost. How can I stop this from happening? I'm sure session data would not normally disappear or would it?
View Replies !
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.
View Replies !
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 Replies !
Create Session Then Store A Session Variable
I use the following code to create session then store a session variable called query and then redirect to another page called insertaccount.php where i wish to use the session value query. when i get to insertaccount.php the session variable query does not exist.can any one tell me why this is. page1.php <php? session_start(); $_SESSION['query'] = $query; header("Location: http://127.0.0.1/signup/insertaccount.php"); ?> insertaccount.php //inside <?php session_start(); $sql_query = $_SESSION['query']; ?>
View Replies !
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:
View Replies !
Creating A UserID
I want to create an external script file that stores my user ID & password to access mySQL. Is this the safest way to protect my info? having the main page call for the my personal info? is there a way to create a php function using an external script? How would I go about?
View Replies !
Network UserID
Trying to build a dept website. Is there a way to get the network login id(the corporate network) of the users visiting my page? I plan to use this to control site access and hate to ask them to do a logon again. The OS is XP Pro.
View Replies !
Userid On All Pages
i m designing a website wherein user first login to the site. once he login he can access the other pages. i want the username to be displayed on all the pages till he logouts. but i m getting the username displayed only on the second page. Code:
View Replies !
Generate Random Userid
I'm trying to do some marketing research and I am looking to track which pages users go to and where they leave. On every link I have something like this <a href='somepage.php?pageid=about_us?userid=$randuserid and follow the user on the site. How would I generate $randuserid = (Random Number).
View Replies !
Sql Query To Show Only One Userid That Will Add
i have a query line, so it's going to add all the users who have submitted results into a table. how do i change this so only one userid will add? currently is userid 3 has added 4 results into tippingresults they will have 3 rows in tippingtable, i want just one row... how can this be done? Code:
View Replies !
Login, Select UserID On Log On
I'm trying to make a login system the when someone logs on the url will be like filename.php?memberID=1, so it echo's their information on the page. How do i select the user ID from the User name and Password if they are entered correctly.
View Replies !
UserID And Password Problem..
I have Installed XAMPP for localserver. So i have installed some PHP script. Now there are some login procedure is there. Where i put the UserId and password , the Login procedure doesn't working. it returns back to the same page.i know the UserId and Password is correct. Now when i upload the same PHP script To my WebServer the same userID and password is working. i can now Login to the system. whats the problem?
View Replies !
SESSION Variable Site Without Using A Session.
I am having a problem. Currently on my site I have a user_id that is a SESSION variable. I am using a session variable so that I can call the users information from any page because the variable will always be remembered. I was curious if there is a different way to do this without using a session. Would that be considered a class? I need to have the site remember the users id throughtout the site without using a session.
View Replies !
Regular Expressions To Get Userid In An Html File
I would like to parse an html file containing several link with userid in order to retrieve all userid and put them into an array. Here is what my html looks like : ....r"><a href="userprofile.php?userid=346047" ><img s... And want : array("346047", ...); I am playing with RegEx without success. Do you have an idea ?
View Replies !
Join Two Table That Have UsedID And Msepcdp Userid In Common.
I used this SQl query to join two table that have usedID and msepcdp userid in common. "SELECT * FROM users,msepcdp WHERE users.ID = msepcdp.userid AND msepcdp.type LIKE 'music" Wheni i try to echo the the fields using: "$query2 = "SELECT * FROM users,msepcdp WHERE users.ID = msepcdp.userid AND msepcdp.type LIKE 'music'"; Code:
View Replies !
SESSIONS - Pull Information From The Db Solely Based On The Userid Field In The Database.
i have a user management system which i want to pull information from the db solely based on the userid field in the database. When the user logs in a session is created which looks as follows: PHP Code: session_register('userid'); $_SESSION['userid'] = $userid; session_register('first_name'); $_SESSION['first_name'] = $first_name; session_register('last_name'); $_SESSION['last_name'] = $last_name; what would be the code to pull the content from the db? i'm thinking it would be something like the following, but i'm not sure as this is the first time i have ever used sessions. PHP Code: if($_SESSION['userid'] == $userid;{ $query = "SELECT * FROM `users"; $result = mysql_query($query); $rows = mysql_num_rows($result); ...............
View Replies !
Get The Message: "no Session!" Can I Echo The Value Of The Session Variable?
I cant set a session. I do like this: $unik = "something"; session_start(); session_register('unik'); on another page iI do like this: session_start(); if (!isset($HTTP_SESSION_VARS['unik'])) { echo " no session!"; } else { echo " session ok!"; } Here I just get the message: "no session!" Can I echo the value of the session variable 'unik' just by doing like this? $unik = $HTTP_SESSION_VARS['unik']; echo "$unik";
View Replies !
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.
View Replies !
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....
View Replies !
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(); }
View Replies !
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:
View Replies !
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
View Replies !
|