changing a login script

Discussion in 'PHP' started by promotingspace.net, Jun 26, 2007.

  1. #1
    Hi
    I'm using a free php login script and want to make some changes to my own language. ( that is a right to left one so I have to use tables to have it displayed correctly.)
    The original code is this:

    <?php
    /* $Id: login.php,v 1.7 2002/09/03 22:02:01 shaggy Exp $ */
    
    	require_once 'global.php';
    	
    	if ($_SESSION['logged']) {
    		redirect('user.php');
    	}
    
    	require_once 'html_form.php';
    	$form = new Form(uri_self());
    
    	$form->addText('username', 'Username');
    	$form->addPassword('password', 'Password');
    	$form->addCheckbox('remember', 'Remember me');
    
    	$form->addSubmit('Log in');
    
    	$form->addRule('username', 'range:5:20', 'Enter your username, 5 - 20 characters.');
    	$form->addRule('password', 'range:5:20', 'Enter your password, 5 - 20 characters.');
    
    	$form->addFilter('_ALL_', 'db');
    
    	if ($form->valid()) {
    		$processed = $form->getProcessed();
    		$remember = $form->getValue('remember');
    
    		if (!isset($_SESSION['login'])) {
    			$_SESSION['login'] = 3;
    		} else {
    			if ($_SESSION['login'] <= 1) {
    				die('You cannot log in.');
    			}
    		}
    
    		if ($user->_checkLogin($processed['username'], $processed['password'], $remember)) {
    			if (isset($_SESSION['log_to'])) {
    				redirect($_SESSION['log_to']);
    			} else {
    				redirect('/user/');
    			}
    		} else {
    			failed($form);
    		}
    
    	} else {
    		begin_html();
    		$form->display();
    	}
    
    	function failed(&$form) {
    		begin_html();
    		echo "<p>You could not be logged in, $_SESSION[login] attempts left.</p>
    		<p>Possible reasons for this are:</p>
    
    		<ul>
    			<li>Your username and/or password is not correct.
    				Check your username and password and then try again.</li>
    			<li>You haven't " .
    			'<a href="signup.php" title="Sign up for an account, it is free">registered</a> yet</li>
    			<li>Your account is temporarily disabled.</li>
    			<li>You are trying to login simultaneously from two different computers or
    			two browsers on the same computer.</li>
    		</ul>';
    
    		$form->display();
    	}
    ?>
    PHP:
    it has some functions, but does not seem difficult to guess how they work. I want the form like this:
    
    <p align="right">&nbsp;</p>
    <div align="right">
    	<table border="0" width="43%" dir="rtl" id="table1">
    		<tr>
    			<td width="87"><span lang="fa">شناسه كاربري:&nbsp; </span></td>
    			<td><input type="text" name="username" size="25"></td>
    		</tr>
    		<tr>
    			<td width="87"><span lang="fa">رمز عبور:</span></td>
    			<td><input type="text" name="password" size="25"></td>
    		</tr>
    		<tr>
    			<td width="87">
    			<p><input type="checkbox" name="remember" value="ON" style="float: left"></td>
    			<td><span lang="fa">ورود اتوماتيك در بازديدهاي بعد</span></td>
    		</tr>
    		<tr>
    			<td width="87">&nbsp;</td>
    			<td>
    			<p align="center"><input type="submit" value="ورود" name="B1"></td>
    		</tr>
    	</table>
    </div>
    Code (markup):
    But defenitely I'll have to make some other changes to make it work. what should I do about it?
    Thanks

    <?php
    /* $Id: login.php,v 1.7 2002/09/03 22:02:01 shaggy Exp $ */
    
    	require_once 'global.php';
    	
    	if ($_SESSION['logged']) {
    		redirect('user.php');
    	}
    
    	require_once 'html_form.php';
    	$form = new Form(uri_self());
    	?>
      <p align="right">&nbsp;</p>
    <div align="right">
    	<table border="0" width="43%" dir="rtl" id="table1">
    		<tr>
    			<td width="87"><span lang="fa">شناسه كاربري:&nbsp; </span></td>
    			<td><input type="text" name="username" size="25"></td>
    		</tr>
    		<tr>
    			<td width="87"><span lang="fa">رمز عبور:</span></td>
    			<td><input type="text" name="password" size="25"></td>
    		</tr>
    		<tr>
    			<td width="87">
    			<p><input type="checkbox" name="remember" value="ON" style="float: left"></td>
    			<td><span lang="fa">ورود اتوماتيك در بازديدهاي بعد</span></td>
    		</tr>
    		<tr>
    			<td width="87">&nbsp;</td>
    			<td>
    			<p align="center"><input type="submit" value="ورود" name="login"></td>
    		</tr>
    	</table>
    </div>
      <?
    
    	if ($form->valid()) {
    		$processed = $form->getProcessed();
    		$remember = $form->getValue('remember');
    
    		if (!isset($_SESSION['login'])) {
    			$_SESSION['login'] = 3;
    		} else {
    			if ($_SESSION['login'] <= 1) {
    				die('You cannot log in.');
    			}
    		}
    
    		if ($user->_checkLogin($processed['username'], $processed['password'], $remember)) {
    			if (isset($_SESSION['log_to'])) {
    				redirect($_SESSION['log_to']);
    			} else {
    				redirect('/user/');
    			}
    		} else {
    			failed($form);
    		}
    
    	} else {
    		begin_html();
    		$form->display();
    	}
    
    	function failed(&$form) {
    		begin_html();
    		echo "<p>You could not be logged in, $_SESSION[login] attempts left.</p>
    		<p>Possible reasons for this are:</p>
    
    		<ul>
    			<li>Your username and/or password is not correct.
    				Check your username and password and then try again.</li>
    			<li>You haven't " .
    			'<a href="signup.php" title="Sign up for an account, it is free">registered</a> yet</li>
    			<li>Your account is temporarily disabled.</li>
    			<li>You are trying to login simultaneously from two different computers or
    			two browsers on the same computer.</li>
    		</ul>';
    
    		$form->display();
    	}
    ?>
    
    
    PHP:
     
    promotingspace.net, Jun 26, 2007 IP
  2. dankenpo

    dankenpo Guest

    Messages:
    30
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Sorry I don't speak Arabic or Farsi. But I do speak php. Can you clarify what exactly you are trying to do? I might be able to help you if I understood better what it is you want the script to accomplish.
     
    dankenpo, Jun 26, 2007 IP
  3. promotingspace.net

    promotingspace.net Peon

    Messages:
    361
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Many thanks for your enthusiasm to assist me solving the problem.
    I looked through the codes and replaced the array elements and got the form right to left. It's ok now. If I had any other question, I'll post them on the forum.
    Thanks again:)
     
    promotingspace.net, Jun 27, 2007 IP
  4. promotingspace.net

    promotingspace.net Peon

    Messages:
    361
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi
    Please look at the function below that I include and use it in my protected pages ( that requires login):

    function membersOnly() {
    		if (!$_SESSION['logged']) {
    			$_SESSION['log_to'] = $_SERVER['REQUEST_URI'];
    			die('This page is available only to registered members,
    				you have to <a href="login.php">login</a> first, if ' .
    				"you haven't" . ' <a href="signup.php">registered</a> ' .
    				 'yet you can do that for free.');
    		}
    	}
    
    PHP:
    This makes the protected pages almost blank to users when they have not logged in. like this:
    http://pedia.sys17.net/protected.htm
    But it's too bad. and I want it like this:
    http://pedia.sys17.net/wantprolikethis.htm
    How can I do that?
    Thanks
     
    promotingspace.net, Jun 27, 2007 IP
  5. dankenpo

    dankenpo Guest

    Messages:
    30
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    instead of a text string in the die(' function, just use the URL of that page you want it to look like.
     
    dankenpo, Jun 29, 2007 IP