User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 422,797 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,387 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1265 | Replies: 21 | Solved
Reply
Join Date: Sep 2006
Posts: 89
Reputation: scorpionz is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
scorpionz scorpionz is offline Offline
Junior Poster in Training

How to direct page to login page

  #1  
Feb 15th, 2008
Hi this is Scorpion
I have create 5 pages on PHP
and 1 login Page.
Now the issue is that if user didnt login to the Website, then he cannot view those pages and simply he/she must direct to login page if click to other categories of Page.
I have Created a session but it is not doing it so.
Any help will be appreciated with great concern

Regards
Scorpion
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 239
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: How to direct page to login page

  #2  
Feb 16th, 2008
when the user logs in, put his username in the session. In all other pages, check if $_SESSION['username'] is set and not equal to null. If its null, then use header function to redirect to the login page.
Eg.
  1. //after user logs in,
  2. $_SESSION['username']=$username;
  3. //
  4. in other pages,
  5. if(! isset($_SESSION['username']) || $_SESSION['username']=="")) {
  6. //redirect to login page
  7. }

Cheers,
Naveen
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Sep 2006
Posts: 89
Reputation: scorpionz is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
scorpionz scorpionz is offline Offline
Junior Poster in Training

Thanx...

  #3  
Feb 16th, 2008
Thanx a lot dear for such an great help
Will be back soon
Regards
Scorpion
Reply With Quote  
Join Date: Sep 2006
Posts: 89
Reputation: scorpionz is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
scorpionz scorpionz is offline Offline
Junior Poster in Training

Re: How to direct page to login page

  #4  
Feb 19th, 2008
Hi this is scorpion

if i want to create my user account
like
Name, loginname, email,password...
let suppose i enter these values to create account in my Signup Form
let suppose i click on button "Create Account"

if ('')
{
then it direct to Welcome user page and and it must be sign in automatically....
}

but
in my Present case what i am dong is that
i give the location but it is automatically directing to Sign in Page.
Infact i start seession in my welcome_user.php

well how to direct it to get login automatically when create an account
not to sign in.

Any help will be higly appreciated

Thanks and Regards
scorpion
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 239
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: How to direct page to login page

  #5  
Feb 19th, 2008
On successful registration, add username to the session. In the next page, check if session is set, if yes, then redirect directly to the page which he gets after successful login. If session is not set, redirect him to login page.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Sep 2006
Posts: 89
Reputation: scorpionz is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
scorpionz scorpionz is offline Offline
Junior Poster in Training

Re: How to direct page to login page

  #6  
Feb 19th, 2008
if(isset($_POST['create_user']))
{
$usr_email_chk_avail = $_POST['user_email'];
$usr_nam_chk_avail = $_POST['user_name'];
$usr_pass_chk_avail = $_POST['user_password'];

$sql_chk = "select * from login_session where user_email='$usr_email_chk_avail' AND user_name='$usr_nam_chk_avail' AND user_password='$usr_pass_chk_avail'";

echo $sql_chk;
$result_chk = mysql_query($sql_chk);

$num_rows = mysql_num_rows($result_chk);

if ($num_rows <= 0)
{
echo "<script>alert('Congratulation This User Name: Available for You')</script>";
echo $sql_chk;
echo "<script>window.location='http://localhost/login_sess/welcome_user.php'</script>";
include 'create_user.php';

$_SESSION('u_name') = $usr_nam_chk_avail;
}



this is my code
but it is throwing error

Fatal error: Can't use function return value in write context in C:\xampp\htdocs\login_Sess\sign_up.php on line 100
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 239
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: How to direct page to login page

  #7  
Feb 19th, 2008
Its $_SESSION['u_name']=$usr_nam_chk_avail;
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Sep 2006
Posts: 89
Reputation: scorpionz is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
scorpionz scorpionz is offline Offline
Junior Poster in Training

Re: How to direct page to login page

  #8  
Feb 19th, 2008
cant understand your Point....
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 239
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: How to direct page to login page

  #9  
Feb 19th, 2008
its not
$_SESSION('u_name') = $usr_nam_chk_avail; But the one I posted above.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Sep 2006
Posts: 89
Reputation: scorpionz is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
scorpionz scorpionz is offline Offline
Junior Poster in Training

Re: How to direct page to login page

  #10  
Feb 19th, 2008
Oh My God its just a Bracket mistake
and becomes invisible for me.....
sometimes little mistakes becomes a biggest mistake

Thanks after all Naveen
Regards
Scorpion
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 9:25 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC