473,387 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

[Help]User must login to access the pages

Below is my code where the link will be generated from database.. when user wanted to access the link they must be logged in.. how to make it?


Expand|Select|Wrap|Line Numbers
  1. <div class="h3"><?php echo $servername; ?> Features</div>
  2. <div class="mainbox">
  3. <ul id="features">
  4. <?php
  5. $con = mysql_connect("localhost","root","");
  6. if (!$con)
  7.   {
  8.   die('Could not connect: ' . mysql_error());
  9.   }
  10.  
  11. mysql_select_db("job_seeks", $con);
  12.  
  13. $result = mysql_query("SELECT * FROM employer_user");
  14. while($row = mysql_fetch_array($result))
  15.   {
  16.   echo "<li><a href="."?page=job_detail".">".$row['business_name']."</a></li>";
  17.   }
  18. echo "</tbody>";
  19. echo "</table>";
  20.  
  21. mysql_close($con);
  22. ?>
  23. </ul>
  24. </div>
And this is the code for the page that user needed to login to access this page.. this page is linked with the code at the top

Expand|Select|Wrap|Line Numbers
  1. <div class="h3"><?php echo $servername; ?> Features</div>
  2. <div class="mainbox">
  3. <ul id="features">
  4. <?php
  5. $con = mysql_connect("localhost","root","");
  6. if (!$con)
  7.   {
  8.   die('Could not connect: ' . mysql_error());
  9.   }
  10.  
  11. mysql_select_db("job_seeks", $con);
  12.  
  13. $result = mysql_query("SELECT * FROM employer_user");
  14. $row = mysql_fetch_array($result);
  15. ?>
  16.  
  17. <table cellspacing=0 cellpadding=5>
  18.         <tr><td class=listtitle colspan=2><center><span class='title2'></span></center></td></tr>
  19.         <?php
  20.         echo "
  21.         <form method=\"POST\">
  22.         <tr><td class=list align=left><b>Username :</b></td><td class=list> ".$row['username']."<br></td></tr>
  23.         <tr><td class=list align=left><b>Business Name :</b></td><td class=list> ".$row['business_name']."<br></td></tr>
  24.         <tr><td class=list align=left><b>Address :</b></td><td class=list> ".$row['address']."<br></td></tr>
  25.         <tr><td class=list align=left><b>Location :</b></td><td class=list> ".$row['location']."<br></td></tr>
  26.         <tr><td class=list align=left><b>City/Town :</b></td><td class=list> ".$row['city_town']."<br></td></tr>
  27.         <tr><td class=list align=left><b>Email :</b></td><td class=list> ".$row['email']."<br></td></tr>
  28.         <tr><td class=list align=left><b>Phone Number :</b></td><td class=list> ".$row['phone']."<br></td></tr>
  29.         <tr><td class=list align=left><b>Qualification :</b></td><td class=list> ".$row['qualification']."<br></td></tr>
  30.         <tr><td class=list align=left><b>Salary :</b></td><td class=list> ".$row['salary']."<br></td></tr>
  31.         <tr><td class=list align=left><b>Description :</b></td><td class=list> ".$row['company_description']."<br></td></tr>";
  32.         echo "</td></tr></table>";
  33.         echo "<p><center><input type=\"submit\" name=\"setting\" value=\"Apply\" onClick=\"parent.location='?page=account'\" />
  34.                 </center>";
  35. ?>
  36. </ul>
  37. </div>
  38.  
  39.  
  40.  
  41.  
Dec 7 '11 #1

✓ answered by AutumnsDecay

Session variables are domain based, not directory based. If you set "$_SESSION['auth']" to '1' on the login page, and include that session on your proceeding pages, $_SESSION['auth'] will still be set.

Check this out:

www.autumnsolutions.org/storage/sessions

On the first page I made the $_SESSION['auth'] variable be set to "Wooo!" or something like that. When you click 'Go' underneath that, it directs you to http://www.autumnsolutions.org/stora...age2/index.php.

You can see on the new page that when I print my 'auth' session variable to the screen, it still says 'Wooo!', and then I added the 'Yay' after it to show that it hit a new page.

I don't want to sound like a jerk, but are you putting any research effort into this at all, or are you just wanting us to give you the answers you need?

10 2947
AutumnsDecay
170 100+
I'm not exactly what you're after as your question is pretty vague, but it sounds like you're looking for a login script of sorts.

A simple login form would look something like this:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. if((!$_SESSION['auth']) || ($_SESSION['auth'] != 1)){
  4.  
  5. ?>
  6.  
  7. <form action="login.php" method="post">
  8. Username: <input name="username" type="text" />
  9. Password: <input name="password" type="password" />
  10. </form>
  11.  
  12. <?php }
  13.  
  14.  
  15. else {
  16.     //access to authorized stuff
  17. }
  18.  
  19. ?>
  20.  
  21.  
And your login page would look something like this, assuming you're using basic encrypting like md5:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. session_start();
  4. $username = $_POST['username'];
  5. $password = md5($_POST['password']);
  6.  
  7. $result = mysql_query("SELECT * FROM users WHERE username = '$username'");
  8.  
  9. if(mysql_num_rows($result) > 0){
  10.     $row = mysql_fetch_assoc($result);
  11.     if($row['password'] == $password){
  12.         $_SESSION['auth'] = 1;
  13.         header("Location: index.php");
  14.     }
  15.     else {
  16.         print 'Invalid password.';
  17.     }
  18. }
  19. else {
  20.     print 'No users found.';
  21. }
  22. ?>
  23.  
That's a rough idea for a fairly low security login script.
Dec 7 '11 #2
i have my login and logout script pages... but i wanted to make the script that i given above, user must be logged in to access the above pages... how can i do?
Dec 8 '11 #3
AutumnsDecay
170 100+
Set a session variable, and check to see if that session variable exists on each page.

Login Script:
Expand|Select|Wrap|Line Numbers
  1. session_start(); // Start the session
  2. //All your user data verification for login
  3. $_SESSION['auth'] = 1; //Create a SESSION variable called 'auth'.
  4. header("Location: yourpage.php"); //Redirects to yourpage.php after the script has run.
  5.  
On each proceeding page (yourpage.php, yourpage2.php, etc):

Expand|Select|Wrap|Line Numbers
  1. session_start();
  2. if((!$_SESSION['auth']) || ($_SESSION['auth'] != 1)){ 
  3. //If the Session's 'auth' variable isn't set, or if it doesn't equal 1, then:
  4.  
  5.     header("Location: index.php"); //Redirect to the home page if they aren't authorized
  6. }
  7.  
Another thing you can do is authorized information in a public place. Example: If a user isn't logged in, display 'Login or Register', else if a user is logged in, display 'Welcome back!'.

Expand|Select|Wrap|Line Numbers
  1. if((!$_SESSION['auth']) || ($_SESSION['auth'] != 1)){
  2.     print 'Login or Register';
  3. }
  4.  
  5. else if($_SESSION['auth'] = 1){
  6.     print 'Welcome back!';
  7. }
  8.  
Dec 8 '11 #4
See this ss>> http://prntscr.com/4hxgv Above code are stored at the pages folder... and in source folder wheres my login/logout pages are stored. thats mean theres a session_start already called.. And this is my login pages looks like>> http://prntscr.com/4hxl8 my login part already set appear on every pages.. how i gonna to do
Dec 8 '11 #5
AutumnsDecay
170 100+
Session variables are domain based, not directory based. If you set "$_SESSION['auth']" to '1' on the login page, and include that session on your proceeding pages, $_SESSION['auth'] will still be set.

Check this out:

www.autumnsolutions.org/storage/sessions

On the first page I made the $_SESSION['auth'] variable be set to "Wooo!" or something like that. When you click 'Go' underneath that, it directs you to http://www.autumnsolutions.org/stora...age2/index.php.

You can see on the new page that when I print my 'auth' session variable to the screen, it still says 'Wooo!', and then I added the 'Yay' after it to show that it hit a new page.

I don't want to sound like a jerk, but are you putting any research effort into this at all, or are you just wanting us to give you the answers you need?
Dec 8 '11 #6
AutumnsDecay
170 100+
Another note, when you do "session_start();" on your proceeding pages, it does NOT overwrite the existing session, it EXTENDS the session on to the new page.
Dec 8 '11 #7
-my problem is solved-
Dec 8 '11 #8
AutumnsDecay
170 100+
Perfect.

If one of my answers solved your problem, please set it as the Answer for this thread. This will allow other users that have the same issue as you to see what the fix was.

Thanks.
Dec 8 '11 #9
where to set it as the thread is answer?
Dec 8 '11 #10
AutumnsDecay
170 100+
Bottom right of all my replies you should see "Choose as Best Answer".

Thanks.
Dec 8 '11 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Dan | last post by:
Hello to all. Any knowledge that you might have one the following subject will be GREATLY appriciated. I am new to Access Pages and I can not get rid of the following errors when I open my...
0
by: luci | last post by:
Hello I've developed several data access pages and I searched for the same problems in different internet pages but I never got back a usable answer. Here are my questions: 1) How is it...
0
by: Donald Watson | last post by:
I have created data access pages for my database that is sitting in a shared folder on the network so all my users have access to it. Everything works perfectly. I have 2 data access pages built....
3
by: Lyle Fairfield | last post by:
In a recent thread there has been discussion about Data Access Pages. It has been suggested that they are not permitted on many or most secure sites. Perhaps, that it is so, although I know of no...
10
by: Edlueze | last post by:
I am developing some Data Access Pages (DAP) using Microsoft Access 2003 on Microsoft Windows XP. When I try to open these pages (located on my C: drive), the display of the data access page is...
4
by: Joe | last post by:
Hi, I have MS Access database with a small table that has four columns ID (Primary Key), page, userid and password. The page column holds the name of the page which has the login form. The...
0
by: Stuart Adair | last post by:
Good morning, I've build a database with Access 2003 which sits on a network. I want to use Data Access Pages to allow users on the network to be able to enter data to a field called RMComment....
2
by: Torilyn73 | last post by:
Alrighty... one problem down... 40 more to go!! (Just kidding.. not really 40.. only 32!) My database needs to be accessible via the web. I have the server information so when its ready I can...
3
by: freee8896 | last post by:
Can nyone help me with this multi user login from the same system. Multiple users must be able to login from the same system at a time.... in PHP. Sessions must be used. Please donot suggest these...
0
by: patiencer | last post by:
Hi! Can you help me a effective source code of user login with ms access as your database i already set the data adopter, dataset, datasource and whatsoever. I just need to get how to call the MS...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.