Webmasterpals  

Go Back   Webmasterpals > Webmasterpals Network > PHP Login Script v2.0

Reply
 
Thread Tools Display Modes
  #1  
Old 02-18-2012, 05:40 PM
polarexpress polarexpress is offline
Senior Member
 
Join Date: Dec 2011
Posts: 181
polarexpress is on a distinguished road
Smile How to redirect the users to their id specific setting pages after updating profile?

How to redirect the users to their id specific setting pages like

mysettings.php?id=1
mysettings.php?id=2
mysettings.php?id=3

after updating the profile or password there provided that the users are redirected to their id specific landing pages where they can navigate through the following pages / links dynamically as

myaccount.php?id=1
mysettings.php?id=1
admin.php?id=1 (Applicable for admin level only)
logout.php

myaccount.php?id=2
mysettings.php?id=2
admin.php?id=2 (Applicable for admin level only)
logout.php

myaccount.php?id=3
mysettings.php?id=3
admin.php?id=3 (Applicable for admin level only)
logout.php

and so on?
Reply With Quote

DirTimes Web Directory - Premium General web directory of quality websites. Submit today!

Premium Web Directory - Premium general web directory. Submit your site for Inclusion

  #2  
Old 02-18-2012, 11:41 PM
Wombat76 Wombat76 is offline
Senior Member
 
Join Date: Mar 2011
Location: UK
Posts: 1,060
Wombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond repute
Default Re: How to redirect the users to their id specific setting pages after updating profi

Just replace the numbers with $_SESSION['user_id'] and use the syntax (in PHP):

Code:
header ("Location: mysettings.php?id='".$_SESSION['user_id']."'");
Replace mysettings.php with myaccount.php, admin.php as required.
Reply With Quote
  #3  
Old 02-18-2012, 11:47 PM
Wombat76 Wombat76 is offline
Senior Member
 
Join Date: Mar 2011
Location: UK
Posts: 1,060
Wombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond repute
Default Re: How to redirect the users to their id specific setting pages after updating profi

Or, if the user should click a link (in HTML):

Code:
<a href='mysettings.php?id="<?php echo $_SESSION['user_id']; ?>"'>LINK</a>
Reply With Quote
  #4  
Old 02-19-2012, 01:59 AM
weekendrockstar weekendrockstar is offline
Member
 
Join Date: Feb 2012
Posts: 74
weekendrockstar is on a distinguished road
Default Re: How to redirect the users to their id specific setting pages after updating profi

Well if they are logged in you shouldn't have to include user_id in the link because as long as they page they are going to makes use of the SESSION user_id it will get it from the session and wouldn't need to be passed along. You would only need to pass along an id if someone were viewing another person's page then you'd want to pass along the id. Or you'd want to pass along a user's idea if the page they're going to doesn't make use of the session information.
Reply With Quote
  #5  
Old 02-19-2012, 06:02 AM
polarexpress polarexpress is offline
Senior Member
 
Join Date: Dec 2011
Posts: 181
polarexpress is on a distinguished road
Default Re: How to redirect the users to their id specific setting pages after updating profi

I guess none of you has understood my question.

The users can already navigate through pages dynamically linked with one another based on their ids stored in database during the login session when they are redirected to their landing / account page after successful login.

An example of such navigation of a user whose id is 1 is as following:

myaccount.php?id=1
mysettings.php?id=1
admin.php?id=1 (Applicable for admin level only)
logout.php

My question is that when the above user shall take attempt to update his profile or password using the profile update form or password update form at mysettings.php?id=1 page, how can he be redirected to same page or link itself (mysettings.php?id=1) after submitting the form?

Presently the user is redirected to mysettings.php from mysettings.php?id=1 after submitting the form at mysettings.php?id=1

How to associate or link the 'SAVE' and 'UPDATE' buttons available at mysettings.php?id=1 with mysettings.php?id=1 itself but not with mysettings.php during the update process.


Thank you,
Reply With Quote
  #6  
Old 02-19-2012, 07:59 AM
polarexpress polarexpress is offline
Senior Member
 
Join Date: Dec 2011
Posts: 181
polarexpress is on a distinguished road
Default Re: How to redirect the users to their id specific setting pages after updating profi

Quote:
Originally Posted by polarexpress View Post
I guess none of you has understood my question.

The users can already navigate through pages dynamically linked with one another based on their ids stored in database during the login session when they are redirected to their landing / account page after successful login.

An example of such navigation of a user whose id is 1 is as following:

myaccount.php?id=1
mysettings.php?id=1
admin.php?id=1 (Applicable for admin level only)
logout.php

My question is that when the above user shall take attempt to update his profile or password using the profile update form or password update form at mysettings.php?id=1 page, how can he be redirected to same page or link itself (mysettings.php?id=1) after submitting the form?

Presently the user is redirected to mysettings.php from mysettings.php?id=1 after submitting the form at mysettings.php?id=1

How to associate or link the 'SAVE' and 'UPDATE' buttons available at mysettings.php?id=1 with mysettings.php?id=1 itself but not with mysettings.php during the update process.

Your guidelines are good for creating user id specific landing pages and dynamic URLs.

The solution is to leave the form action blank

Profile update form:
<form action="" method="post" name="myform" id="myform">

Password update form
<form name="pform" id="pform" method="post" action="">

Thank you,
Reply With Quote
  #7  
Old 02-20-2012, 03:02 PM
Wombat76 Wombat76 is offline
Senior Member
 
Join Date: Mar 2011
Location: UK
Posts: 1,060
Wombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond repute
Default Re: How to redirect the users to their id specific setting pages after updating profi

Quote:
Originally Posted by weekendrockstar View Post
Well if they are logged in you shouldn't have to include user_id in the link because as long as they page they are going to makes use of the SESSION user_id it will get it from the session and wouldn't need to be passed along. You would only need to pass along an id if someone were viewing another person's page then you'd want to pass along the id. Or you'd want to pass along a user's idea if the page they're going to doesn't make use of the session information.
You are exactly right. My bad.
Reply With Quote
  #8  
Old 02-22-2012, 06:13 AM
polarexpress polarexpress is offline
Senior Member
 
Join Date: Dec 2011
Posts: 181
polarexpress is on a distinguished road
Default Re: How to redirect the users to their id specific setting pages after updating profi

Quote:
Originally Posted by Wombat76 View Post
You are exactly right. My bad.
Why login.php fails to accomplish the login session this way sometimes and redirect the users to their account pages (myaccount.php?id=1, myaccount.php?id=2 and so on.....)?

Aside from the existing code in myaccount.php do the developers have to put any other PHP code in it in order to redirect the users to their password protected account pages (myaccount.php?id=1, myaccount.php?id=2 and so on.....) based on their session id as mentioned in header of login.php?

Shall the users be redirected to their id specific pages definately based on the header syntax /header ('Location: myacaccount.php?id=' .$_SESSION['user_id']);/ of login.php only? If no, what shall make the log in process definately successful all times?

Last edited by polarexpress : 02-22-2012 at 08:56 AM.
Reply With Quote
  #9  
Old 02-22-2012, 08:58 AM
Wombat76 Wombat76 is offline
Senior Member
 
Join Date: Mar 2011
Location: UK
Posts: 1,060
Wombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond repute
Default Re: How to redirect the users to their id specific setting pages after updating profi

As weekendrockstar correctly said, when a user logs in their $_SESSION variables are set up which are accessible from every subsequent page in your website. Therefore it isn't necessary to pass the id number as a querystring of the header statement in login.php.

So, instead of using header ("Location: myaccount.php?id='" .$_SESSION['user_id']."'"); you can simply go back to the original header ('Location: myaccount.php');

Then, in myaccount.php, use

Code:
$id = $_SESSION['user_id'];
in order to get the user's id number. You can then use that variable $id to display the individual page for that user (which you must already be doing).

I'm not sure why login.php is failing to redirect correctly sometimes unless it's a timing issue, but if that is the problem, then the above change should solve it.

Sorry for the confusion and hope this explains it better.
Reply With Quote
  #10  
Old 02-22-2012, 10:10 AM
polarexpress polarexpress is offline
Senior Member
 
Join Date: Dec 2011
Posts: 181
polarexpress is on a distinguished road
Default Re: How to redirect the users to their id specific setting pages after updating profi

Weekendrockstar is quite right but for convenience of some administrative tasks I would like to append the query string and it's corresponding values depending on the values of users' id stored in the database during registration process. The header syntex that uses user_id as session variable /header('Location: myaccount.php?id=' .$_SESSION['user_id']);/ must be good enough to serve the purpose as it is the primary key in the database table but surprisingly the log in session fails sometimes this way.

What could be the reason behind it?

Thank you,

Last edited by polarexpress : 02-22-2012 at 01:15 PM.
Reply With Quote
  #11  
Old 02-22-2012, 07:08 PM
Wombat76 Wombat76 is offline
Senior Member
 
Join Date: Mar 2011
Location: UK
Posts: 1,060
Wombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond reputeWombat76 has a reputation beyond repute
Default Re: How to redirect the users to their id specific setting pages after updating profi

I'm not sure why it should only work sometimes. When it fails, what is in the browser's address bar? It should read something like "...myaccount.php?id='1'".
Reply With Quote
  #12  
Old 02-23-2012, 06:21 AM
polarexpress polarexpress is offline
Senior Member
 
Join Date: Dec 2011
Posts: 181
polarexpress is on a distinguished road
Default Re: How to redirect the users to their id specific setting pages after updating profi

I've figured out the problem finally.

The sessiona variable based header syntex

header('Location: myaccount.php?id=' .$_SESSION['user_id']);

in login.php is all right to redirect the users to the dynamic url based landing pages associated with their ids.

The problem occurs when the isset function (For checking the session variable) in myaccount.php is placed at any other place than the top of the page. The function fails to screen and check the variable sometimes when it is put at any other place than the top of the page.

In myaccount.php it is good to put the isset function just below the database connection and password protection syntexes to avoid any unexpected failure in log in session.

< ?php
include 'dbc.php';
page_protect(); ?>
<? php if (isset($_SESSION['user_id'])) { ?>

Thank you,

Last edited by polarexpress : 02-24-2012 at 03:22 PM.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 11:50 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Webmasterpals.com (c) 2008 - All Rights Reserved