Add session variables for multiple users2019 Community Moderator ElectionAdd a column with a default value to an existing table in SQL ServerHow to concatenate text from multiple rows into a single text string in SQL server?Inserting multiple rows in a single SQL query?Using group by on multiple columnsHow do servlets work? Instantiation, sessions, shared variables and multithreadingCheck if PHP session has already startedSession-and user informationEmbed PHP in an email to start a session and store variableSession variables reset on the refresh of the page (logging out user)Maintain PHP session between https and http pages
Examples of transfinite towers
Bacteria contamination inside a thermos bottle
Why is a white electrical wire connected to 2 black wires?
What favor did Moody owe Dumbledore?
Do I need life insurance if I can cover my own funeral costs?
Do I need to be arrogant to get ahead?
How to pronounce "I ♥ Huckabees"?
Simplify an interface for flexibly applying rules to periods of time
If I can solve Sudoku, can I solve the Travelling Salesman Problem (TSP)? If so, how?
Encrypting then Base64 Encoding
Four married couples attend a party. Each person shakes hands with every other person, except their own spouse, exactly once. How many handshakes?
Official degrees of earth’s rotation per day
Different outputs for `w`, `who`, `whoami` and `id`
Why one should not leave fingerprints on bulbs and plugs?
Why did it take so long to abandon sail after steamships were demonstrated?
New passport but visa is in old (lost) passport
et qui - how do you really understand that kind of phraseology?
Custom alignment for GeoMarkers
Do the common programs (for example: "ls", "cat") in Linux and BSD come from the same source code?
Python if-else code style for reduced code for rounding floats
Is there a symmetric-key algorithm which we can use for creating a signature?
Book: Young man exiled to a penal colony, helps to lead revolution
As a new Ubuntu desktop 18.04 LTS user, do I need to use ufw for a firewall or is iptables sufficient?
Math equation in non italic font
Add session variables for multiple users
2019 Community Moderator ElectionAdd a column with a default value to an existing table in SQL ServerHow to concatenate text from multiple rows into a single text string in SQL server?Inserting multiple rows in a single SQL query?Using group by on multiple columnsHow do servlets work? Instantiation, sessions, shared variables and multithreadingCheck if PHP session has already startedSession-and user informationEmbed PHP in an email to start a session and store variableSession variables reset on the refresh of the page (logging out user)Maintain PHP session between https and http pages
I have a login page which directs to a process_login page which in turn directs the user to the appropriate page(i.e. i have a SQL table with 3 users - admin, student, instructor)
The code below achieves that but i am having difficulty when i try to add session variables. I have commented out the code i was trying when adding the session variables.
What would be the best way to add session variables to this?
process_login
<?php
//session_start();
include('connect.php');
$name =$_POST['userlogin'];
$pass = $_POST['userpw'];
//$_SESSION['currentuser'] = $name;
$loginsql = "SELECT * FROM VLE_users WHERE name = '$name' AND passw = '$pass' ";
$result = $conn -> query ($loginsql);
if(!$result)
echo $conn ->error;
//$num = $result -> num_rows;
//if($num>0){
while ($row = $result->fetch_assoc())
//$userid =$row ['id'];
//$S_SESSION['userid'] = $userid;
if($row['type'] == 3)
header('Location:index2.php');
elseif($row['type'] == 2)
header('Location: studentpage.php');
elseif($row['type']==1)
header('Location:admin_dash.php');
else
header('Location:index.php');
?>
php sql authentication login session-variables
add a comment |
I have a login page which directs to a process_login page which in turn directs the user to the appropriate page(i.e. i have a SQL table with 3 users - admin, student, instructor)
The code below achieves that but i am having difficulty when i try to add session variables. I have commented out the code i was trying when adding the session variables.
What would be the best way to add session variables to this?
process_login
<?php
//session_start();
include('connect.php');
$name =$_POST['userlogin'];
$pass = $_POST['userpw'];
//$_SESSION['currentuser'] = $name;
$loginsql = "SELECT * FROM VLE_users WHERE name = '$name' AND passw = '$pass' ";
$result = $conn -> query ($loginsql);
if(!$result)
echo $conn ->error;
//$num = $result -> num_rows;
//if($num>0){
while ($row = $result->fetch_assoc())
//$userid =$row ['id'];
//$S_SESSION['userid'] = $userid;
if($row['type'] == 3)
header('Location:index2.php');
elseif($row['type'] == 2)
header('Location: studentpage.php');
elseif($row['type']==1)
header('Location:admin_dash.php');
else
header('Location:index.php');
?>
php sql authentication login session-variables
What kind of trouble are you having? Your first 2 uses appear to be correct and the 3rd one has a typo (extraS
in the name).
– Dave
Mar 7 at 15:42
whe i uncomment that code, nothing works, cant login to any page.
– Drewsh
Mar 7 at 15:45
If you fix the typo on the 3rd instance and uncomment them all do things work? If you haven't already enable error reporting so you can see what is going onini_set('display_errors','1'); ini_set('display_startup_errors','1'); error_reporting(E_ALL);
– Dave
Mar 7 at 15:55
add a comment |
I have a login page which directs to a process_login page which in turn directs the user to the appropriate page(i.e. i have a SQL table with 3 users - admin, student, instructor)
The code below achieves that but i am having difficulty when i try to add session variables. I have commented out the code i was trying when adding the session variables.
What would be the best way to add session variables to this?
process_login
<?php
//session_start();
include('connect.php');
$name =$_POST['userlogin'];
$pass = $_POST['userpw'];
//$_SESSION['currentuser'] = $name;
$loginsql = "SELECT * FROM VLE_users WHERE name = '$name' AND passw = '$pass' ";
$result = $conn -> query ($loginsql);
if(!$result)
echo $conn ->error;
//$num = $result -> num_rows;
//if($num>0){
while ($row = $result->fetch_assoc())
//$userid =$row ['id'];
//$S_SESSION['userid'] = $userid;
if($row['type'] == 3)
header('Location:index2.php');
elseif($row['type'] == 2)
header('Location: studentpage.php');
elseif($row['type']==1)
header('Location:admin_dash.php');
else
header('Location:index.php');
?>
php sql authentication login session-variables
I have a login page which directs to a process_login page which in turn directs the user to the appropriate page(i.e. i have a SQL table with 3 users - admin, student, instructor)
The code below achieves that but i am having difficulty when i try to add session variables. I have commented out the code i was trying when adding the session variables.
What would be the best way to add session variables to this?
process_login
<?php
//session_start();
include('connect.php');
$name =$_POST['userlogin'];
$pass = $_POST['userpw'];
//$_SESSION['currentuser'] = $name;
$loginsql = "SELECT * FROM VLE_users WHERE name = '$name' AND passw = '$pass' ";
$result = $conn -> query ($loginsql);
if(!$result)
echo $conn ->error;
//$num = $result -> num_rows;
//if($num>0){
while ($row = $result->fetch_assoc())
//$userid =$row ['id'];
//$S_SESSION['userid'] = $userid;
if($row['type'] == 3)
header('Location:index2.php');
elseif($row['type'] == 2)
header('Location: studentpage.php');
elseif($row['type']==1)
header('Location:admin_dash.php');
else
header('Location:index.php');
?>
php sql authentication login session-variables
php sql authentication login session-variables
edited Mar 7 at 15:47
Toby Allen
8,797863117
8,797863117
asked Mar 7 at 15:39
DrewshDrewsh
1
1
What kind of trouble are you having? Your first 2 uses appear to be correct and the 3rd one has a typo (extraS
in the name).
– Dave
Mar 7 at 15:42
whe i uncomment that code, nothing works, cant login to any page.
– Drewsh
Mar 7 at 15:45
If you fix the typo on the 3rd instance and uncomment them all do things work? If you haven't already enable error reporting so you can see what is going onini_set('display_errors','1'); ini_set('display_startup_errors','1'); error_reporting(E_ALL);
– Dave
Mar 7 at 15:55
add a comment |
What kind of trouble are you having? Your first 2 uses appear to be correct and the 3rd one has a typo (extraS
in the name).
– Dave
Mar 7 at 15:42
whe i uncomment that code, nothing works, cant login to any page.
– Drewsh
Mar 7 at 15:45
If you fix the typo on the 3rd instance and uncomment them all do things work? If you haven't already enable error reporting so you can see what is going onini_set('display_errors','1'); ini_set('display_startup_errors','1'); error_reporting(E_ALL);
– Dave
Mar 7 at 15:55
What kind of trouble are you having? Your first 2 uses appear to be correct and the 3rd one has a typo (extra
S
in the name).– Dave
Mar 7 at 15:42
What kind of trouble are you having? Your first 2 uses appear to be correct and the 3rd one has a typo (extra
S
in the name).– Dave
Mar 7 at 15:42
whe i uncomment that code, nothing works, cant login to any page.
– Drewsh
Mar 7 at 15:45
whe i uncomment that code, nothing works, cant login to any page.
– Drewsh
Mar 7 at 15:45
If you fix the typo on the 3rd instance and uncomment them all do things work? If you haven't already enable error reporting so you can see what is going on
ini_set('display_errors','1'); ini_set('display_startup_errors','1'); error_reporting(E_ALL);
– Dave
Mar 7 at 15:55
If you fix the typo on the 3rd instance and uncomment them all do things work? If you haven't already enable error reporting so you can see what is going on
ini_set('display_errors','1'); ini_set('display_startup_errors','1'); error_reporting(E_ALL);
– Dave
Mar 7 at 15:55
add a comment |
1 Answer
1
active
oldest
votes
$_SESSION["currentuser"] = $name;
Should work just fine
$S_SESSION['userid'] = $userid;
Should be :
$_SESSION['userid'] = $userid;
did you make a typo there or? And exactly what is the trouble you are experiencing? what doesn't work ?
yes typo. when i uncomment the code i cant login to any page
– Drewsh
Mar 7 at 15:49
it just takes me back to login page
– Drewsh
Mar 7 at 15:51
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047594%2fadd-session-variables-for-multiple-users%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$_SESSION["currentuser"] = $name;
Should work just fine
$S_SESSION['userid'] = $userid;
Should be :
$_SESSION['userid'] = $userid;
did you make a typo there or? And exactly what is the trouble you are experiencing? what doesn't work ?
yes typo. when i uncomment the code i cant login to any page
– Drewsh
Mar 7 at 15:49
it just takes me back to login page
– Drewsh
Mar 7 at 15:51
add a comment |
$_SESSION["currentuser"] = $name;
Should work just fine
$S_SESSION['userid'] = $userid;
Should be :
$_SESSION['userid'] = $userid;
did you make a typo there or? And exactly what is the trouble you are experiencing? what doesn't work ?
yes typo. when i uncomment the code i cant login to any page
– Drewsh
Mar 7 at 15:49
it just takes me back to login page
– Drewsh
Mar 7 at 15:51
add a comment |
$_SESSION["currentuser"] = $name;
Should work just fine
$S_SESSION['userid'] = $userid;
Should be :
$_SESSION['userid'] = $userid;
did you make a typo there or? And exactly what is the trouble you are experiencing? what doesn't work ?
$_SESSION["currentuser"] = $name;
Should work just fine
$S_SESSION['userid'] = $userid;
Should be :
$_SESSION['userid'] = $userid;
did you make a typo there or? And exactly what is the trouble you are experiencing? what doesn't work ?
answered Mar 7 at 15:43
Delano zuurmanDelano zuurman
8918
8918
yes typo. when i uncomment the code i cant login to any page
– Drewsh
Mar 7 at 15:49
it just takes me back to login page
– Drewsh
Mar 7 at 15:51
add a comment |
yes typo. when i uncomment the code i cant login to any page
– Drewsh
Mar 7 at 15:49
it just takes me back to login page
– Drewsh
Mar 7 at 15:51
yes typo. when i uncomment the code i cant login to any page
– Drewsh
Mar 7 at 15:49
yes typo. when i uncomment the code i cant login to any page
– Drewsh
Mar 7 at 15:49
it just takes me back to login page
– Drewsh
Mar 7 at 15:51
it just takes me back to login page
– Drewsh
Mar 7 at 15:51
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047594%2fadd-session-variables-for-multiple-users%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What kind of trouble are you having? Your first 2 uses appear to be correct and the 3rd one has a typo (extra
S
in the name).– Dave
Mar 7 at 15:42
whe i uncomment that code, nothing works, cant login to any page.
– Drewsh
Mar 7 at 15:45
If you fix the typo on the 3rd instance and uncomment them all do things work? If you haven't already enable error reporting so you can see what is going on
ini_set('display_errors','1'); ini_set('display_startup_errors','1'); error_reporting(E_ALL);
– Dave
Mar 7 at 15:55