| | |
Linking from the login page to other pages
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2006
Posts: 90
Reputation:
Solved Threads: 0
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>
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>
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.
In adminpage.php, have a menu to navigate to other pages.
php Syntax (Toggle Plain Text)
<? // 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: adminpage.php"); } ?>
In adminpage.php, have a menu to navigate to other pages.
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Oct 2006
Posts: 90
Reputation:
Solved Threads: 0
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>
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>
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*
*PM asking for help will be ignored*
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
Cheers,
Naveen
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
Similar Threads
- Hijackthis Log (Viruses, Spyware and other Nasties)
- Please check this log to see if I'm clean (Viruses, Spyware and other Nasties)
- PHP sessions/$_POST problem. Too Stressed today! (PHP)
- Spyware Problem (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: Explain about Text
- Next Thread: How to search between two dates using mysql or php
| Thread Tools | Search this Thread |
301 apache api array autosuggest beginner binary broken cakephp checkbox class cms code compression cron curl data database date display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google href htaccess html httppost if...loop image include insert ip javascript joomla jquery key library limit link links login mail md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search searchbox server session sessions sms sorting source space sql syntax system table tutorial update upload url validator variable video volume votedown web website youtube zend






