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 Complete Forum Thread with Replies
Related Forum Messages:
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 Replies !
More Ways To Define An Variable
I asked this question before but I forgot/ran into some problems. There are more ways to defina an variable: 1. $var = 'value' Notice the ' 2. $var = "value"; Notice the " and what is the third? Something like /"value/" I think.
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 !
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 !
"Remember Me(session)" Several Ways! Which One?
I use to use a login script which would do: session_set_cookie_params($thirdyDays); session_start(); I would do this when the login was successful and then, it would remember the session info for 30 days and all i had to do was session_start it. However, it doesn't always work, almost never works in my localhost, it sometimes works in my web server, I tried commenting the session.life_time or whatever, but that didn't help. And you can't always expect the enviornment you're working in to have it commented etc. 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 !
2 Ways
Having a session variable test. Is there a difference between: $test = "string"; or $_session['test'] = "string";
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 !
Best Ways For Mass Mailing
I would like to understand which are the best ways to send bulk mailings like for newsletters and so on ( not spamming, always to receivers who opt-in ). I am not looking for code for now , I have found some very interesting classes and I also have my own scripts, I just want to know all the options available and why one is better of another . So, if have to send just a few copies to, say, less than one hundred people I can use the mail function, If I have to send , say, 20 thousand emails I will have to hire dedicated mail servers, but what if I have to deliver a few hundreds emails ? What is usually the max limit using my shared hosting before moving to a dedicated mail server ? What is the best way ? maybe splitting the delivery in batches using the default mail ( sendmail ) or by SMTP ?
View Replies !
Gettext Vs Custom Ways
Does anyone here have experience with PHP gettext functions? I'd like to know how they work better. Also, is gettext more efficient than serializing the language strings into language files and unserializing them at each request? I found this on Google saying that some guy sped up gettext, but I have no idea how fast it was in the first place: I was planning to just unserialize the appropriate language file at each page request and then use the strings kind of like phpBB does (language strings are assigned to constants and the needed strings are assigned to the template engine per-page). It seems to me that this would be easier to deal with than using _() and an English string to encode every string before sending it to the template engine.
View Replies !
3 Ways: Reading Files
readfile(), fpassthru(), and file() are the 3 ways to read the WHOLE file. Why so many methods, redundant? I trying to find the advantage.
View Replies !
Connection Security Both Ways
Supposed a visitor enters a secure (https) area of a site. They submit sensitive data which upon reaching the server is determined to have some problems. If some of that sensitive data is included in the output as values in a form when the page reloads to specify the problem, would the data be transmitted as securely to the visitor as it was to the server from the visitor's browser?
View Replies !
Ways Of Displaying Text!!
I have a recordset i am displaying on my page such as this is movie one this is movie two this is movie three but these are to long to display on the page so how do i make it so it displays like this this is mo... this is mo... this is mo...
View Replies !
Ways To Optimize Html Pages
I know there are ways to optimize html pages with all of the software out there. But does anyone know if they make one that will crunch PHP without changing the code? Everytime I edit php code in my WYSIWYG editor it leaves spaces that aren't needed in the coding.
View Replies !
XSS: Ways To Disguise JavaScript Tags?
I'm trying to figure out how my users may use (or better misuse) the input fields of my site to to insert JavaScript. I'm already replacing all occurencies of "script" in every input field but I wanted to know if anybody here ever stumbled upon a trick to disguise the <script> tag?
View Replies !
Know Any Slick Ways To Build A String From Array?
I have this arr $months = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); and I would like to take this array and build a string of the form "<option value="1">January</option> <option value="2">February</option> <option value="3">March</option> ... December</option>" Does anyone know a slick way to get to the above string from the given array? I'm using PHP 4.
View Replies !
Better Ways Compare Strings: Exact Matches
I'm creating a lot of arrays. Some of the arrays carry words that get duplicated... For example: $aCities = {"Durham", "Raleigh", "Raleigh-Durham", "Salem", "Winston", "Winston-Salem" } I've been using stristr alot but that ends up meaning that I must take the arrays out of alphabetical order and in the end it complicates things on my part. I'll comparing it to the strcmp() function right at the moment but I ran into some difficulties with strcmp() a couple nights ago, along the lines of having to convert the strings in the array lower-case (all my arrays are currently stored in a ucwords() format). The dashes in the names also present a bit of a problem. The way I'm currently doing the comparisons... function GetCity($sSearchThis) { $aAllCities = GetAllCitiesArray(); // make sure parameter is lowercase $sSearchMe = strtolower($sSearchThis); foreach ($aAllCities as $sThisCity) { if (stristr($sSearchMe, $sThisCity) !== FALSE) { return($sThisCity); } // default to raleigh return("raleigh"); } What's the best way to accomplish this or is there a better way under the following conditions: (1) The item passed in IS a string (not an array). (2) A default string is always returned when no match is found. (3) The alphabetical order of the array must remain alphabetized. (4) The dashes are not required.
View Replies !
Alternate Ways To Pass Information To Scripts
This is one for the PHP-ilk that can sneeze better code than most write. Under Apache, and only under Apache, you can use the following snippet of code to get information passed to the script in a way other than get/post/sessions, which is passed directly after the script name but before the querystring, eg: http://blah.net/index.php/type/value/type/value/?type=value PHP Code:
View Replies !
Recommended Ways Of Passing Parameters To A Function
I have a function like this: Code: function show_categories ($cat_to_show, $number_to_show) { ... function code .....} I call it in this manner: show_categories (1, 20); However, sometimes I may want to show all articles from every category, not just one. What would be a good way to handle this? show_categories (0, 20); // use cat number 0 since we don't have anything with cat 0 show_categories (9999, 20); // use a category number that will definitely not exist show_categories ('ALL', 20); // use a distinct value Or is there a better way?
View Replies !
Ways To Tell If Existing Setup Is SAPI Or Shared Object?
What ways are there to tell if PHP is actually built into an Apache 2 installation or if it's installed as a shared object? I've dropped a file containing phpinfo() on the server I'm looking at, hoping the Server API value would give me a clue, but it just says "Apache 2.0 Filter," and I don't know if Apache filters are required to be one or the other....
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 !
What Are Normal Ways To Scale Up PHP's Default Settings For Growing Traffic?
PHP comes with certain defaults, set in php.ini. Among these, scripts time out after 60 seconds, I think. The default memory limit for a script is, I believe, 8 megs. I assume that when people do large-scale sites with PHP they scale these numbers up. If you have a content management system running every aspect of a large corporate web site, including a database back end that employees use for important, secret, protected information, then I imagine there is quite a lot of processing that might be needed for every request. A limit that I run into all the time is the memory limit. If I get a large amount of info back from the database, and then try to store the return in an array, it is easy to go over the default 8 meg limit.
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 !
|