943,633 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 707
  • PHP RSS
Jan 8th, 2008
0

help

Expand Post »
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............
Reputation Points: 19
Solved Threads: 5
Junior Poster
lydia21 is offline Offline
183 posts
since Nov 2007
Jan 8th, 2008
0

Re: help

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
Reputation Points: 5
Solved Threads: 5
Junior Poster
vssp is offline Offline
197 posts
since Jul 2006
Jan 8th, 2008
0

help

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;
}
?>
Reputation Points: 19
Solved Threads: 5
Junior Poster
lydia21 is offline Offline
183 posts
since Nov 2007
Jan 8th, 2008
0

Re: help

Heres my code....
Loginform.php
PHP Syntax (Toggle Plain Text)
  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
PHP Syntax (Toggle Plain Text)
  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.
ezb
Reputation Points: 10
Solved Threads: 3
Newbie Poster
ezb is offline Offline
23 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: reading .doc using php
Next Thread in PHP Forum Timeline: pll help (HOST)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC