| 
	
 | 
 Posted by Flamer on 06/14/17 11:55 
Flaming Corncob wrote: 
 
> Below is the code I've come up with. So far it works the way I want it 
> to, but I am an amateur at this whole thing and would like to know if 
> there's any potential problems with it. It's coded to work in a single 
> page, linking to itself instead of linking to other pages. NOTE: It 
> doesn't currently check the account ID that is entered against a 
> database. That's easy to do. Right now all it does is accept whatever 
> the user types in as uses it. 
> 
> <html> 
> 
> <? 
> if($key!="1701") 
> { 
> header("Location:?key=1701&page=page_1"); 
> } 
> else 
> // Start: MAIN BODY 
> { 
> session_start(); 
> if(!session_is_registered("account_id")) 
> { 
> if($page=="post_id") 
> { 
> post_id($key); 
> } 
> } 
> else 
> { 
> if($page=="member_logout") 
> { 
> member_logout($key); 
> } 
> } 
> 
> echo "<body>"; 
> 
> if(!session_is_registered("account_id")) 
> { 
> member_login($key); 
> } 
> else 
> { 
> echo "Hello, ".$_SESSION['account_id']."!"; 
> if($page!="page_1") 
> { 
> echo "<br><a href='?key=$key&page=page_1'>Goto Page 1</a>"; 
> } 
> else if($page!="page_2") 
> { 
> echo "<br><a href='?key=$key&page=page_2'>Goto Page 2</a>"; 
> } 
> echo "<br><a href='?key=$key&page=member_logout'>Log Out</a>"; 
> } 
> 
> echo "</body>"; 
> // End: MAIN BODY 
> } 
> 
> function member_login($key) 
> { 
> echo "<form action='?key=$key&page=post_id' method='post'>"; 
> echo "Account ID: <input type='text' name='account_id'>"; 
> echo "</form>"; 
> } 
> 
> function member_logout($key) 
> { 
> session_destroy(); 
> header("Location:?key=0"); 
> } 
> 
> function post_id($key) 
> { 
> session_register("account_id"); 
> $_SESSION['account_id']=$_POST['account_id']; 
> header("Location:?key=$key"); 
> } 
> 
> echo "</html>"; 
> ?> 
 
header("location: needs to be a full url starting with http://, also 
you probably want to put an @ at the start of the @session_destroy 
command, not needed, however if a cookie isnt set on their pc (ie they 
refreshed the logout page) they will get an ugly error.  
 
Flamer.
 
  
Navigation:
[Reply to this message] 
 |