How to generate a random session variable in php
i want to generate a random session variable and insert the variable in a mysql record to use later to validate an account set up.
person fills out form to create account and submits; inserts form information in mysql record.
i want the random variable to be inserted from a hidden field and the page sends an email with a link to click on to compare the variable to validate the user.
Not sure how to generate a random session variable and get that to the hidden field value to be inserted with the other form information.
thanks for your help,
Jim Balthrop
To insert the key I would personally do something like...
$key = md5($username . $password . $salt);
Insert that into your MySQL database, then send them a email with it, my next code shows how to activate it.
This is to activate the account.
<?php
$key;
$errors = array();
if(isset($_GET['key']){
$key = $_GET['key'];
$sql = 'SELECT * FROM users WHERE key = \'' . $key '\' LIMIT 1';
$result = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($result)){
$sql2 = 'UPDATE users SET active = 1 WHERE key = \'' . $key '\' LIMIT 1';
$result2 = mysql_query($sql2) or die(mysql_error());
if($result2){
//successfully activated account
else{
//Something Went Wrong!
else{
$errors[] = 'Invaild Key, Please try again!';
else{
$errors[] = 'Invaild Key, Please try again!';
?>
Similar Messages
-
How to set a new session variable?
Hi all,
Can anybody say how to set a new session variable in istore?Hi,
you can use either
pageContext.getAttribute(VAR, PageContext.REQUEST_SCOPE);
or
<%@page session="true" %>
session.putValue
session.getValue
Hope this will help.
Thanks
Gurjeet -
Urgent How to generate a random code such as registration code?
I would like to ask that how to generate a random code?
For example, when you register a E-mail account, you need to enter the code for activation. I would like to create a java Bean to do this job. Would you help me?In fact, I would like to set a 10 digi codes randomly (such as FH654CS081, MKO624VG9f) for user input when they register the forum account. This random code will be sent to the user's email. User have to input this code to a JSP web site. Also, the code which is inputed by user will be matched with the database. If user input success, the forum account will be activated.
By generating this 10 digi codes, I want to handle this generation by using java bean.
1) Any thing else i need to import ? (such as <% page import="java.......?")
2) Any functions can handle this task?
3) Any example can be my reference?
Thank you very much -
How to generate report with dynamic variable number of columns?
How to generate report with dynamic variable number of columns?
I need to generate a report with varying column names (state names) as follows:
SELECT AK, AL, AR,... FROM States ;
I get these column names from the result of another query.
In order to clarify my question, Please consider following table:
CREATE TABLE TIME_PERIODS (
PERIOD VARCHAR2 (50) PRIMARY KEY
CREATE TABLE STATE_INCOME (
NAME VARCHAR2 (2),
PERIOD VARCHAR2 (50) REFERENCES TIME_PERIODS (PERIOD) ,
INCOME NUMBER (12, 2)
I like to generate a report as follows:
AK CA DE FL ...
PERIOD1 1222.23 2423.20 232.33 345.21
PERIOD2
PERIOD3
Total 433242.23 56744.34 8872.21 2324.23 ...
The TIME_PERIODS.Period and State.Name could change dynamically.
So I can't specify the state name in Select query like
SELECT AK, AL, AR,... FROM
What is the best way to generate this report?SQL> -- test tables and test data:
SQL> CREATE TABLE states
2 (state VARCHAR2 (2))
3 /
Table created.
SQL> INSERT INTO states
2 VALUES ('AK')
3 /
1 row created.
SQL> INSERT INTO states
2 VALUES ('AL')
3 /
1 row created.
SQL> INSERT INTO states
2 VALUES ('AR')
3 /
1 row created.
SQL> INSERT INTO states
2 VALUES ('CA')
3 /
1 row created.
SQL> INSERT INTO states
2 VALUES ('DE')
3 /
1 row created.
SQL> INSERT INTO states
2 VALUES ('FL')
3 /
1 row created.
SQL> CREATE TABLE TIME_PERIODS
2 (PERIOD VARCHAR2 (50) PRIMARY KEY)
3 /
Table created.
SQL> INSERT INTO time_periods
2 VALUES ('PERIOD1')
3 /
1 row created.
SQL> INSERT INTO time_periods
2 VALUES ('PERIOD2')
3 /
1 row created.
SQL> INSERT INTO time_periods
2 VALUES ('PERIOD3')
3 /
1 row created.
SQL> INSERT INTO time_periods
2 VALUES ('PERIOD4')
3 /
1 row created.
SQL> CREATE TABLE STATE_INCOME
2 (NAME VARCHAR2 (2),
3 PERIOD VARCHAR2 (50) REFERENCES TIME_PERIODS (PERIOD),
4 INCOME NUMBER (12, 2))
5 /
Table created.
SQL> INSERT INTO state_income
2 VALUES ('AK', 'PERIOD1', 1222.23)
3 /
1 row created.
SQL> INSERT INTO state_income
2 VALUES ('CA', 'PERIOD1', 2423.20)
3 /
1 row created.
SQL> INSERT INTO state_income
2 VALUES ('DE', 'PERIOD1', 232.33)
3 /
1 row created.
SQL> INSERT INTO state_income
2 VALUES ('FL', 'PERIOD1', 345.21)
3 /
1 row created.
SQL> -- the basic query:
SQL> SELECT SUBSTR (time_periods.period, 1, 10) period,
2 SUM (DECODE (name, 'AK', income)) "AK",
3 SUM (DECODE (name, 'CA', income)) "CA",
4 SUM (DECODE (name, 'DE', income)) "DE",
5 SUM (DECODE (name, 'FL', income)) "FL"
6 FROM state_income, time_periods
7 WHERE time_periods.period = state_income.period (+)
8 AND time_periods.period IN ('PERIOD1','PERIOD2','PERIOD3')
9 GROUP BY ROLLUP (time_periods.period)
10 /
PERIOD AK CA DE FL
PERIOD1 1222.23 2423.2 232.33 345.21
PERIOD2
PERIOD3
1222.23 2423.2 232.33 345.21
SQL> -- package that dynamically executes the query
SQL> -- given variable numbers and values
SQL> -- of states and periods:
SQL> CREATE OR REPLACE PACKAGE package_name
2 AS
3 TYPE cursor_type IS REF CURSOR;
4 PROCEDURE procedure_name
5 (p_periods IN VARCHAR2,
6 p_states IN VARCHAR2,
7 cursor_name IN OUT cursor_type);
8 END package_name;
9 /
Package created.
SQL> CREATE OR REPLACE PACKAGE BODY package_name
2 AS
3 PROCEDURE procedure_name
4 (p_periods IN VARCHAR2,
5 p_states IN VARCHAR2,
6 cursor_name IN OUT cursor_type)
7 IS
8 v_periods VARCHAR2 (1000);
9 v_sql VARCHAR2 (4000);
10 v_states VARCHAR2 (1000) := p_states;
11 BEGIN
12 v_periods := REPLACE (p_periods, ',', ''',''');
13 v_sql := 'SELECT SUBSTR(time_periods.period,1,10) period';
14 WHILE LENGTH (v_states) > 1
15 LOOP
16 v_sql := v_sql
17 || ',SUM(DECODE(name,'''
18 || SUBSTR (v_states,1,2) || ''',income)) "' || SUBSTR (v_states,1,2)
19 || '"';
20 v_states := LTRIM (SUBSTR (v_states, 3), ',');
21 END LOOP;
22 v_sql := v_sql
23 || 'FROM state_income, time_periods
24 WHERE time_periods.period = state_income.period (+)
25 AND time_periods.period IN (''' || v_periods || ''')
26 GROUP BY ROLLUP (time_periods.period)';
27 OPEN cursor_name FOR v_sql;
28 END procedure_name;
29 END package_name;
30 /
Package body created.
SQL> -- sample executions from SQL:
SQL> VARIABLE g_ref REFCURSOR
SQL> EXEC package_name.procedure_name ('PERIOD1,PERIOD2,PERIOD3','AK,CA,DE,FL', :g_ref)
PL/SQL procedure successfully completed.
SQL> PRINT g_ref
PERIOD AK CA DE FL
PERIOD1 1222.23 2423.2 232.33 345.21
PERIOD2
PERIOD3
1222.23 2423.2 232.33 345.21
SQL> EXEC package_name.procedure_name ('PERIOD1,PERIOD2','AK,AL,AR', :g_ref)
PL/SQL procedure successfully completed.
SQL> PRINT g_ref
PERIOD AK AL AR
PERIOD1 1222.23
PERIOD2
1222.23
SQL> -- sample execution from PL/SQL block
SQL> -- using parameters derived from processing
SQL> -- cursors containing results of other queries:
SQL> DECLARE
2 CURSOR c_period
3 IS
4 SELECT period
5 FROM time_periods;
6 v_periods VARCHAR2 (1000);
7 v_delimiter VARCHAR2 (1) := NULL;
8 CURSOR c_states
9 IS
10 SELECT state
11 FROM states;
12 v_states VARCHAR2 (1000);
13 BEGIN
14 FOR r_period IN c_period
15 LOOP
16 v_periods := v_periods || v_delimiter || r_period.period;
17 v_delimiter := ',';
18 END LOOP;
19 v_delimiter := NULL;
20 FOR r_states IN c_states
21 LOOP
22 v_states := v_states || v_delimiter || r_states.state;
23 v_delimiter := ',';
24 END LOOP;
25 package_name.procedure_name (v_periods, v_states, :g_ref);
26 END;
27 /
PL/SQL procedure successfully completed.
SQL> PRINT g_ref
PERIOD AK AL AR CA DE FL
PERIOD1 1222.23 2423.2 232.33 345.21
PERIOD2
PERIOD3
PERIOD4
1222.23 2423.2 232.33 345.21 -
How do I insert a session variable into a record?
I can’t figure out how to insert the value passed by a
session variable into a record.
I have a form I want to use to insert a record. I pass
session variables to this page and want to insert one of them into
the record. The session information is:
session_start();
$_SESSION['usename'] = $_POST['username'];
$idvar = $_SESSION['id'];
$_SESSION[‘id’] is the user_id that I want to
insert into the record.
I know $idvar is getting to the page with the form because I
can echo it.
The insert code looks like this:
if ((isset($_POST["MM_insert"])) &&
($_POST["MM_insert"] == "register")) {
$insertSQL = sprintf("INSERT INTO h_genres (user_id,
username, contrib_to, Advertising, Annual_Reports, Leader_Content,
Member_Content, Brochures) VALUES (%s, %s, %s, %s, %s, %s, %s,
%s)",
GetSQLValueString($_POST['user_id'], "int"),
GetSQLValueString($_POST['username'], "text"),
GetSQLValueString($_POST['contrib_to'], "text"),
GetSQLValueString(isset($_POST['Advertising']) ? "true" :
"", "defined","'Y'","'N'"),
GetSQLValueString(isset($_POST['Annual_Reports']) ? "true" :
"", "defined","'Y'","'N'"),
GetSQLValueString(isset($_POST['Leader_Content']) ? "true" :
"", "defined","'Y'","'N'"),
GetSQLValueString(isset($_POST['Member_Content']) ? "true" :
"", "defined","'Y'","'N'"),
GetSQLValueString(isset($_POST['Brochures']) ? "true" : "",
"defined","'Y'","'N'"));
mysql_select_db($database_hauw, $hauw);
$Result1 = mysql_query($insertSQL, $hauw) or
die(mysql_error());
I have a hidden field for the user_id:
<input name="user_id" type="hidden" id="user_id" />
I think I need to get the value in $idvar into user_id but I
don’t know how.
Any help is appreciated.awsweb wrote:
> I have a hidden field for the user_id:
> <input name="user_id" type="hidden" id="user_id"
/>
>
> I think I need to get the value in $idvar into user_id
but I don?t know how.
<input name="user_id" type="hidden" id="user_id"
value="<?php echo
$idvar; ?>" />
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/ -
How to generate pseudo random noise(PRN) binary sequence using shift registers?
what is the block diagram to generate pseudo random noise (PRN) binary sequence of 1's and 0's using shift registers
please help
i need 2 submit this project in this weekThis is a fairly simple homework problem. My hints (on the LabVIEW side):
1- look at while loops
2- look at shift registers on while loops with multiple input elements
3-look at the logic components, AND, OR XOR
Look at this wiki article: http://en.wikipedia.org/wiki/Linear_feedback_shift_register
Do the work, you won't learn if someone shows you how it is done! The palette that the previous post points to are of PRN and other "noise generators" but I suspect that is not what you are after.
Know that creating a PRN with a reasonable number of shift register taps produces very pseudo results, as the "random" pattern begins to repeat pretty quickly, thereby making it not a truly random number.
When you have an attempt that is sort of working and want additional suggestions, post the code here. We won't do your work, we will help you try to do it, and learn it, yourself.
Putnam
Certified LabVIEW Developer
Senior Test Engineer
Currently using LV 6.1-LabVIEW 2012, RT8.5
LabVIEW Champion -
How to generate n random dates between 2 time periods
Hi,
I'm trying to write a method that generates n random dates between 2
time periods. For example, lets say I want to generate n random dates
between Jan 1 2003 and Jan 15 2003. I'm not sure how to go about
doing the random date generation. Can someone provide some direction
on how to do this?
The method signature should look like this.
public String[] generateRandomDates(String date1,String date2,int n){
// date1 and date2 come in the format of mmddyyyyhh24miss.
// n is the number of random dates to generate.
return dateArray;
Thanks.
Peterfirst take a look at the API concerning a source of randomness (Random might be a good guess), then take a look at stuff concerning dates (Date might be cool, maybe you will find some links from there).
Who wrote this stupid assignment? -
How to generate a random number with at least 6 digits?
Hi all,
All is in the question. :-)
I would like to generate a random number but the function "random
number" in Labview isn't accurate enough.
Do you know an algorithm to generate a random number of 6 or more
digit?
Thanks,
PFHi PF,
It's simple. Use 2 random number functions in the same process. Now you
should have 2 distinct random numbers that have the same accuracy. Let's say
LV gives accuracy up to the thousandth (0.XXX), now if you divide one number
by 1000 and then add to the other number you should then have something like
0.XXXXXX. Actually, LV random number function can give up to about 17 digits
(decimal). If you are looking for more digits (>17 digits), the idea above
may not work, then the last thing you may want try is to generate two or
three random numbers then convert all these decimal numbers to fractional
strings chop off the 0 and dot then concatinate them together. After all
it's still a random number. How many digits do you want to get? Make sure
the indicators acce
pt that many digits?
Good luck
Louis.
P-F wrote in message
news:[email protected]..
> Hi all,
>
> All is in the question. :-)
>
> I would like to generate a random number but the function "random
> number" in Labview isn't accurate enough.
>
> Do you know an algorithm to generate a random number of 6 or more
> digit?
>
> Thanks,
>
> PF -
How to generate n random dates
Can anyone help me in generating Random dates, i want to generate 100 random dates in yyyy-mm-dd format.
I've tried this, but will appreciate any neat solutions...
public static void main(String arg[]) {
int no = 0;
while (no < 100) {
// Year
int yylower = 1970; // your lower integer value
int yyupper = 2000; // the larger one of your two integers
double rand = Math.random();
int yyresult = yylower + (int) ( (yyupper - yylower) * rand);
// Month
int mmlower = 1; // your lower integer value
int mmupper = 12; // the larger one of your two integers
rand = Math.random();
int mmresult = mmlower + (int) ( (mmupper - mmlower) * rand);
// Month
int ddlower = 1; // your lower integer value
int ddupper = 29; // the larger one of your two integers
rand = Math.random();
int ddresult = ddlower + (int) ( (ddupper - ddlower) * rand);
System.out.println(yyresult + "-" + mmresult + "-" + ddresult);
no++;
} -
I am new to web applications, but for what I need is to know
how to use session variables. When a user logins I want thier
information stored so when they visit my account they are able to
see thier information and not someone elses. Any help should be in
PHP format. Thank you in advance.prashi123 wrote:
> I am new to web applications, but for what I need is to
know how to use session
> variables. When a user logins I want thier information
stored so when they
> visit my account they are able to see thier information
and not someone elses.
> Any help should be in PHP format. Thank you in advance.
http://www.php.net/manual/en/features.sessions.php
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/ -
Creating a session variable with PHP
Can anyone offer me a PHP script that creates a session
variable? The Dreamweaver CS3 Help documentation offers coding
samples for ColdFusion and ASP but not for PHP. I tried this
without success:
"$_SESSION['usermail']= $_POST['sub_email'];" in which I am
trying to capture an email address from a form and save it to use
in a confirmation email to a new subscriber. Any help would be
sincerely appreciated.
[email protected]I use this -
<?php
if (!isset($_SESSION)) {
session_start();
?>
at the top of the page, and then this within the code block
where you are
processing the form's data -
$_SESSION['usermail']= $_POST['sub_email'];
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go
- DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs,
Tutorials & Resources
==================
"Jugdish" <[email protected]> wrote in
message
news:gb8aov$691$[email protected]..
> Can anyone offer me a PHP script that creates a session
variable? The
> Dreamweaver CS3 Help documentation offers coding samples
for ColdFusion
> and ASP
> but not for PHP. I tried this without success:
> "$_SESSION['usermail']= $_POST['sub_email'];" in which I
am trying to
> capture
> an email address from a form and save it to use in a
confirmation email to
> a
> new subscriber. Any help would be sincerely appreciated.
> [email protected]
> -
Accessing session variables with php
I am trying to access the session variable $_SESSION['MM_Username'] in one of my php pages, but it is somehow showing empty (i.e it does not contain the username that was entered during login).
I checked and confirmed that my login.php function is properly setting the MM_Username session variable by echoing it from the login function.
So why can't I read it from another php file in the same session? Do I need to do something else before the session variables can
be properly read from any php file in the same session? Any help would be appreciated.Here is a test code I am using to access the session variable $_SESSION['MM_username'] from the php page test.php. But it is not working.
I get an empty string all the time for $username. Can any one see something wrong with this code?
<?php require_once('Connections/MyTestingConn.php'); ?>
<?php session_start(); ?>
<?php
$username = "-1";
if (isset($_SESSION['MM_username'])) {
$username = $_SESSION['MM_username'];
echo $username;
else
echo "Eror: can not access session variable";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
</head>
<body>
</body>
</html> -
Passing Session Variable from PHP to Applet
I'm trying to pass a session variable from a PHP script to a third party applet. The applet needs to accept the variable as a string into a parameter. I think the htnl has to be dynamically created to turn the session variable into a string for the parameter value. Any suggestions ?
This is really a PHP question. You might get better results on a PHP forum.
-
How to generate a random number within a specified tolerance and control that tolerance.
I am trying to simulate data without using a DAQ device by using a random number generator and I want to be able to control the "range" of the random number generated though. On the front pannel, the user would be able to input a nominal number, and the random number generator would generate numbers within plus or minus .003 of that nominal number. The data would then be plotted on a graph. Anyone know how to do this? Or if it's even possible?
Just for information sake, the random number is supposed to look like thickness measurements, that's why I want to simulate plus and minus .003 because the data could be thinner or thicker than the nominal.
Thanks in advance!!
Solved!
Go to Solution.You can create a random number with a gaussian probability profile using two equal distributed (0...1) random numbers and applying the Box Muller transform.
I wrote one many years ago, her it is. (LabVIEW 8.0).
Message Edited by altenbach on 04-12-2010 09:13 PM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
BoxMuller.vi 10 KB -
How to generate unique random numbers
Hi All,
I am wondering whether there is already a random library or built-in function available in Java to produce some random numbers between certain ranges that are not repetitive. Let's look at a common examples as follows:
Random diceRoller = new Random();
for (int i = 0; i < 10; i++) {
int roll = diceRoller.nextInt(6) + 1;
System.out.println(roll);
}My understanding from this approach is that it allows the same number to be repeated over and over again. However, I would like to find out how to continue generating random numbers from remaining ones that haven't been generated earlier.
Using the above example to illustrate my intention:
1st random number generated - possibility of 1 - 6 showed up. Say 5 is picked.
2nd random number generated - possibility of 1, 2, 3, 4, 6 only. Say 2 is picked.
3rd random number generated - possibility of 1, 3, 4, 6 available. Say 1 is picked.
4th random number generated - possibility of 3, 4, 6 left. Say 6 is picked.
5th random number generated - possibility of 3, 4 remains. Say 4 is picked.
Any assistance would be much appreciated.
Many thanks,
Jackhtran_888 wrote:
Hi All,
I am wondering whether there is already a random library or built-in function available in Java to produce some random numbers between certain ranges that are not repetitive. Let's look at a common examples as follows:
Random diceRoller = new Random();
for (int i = 0; i < 10; i++) {
int roll = diceRoller.nextInt(6) + 1;
System.out.println(roll);
}My understanding from this approach is that it allows the same number to be repeated over and over again. However, I would like to find out how to continue generating random numbers from remaining ones that haven't been generated earlier.
Using the above example to illustrate my intention:
1st random number generated - possibility of 1 - 6 showed up. Say 5 is picked.
2nd random number generated - possibility of 1, 2, 3, 4, 6 only. Say 2 is picked.
3rd random number generated - possibility of 1, 3, 4, 6 available. Say 1 is picked.
4th random number generated - possibility of 3, 4, 6 left. Say 6 is picked.
5th random number generated - possibility of 3, 4 remains. Say 4 is picked.
Any assistance would be much appreciated.If it is your school assignment then you have the answer above (List & the lists length).
(You might want to look at Collections)
Maybe you are looking for
-
Battery Serial Number Report For Laptops?
Does anyone know if there is a way to get a report of the battery serial number via ARD 3? Chris H. G5 Desktop Mac OS X (10.4.7)
-
How to create new java objects in native methods?
Hello, Is it possible to create java objects and return the same to the java code from a native method? Also is it possible to pass java objects other than String objects (for example, Vector objects) as parameters to native methods and is it possibl
-
Working with target groups in ChaRM?
Has really nobody worked with transport groups in ChaRM??
-
How do I get my apps all on the one screen.
I want all my apps icons to appear on the one screen, without scrolling to the right, I have put the into sub-categories.
-
Cannot load Adobe Pro X - ??
I have just loaded CS6 and noticed Adobe Pro X isn't listed, so I tried to reintall with the CD and continue to receive the following error message: (NOTE: I also tried th deactivation instructions and that produced nothing....Help!!??) Exit Code: 6