473,566 Members | 2,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to direct to my own login page when user enter some other URL

3 New Member
Hi,
I am new to php. I have two pages.one is login page other is details page.
When user enter detaisl page directly in URL i want to redirect to login page then login success it should go to detaisl page.
Could any one help me out.
I tried using a variable declaring , assigning in login page.
checking the value in details page.
but i am getting error as variable not defined if open directly details page.
Dec 10 '07 #1
3 2943
clai83
41 New Member
Hi,
I am new to php. I have two pages.one is login page other is details page.
When user enter detaisl page directly in URL i want to redirect to login page then login success it should go to detaisl page.
Could any one help me out.
I tried using a variable declaring , assigning in login page.
checking the value in details page.
but i am getting error as variable not defined if open directly details page.
Hi,

I think what you are trying to do is, you have a members section that can only be accessed after you login. Now if someone were to try to view a page in the members area and did not login then it would redirect the user to the login page. Now once the user is authorized then the user is redirected back to page he just came from.
Correct so far?

A. To redirect in PHP use the header() function.

[PHP]
<?php
header("Locatio n: login.php");
?>
[/PHP]

Make sure that there is no white space, or anything sent to the browser before the header function like include or require statements, otherwise it will not work. If you can't change your code and you have to have a include or require statement before the header function the use the output buffering functions ob_start() and ob_flush(). Check out www.php.net for a description of that.

B. Telling the login page where your user came from

There are 2 ways you can do this.

1. Use hidden forms on all your pages.
2. Use PHP SESSIONS.

For number 1, you can set up a hidden form on each of your pages that identifies it. The if someone goes to that page without logging in, you can redirect him to the login page with the hidden form value and process it there

I prefer number 2, but if you want to use SESSIONS you gotta read up the topic yourself.

In everypage of your members area you need to do the following

[PHP]
<?php

//start your session
session_start() ;


//There are 2 cases here.
// 1. the user has visited this page for the first time.
// 2. loggin in at some point, but logged out or his session expired

//Check if there is a session variable set or not
//and if not then set a sesesion variable and the redirect
if ( (isset($_SESSIO N['logged_in'])) {
//if user is not logged in then set a session variable
//and redirect
if (!$_SESSION['logged_in']) {
//store the page that the user was in
$_SESSION['previous_page'] = $_SERVER['PHP_SELF'];
header("Locatio n: login.php");
}
else {
//do some user authenication
}
}
else {
//store the page that the user was in
$_SESSION['previous_page'] = $_SERVER['PHP_SELF'];
//redirect
header("Locatio n: login.php");
}

?>
[/PHP]

This is by no means secure or complete. Just the basics.

hope this helps
Dec 10 '07 #2
pveena
3 New Member
Hi,

I think what you are trying to do is, you have a members section that can only be accessed after you login. Now if someone were to try to view a page in the members area and did not login then it would redirect the user to the login page. Now once the user is authorized then the user is redirected back to page he just came from.
Correct so far?

A. To redirect in PHP use the header() function.

[PHP]
<?php
header("Locatio n: login.php");
?>
[/PHP]

Make sure that there is no white space, or anything sent to the browser before the header function like include or require statements, otherwise it will not work. If you can't change your code and you have to have a include or require statement before the header function the use the output buffering functions ob_start() and ob_flush(). Check out www.php.net for a description of that.

B. Telling the login page where your user came from

There are 2 ways you can do this.

1. Use hidden forms on all your pages.
2. Use PHP SESSIONS.

For number 1, you can set up a hidden form on each of your pages that identifies it. The if someone goes to that page without logging in, you can redirect him to the login page with the hidden form value and process it there

I prefer number 2, but if you want to use SESSIONS you gotta read up the topic yourself.

In everypage of your members area you need to do the following

[PHP]
<?php

//start your session
session_start() ;


//There are 2 cases here.
// 1. the user has visited this page for the first time.
// 2. loggin in at some point, but logged out or his session expired

//Check if there is a session variable set or not
//and if not then set a sesesion variable and the redirect
if ( (isset($_SESSIO N['logged_in'])) {
//if user is not logged in then set a session variable
//and redirect
if (!$_SESSION['logged_in']) {
//store the page that the user was in
$_SESSION['previous_page'] = $_SERVER['PHP_SELF'];
header("Locatio n: login.php");
}
else {
//do some user authenication
}
}
else {
//store the page that the user was in
$_SESSION['previous_page'] = $_SERVER['PHP_SELF'];
//redirect
header("Locatio n: login.php");
}

?>
[/PHP]

This is by no means secure or complete. Just the basics.

hope this helps

Hi,
I have still doubt could u please clarify. Where to start session in login page or in details page.
I followed apprach a using header i am still geting details page not redirecting to login page.
In Error log it shows the following message..
Warning: Cannot modify header information - headers already sent
Dec 11 '07 #3
pveena
3 New Member
Hi,
I have still doubt could u please clarify. Where to start session in login page or in details page.
I followed apprach a using header i am still geting details page not redirecting to login page.
In Error log it shows the following message..
Warning: Cannot modify header information - headers already sent
I am using cookies is it right way or not please let me know.
it is working now.
I am calling set cookie method with some variable in login.php if the login is success , in details page i am checking whether this cookie is set or not.if it is not set then calling login page.
it is working i want to know whether it is right way or not.

Please let me know..
Dec 11 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3426
by: XP | last post by:
I am having problems with the blow page. I have a login page where I enter the userid and password. This then connects to this page. If I enter the userid and password correctly, it prints successfully logged into system. If I enter the wrong information all I get is an erro page HTTP status 502 etc. Can anyone help? <?php
1
5461
by: Wayne Smith | last post by:
Applies to: Microsoft FrontPage 2000, Microsoft Access 2000, IIS 5.0 Operating System: Microsoft Windows 2000 Professional I am trying to protect a portion of a web site by allowing users to register a username and password & then login with those details, but so far I am having only marginal success. I am far from an expert on ASP...
2
2311
by: Gill Bates | last post by:
I'm trying to login to a banking site (https://www.providentconnection.com) using vb.net. I've tried many variations of WebClient and HttpWebRequest; none of which I've got to work. My latest version is: Dim myWebClient As New WebClient Dim nvc As New NameValueCollection nvc.Add("Login", username) nvc.Add("Password", password)
7
4474
by: Grant Merwitz | last post by:
Hi I am trying to get the enter key to submit my login form The login form is currently in a control on the page and uses an asp:imagebutton as it's login button. If a user presses enter currently, the page just reloads. I have tried to use some javascript to set the enter key on the button, but this script only seems to work for an...
10
4494
by: et | last post by:
I have an asp.net program that uses a connection string, using integrated security to connect to a sql database. It runs fine on one server, but the other server gives me the error that "Login failed for user "NT AUTHORITY/ANONYMOUS LOGON". Why would this be? There is no reason it should even be trying to login to using NT...
6
9867
by: =?Utf-8?B?UGFyYWcgR2Fpa3dhZA==?= | last post by:
Hi All, We have a requirement where we have to develop a custom Login Page which will accept user's NT credentials ( Username , password, domain name). This then needs to be passed to a website which uses Windows Authentication Now my question is how do we pass these credentials to IIS in classic ASP? Would appreciate any help/pointers on...
4
1915
by: jobs | last post by:
Hello. If my users are logged in, and try to access restricted pages I want to direct them to a custom 403 page. If they are not logged in, I would like to continue to direct them to the login page as is currently happening. Curently, they always direct to the Login page in both cases, which i think is confusing.
2
2508
by: upendrajpr | last post by:
Dear frindes, I am new to php. in my 'php' code when someone login into my page he/she awail the necessary page rights, it's quite ok. but when it click on the page and someone direct copy & paste the url he also access the page without proper login. How it could be possible that someone access only after the login and not direct copy &...
2
1442
oranoos3000
by: oranoos3000 | last post by:
hi I have a login page in my site for login member I want to any user that arrival correctly directly go to page1.php I use header statement(header("Location: page1.php")) in middle page that befor I have Html tage and the other echo statement now header statement dont direct user to page1.php because before this statement this html...
0
7666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7644
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7951
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.