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










0















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');






?>









share|improve this question
























  • 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















0















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');






?>









share|improve this question
























  • 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













0












0








0








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');






?>









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 (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

















  • 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
















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












1 Answer
1






active

oldest

votes


















0














$_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 ?






share|improve this answer























  • 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










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
);



);













draft saved

draft discarded


















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









0














$_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 ?






share|improve this answer























  • 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















0














$_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 ?






share|improve this answer























  • 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













0












0








0







$_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 ?






share|improve this answer













$_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 ?







share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme