Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
NEed help asap with PHP
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="BIOS" data-source="post: 370394" data-attributes="member: 15674"><p>Made you a quick example, use it if you like. Not sure if it's 100% functional, haven't really checked it but should do the job.</p><p></p><p>Just change header("Location: /adminpage"); to the page which has administrative functions on/you only want these specific users to view.</p><p></p><p>[CODE]<?php</p><p></p><p> session_start();</p><p></p><p> $admins = array(</p><p> 'reinoreiska' => 'yourpassword'</p><p> );</p><p></p><p> if(!isset($_SESSION['logged_in'])){</p><p> </p><p> if(isset($_POST['login'])){</p><p> </p><p> $username = isset($_POST['username']) ? stripslashes(trim($_POST['username'])) : '';</p><p> $password = isset($_POST['password']) ? stripslashes(trim($_POST['password'])) : '';</p><p> </p><p> if(empty($username) || empty($password)){</p><p> $error = 'You left a field empty';</p><p> }</p><p></p><p> if(!isset($error)){</p><p></p><p> if(array_key_exists($username, $admins)){</p><p></p><p> if($admins[$username] == $password){</p><p></p><p> $_SESSION['logged_in'] = true;</p><p></p><p> }else{</p><p> $error = 'We couldn\'t find a record with those details';</p><p> }</p><p></p><p> }else{</p><p> #$error = 'User doesn\'t exist'</p><p> // uncomment this if you really want it, however it would allow users to find out the usernames of admins..</p><p> }</p><p></p><p> }</p><p></p><p> }</p><p>?></p><p> <h1>Login page</h1></p><p> <p></p><p> <?php</p><p> if(isset($error)){</p><p> echo $error;</p><p> }else{</p><p> echo 'You need to log-in to view this page.';</p><p> }</p><p> ?></p><p> </p></p><p></p><p> <form method="POST"></p><p> Username: <input type="text" name="username" /><br /></p><p> Password: <input type="text" name="password" /><br /></p><p> <input type="submit" name="login"/></p><p> </form></p><p><?php</p><p> }else{</p><p> header("Location: /adminpage");</p><p> exit();</p><p> }</p><p>?></p><p>[/CODE]</p><p></p><p>Then on /adminpage (your admin only page):</p><p>[CODE]</p><p><?php</p><p>session_start();</p><p></p><p>if(!isset($_SESSION['logged_in'])){</p><p> header("Location: /");</p><p> exit();</p><p>}else{</p><p>?></p><p></p><p>Admin page:</p><p>Page content here...</p><p></p><p><?php } ?>[/CODE]</p></blockquote><p></p>
[QUOTE="BIOS, post: 370394, member: 15674"] Made you a quick example, use it if you like. Not sure if it's 100% functional, haven't really checked it but should do the job. Just change header("Location: /adminpage"); to the page which has administrative functions on/you only want these specific users to view. [CODE]<?php session_start(); $admins = array( 'reinoreiska' => 'yourpassword' ); if(!isset($_SESSION['logged_in'])){ if(isset($_POST['login'])){ $username = isset($_POST['username']) ? stripslashes(trim($_POST['username'])) : ''; $password = isset($_POST['password']) ? stripslashes(trim($_POST['password'])) : ''; if(empty($username) || empty($password)){ $error = 'You left a field empty'; } if(!isset($error)){ if(array_key_exists($username, $admins)){ if($admins[$username] == $password){ $_SESSION['logged_in'] = true; }else{ $error = 'We couldn\'t find a record with those details'; } }else{ #$error = 'User doesn\'t exist' // uncomment this if you really want it, however it would allow users to find out the usernames of admins.. } } } ?> <h1>Login page</h1> <p> <?php if(isset($error)){ echo $error; }else{ echo 'You need to log-in to view this page.'; } ?> </p> <form method="POST"> Username: <input type="text" name="username" /><br /> Password: <input type="text" name="password" /><br /> <input type="submit" name="login"/> </form> <?php }else{ header("Location: /adminpage"); exit(); } ?> [/CODE] Then on /adminpage (your admin only page): [CODE] <?php session_start(); if(!isset($_SESSION['logged_in'])){ header("Location: /"); exit(); }else{ ?> Admin page: Page content here... <?php } ?>[/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
NEed help asap with PHP
Top