help

Reply

Join Date: Nov 2007
Posts: 183
Reputation: lydia21 is an unknown quantity at this point 
Solved Threads: 5
lydia21 lydia21 is offline Offline
Junior Poster

help

 
0
  #1
Jan 8th, 2008
hi
i have a login page which is allowing only registered user .it is working too......
but when the second page URL is typed it is getting displayed i want the all the user to enter through the first page.......when the second page URL is typed it should not get displayed............
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 197
Reputation: vssp has a little shameless behaviour in the past 
Solved Threads: 5
vssp vssp is offline Offline
Junior Poster

Re: help

 
0
  #2
Jan 8th, 2008
When login you store the values to SESSION variable. then

try this code

$user_id=$_SESSION['sng_userid'];
if(!$user_id)
{
echo "<meta http-equiv=refresh content=0;url=index.php>";
exit;
}


this will help for you
Thanks
VSSP
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 183
Reputation: lydia21 is an unknown quantity at this point 
Solved Threads: 5
lydia21 lydia21 is offline Offline
Junior Poster

help

 
0
  #3
Jan 8th, 2008
sorry it is not working....i tried like this

login form
<form method="post" action="start1.php">
<body>
<form name="form1" method="post" action="checklogin.php">
Username<input name="myusername" type="text" id="myusername">
Password<input name="mypassword" type="password" id="mypassword">
<input type="submit" name="Submit" value="Login">
</form>

login code
<?php

$myusername=$_POST['myusername'];
$_session['name']=$myusername;
$mypassword=$_POST['mypassword'];

if ($myusername=="" && $mypassword=="")
{
print "<script language=\"JavaScript\">";
print "window.location = 'http://www.ho.com/aa/viewuser.php'";
print "</script>";
}
else
{
print "<script language=\"JavaScript\">";
print "window.location = 'http://www.ho.com/aa/start.php'";
print "</script>";
}
?>

view user page
<?php
   session_start();
  

$user_id="aletheia.loco"; 
if(!$user_id)
{
echo "<meta http-equiv=refresh content=0;url=start.php>";
exit;
}
?>
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 23
Reputation: ezb is an unknown quantity at this point 
Solved Threads: 3
ezb ezb is offline Offline
Newbie Poster

Re: help

 
0
  #4
Jan 8th, 2008
Heres my code....
Loginform.php
  1. <table>
  2. <tr><td></td><td>
  3. <?php
  4.  
  5. if(isset($_SESSION['group'])){
  6. echo "You are logged in as: <b>";
  7. echo $_SESSION['username'];
  8. }
  9. else { ?>
  10. <table>
  11. <form name="loginform" method="post" action="login.php">
  12. <tr><td>Username:</td><td><input type="text" name="username"></td><td>Password:</td><td><input type="password" name="password"></td><td></td><td><input type="submit" value="Submit"><input type="reset" value="Clear"></td></tr>
  13. </form>
  14. </table>
  15. <?
  16. }
  17. ?>
Code above first checks if the session is set in my case "group" and if it is simple message saying you are logged in as "username" (another seshion I have set up) and they do not see the login form. If it is not set, they will see a basic login form.

Then the actul loging in process and setting up the seshions
  1. <?php
  2.  
  3. $host="localhost";
  4. $username="username";
  5. $password="password";
  6. $db_name="dbname";
  7. $tbl_name="tablename";
  8.  
  9. //Connect to the serve and select database
  10. mysql_connect("$host", "$username", "$password") or die ("Cannot connect to server");
  11. mysql_select_db("$db_name") or die ("cannot select database");
  12.  
  13.  
  14. //Taking information from the form
  15. $username=$_POST['username'];
  16. $password=$_POST['password'];
  17.  
  18.  
  19. //browsing the database for a match
  20. $sql="SELECT user_username, user_password, user_groupid, company_id, user_id FROM $tbl_name WHERE user_username='$username' and user_password='$password'";
  21. $result=mysql_query($sql);
  22.  
  23.  
  24. //count table row
  25. $count=mysql_num_rows($result);
  26.  
  27.  
  28. //If correct username and password result should equal 1
  29. if($count==1){
  30. $Groupid=mysql_result($result,'', 'user_groupid');
  31. $Companyid=mysql_result($result,'','company_id');
  32. $Userid=mysql_result($result,'','user_id');
  33. session_start();
  34. $_SESSION['userid'] = $Userid;
  35. $_SESSION['username'] = $username;
  36. $_SESSION['group'] = $Groupid;
  37. $_SESSION['usercompanyid'] = $Companyid;
basicly searches the database for a match with the login details, and if found starts the seshions.

For the pages you only want logged in users to see, simply rework what I showed you with the login form. Only allowing users with your seshion set, or with a specific value.

Not the safest of scripts, pretty sure someone will show you abetter one, but it will work.
Reply With Quote Quick reply to this message  
Reply

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



Other Threads in the PHP Forum


Views: 615 | Replies: 3
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC