Linking from the login page to other pages

Reply

Join Date: Oct 2006
Posts: 90
Reputation: dami06 is an unknown quantity at this point 
Solved Threads: 0
dami06 dami06 is offline Offline
Junior Poster in Training

Linking from the login page to other pages

 
0
  #1
Feb 5th, 2008
Hi,
Could anyone please tell me how to go about linking some folders which are already in php to the login page. For example once you have logged in successfully, the next thing you want to see is the admin homepage. How do you link the login page to the admin page and then from the admin page to the student page etc. Please i would be greatful if anyone could provide the code. This is my code for both the checklogin.php and login_success.php

checklogin.php

<?php
ob_start();
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="abby1"; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}

ob_end_flush();
?>


login_success.php

<?
// Check if session is not registered , redirect back to main page.
// Put this code in first line of web page.
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>

<html>
<body>
Login Successful
</body>
</html>
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,746
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Linking from the login page to other pages

 
0
  #2
Feb 5th, 2008
Using menus ? If a user is valid, redirect him to the next page which has a menu to navigate to all the pages. You can use the same header function to redirect the user after successful login.
  1. <?
  2. // Check if session is not registered , redirect back to main page.
  3. // Put this code in first line of web page.
  4. session_start();
  5. if(!session_is_registered(myusername)){
  6. header("location:main_login.php");
  7. } else {
  8. header("location: adminpage.php");
  9. }
  10. ?>

In adminpage.php, have a menu to navigate to other pages.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 90
Reputation: dami06 is an unknown quantity at this point 
Solved Threads: 0
dami06 dami06 is offline Offline
Junior Poster in Training

Re: Linking from the login page to other pages

 
0
  #3
Feb 5th, 2008
ok thank you i will try that. But what if what i want is in a folder which is C:\xampp\htdocs\webpaos\admin\index.php

how do i put it. do i put it like what i just put?
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,746
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Linking from the login page to other pages

 
0
  #4
Feb 5th, 2008
yep.
header("location: $url");
where $url can be
1. A url eg. $url="http://www.yahoo.com";
2. The screen where you want to redirect the user.
Eg. $url="path/to/admin/index.php";
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 90
Reputation: dami06 is an unknown quantity at this point 
Solved Threads: 0
dami06 dami06 is offline Offline
Junior Poster in Training

Re: Linking from the login page to other pages

 
0
  #5
Feb 5th, 2008
ok i tried all that but it gave me this error

Parse error: syntax error, unexpected $end in C:\xampp\htdocs\webpaos\login_success.php on line 16

but i don't have a line 16 in the login_success.php. This is the code for login_success.php

<?
// Check if session is not registered , redirect back to main page.
// Put this code in first line of web page.
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
} else {
header("location:localhost/webpaos/admin/index.php")
?>

<html>
<body>
Login Successful
</body>
</html>
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,746
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Linking from the login page to other pages

 
0
  #6
Feb 5th, 2008
else {
header("location:localhost/webpaos/admin/index.php")
Missing } tag and semi-colon after header.
Last edited by nav33n; Feb 5th, 2008 at 1:28 pm.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 90
Reputation: dami06 is an unknown quantity at this point 
Solved Threads: 0
dami06 dami06 is offline Offline
Junior Poster in Training

Re: Linking from the login page to other pages

 
0
  #7
Feb 5th, 2008
my goodness nav your at absolutley brillianttttttttttttttttt..AWESOMEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE..I LOVE YOU.

I have another question though but i will put it in another thread if you don't mind
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,746
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Linking from the login page to other pages

 
0
  #8
Feb 5th, 2008
Oh btw, you cant give localhost. You should give the relative path. For example, if your executing script is in webpaos and you want to redirect the user to admin/index.php, you can do it this way.
header("location: ./admin/index.php");
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,746
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Linking from the login page to other pages

 
0
  #9
Feb 5th, 2008
Umm.. Did it solve your problem ? And yep! dont give the absolute path. If you host this site some day, you should search for localhost in your script and change it to the url. So, its better if you give relative path of the file.

Cheers,
Naveen
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 90
Reputation: dami06 is an unknown quantity at this point 
Solved Threads: 0
dami06 dami06 is offline Offline
Junior Poster in Training

Re: Linking from the login page to other pages

 
0
  #10
Feb 5th, 2008
yes it solved my problem.. what of when i logout and then i want it to redirect back to the login page would this be right?

logout.php

<?
// Put this code in first line of web page.
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
session_destroy();
?>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC