Re: [PHP] Members area Login with permissions!

2011-07-24 Thread Negin Nickparsa
you didn't set the $message

for example here that you mentioned:
You have successfuly been logged in. You can now access
the advanced area.

change it to $message="You have successfuly been logged in. You can now
access the advanced area";

hope it will help.


RE: [PHP] Members area Login with permissions!

2011-07-24 Thread Dajka Tamas
Hi,

I don't see any redirection in your script! It just displays the link to the
corresponding next homepage based on the user level. To really redirect, you
should user "header ('Location: URL');". Be aware, that if you pass ANY
content out, the additional headers can't be set, so either use output
buffer in php.ini, or ob_start somewhere. And hope you do session_start() in
config.php ;)

Cheers,

Tamas

-Original Message-
From: alekto [mailto:alekto.antarct...@gmail.com] 
Sent: Sunday, July 24, 2011 1:28 AM
To: php-general@lists.php.net
Subject: [PHP] Members area Login with permissions!

Hi,
I need some help with my html/php, restricted access script. 
The purpose with this script is to let users login to a members area; some
with admin permission, some with newbe permission and some with advanced
permissions. The permissions are pre-defined in the MySQL-DB with a
use_level-field in the user-table. 

The different user-groups should have access to the following content:

admin - permissions to everything (for now the same as advanced)
advanced - lecture 1 and lecture 2
newbe - only lecture 1

The problem with this script is that it does not redirect the different user
groups to their repective index-pages, please help me to detect why!




http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
http://www.w3.org/1999/xhtml";>
   
   
   
   Connexion
   
   
   
   
   

You have successfuly been loged out.
Home
0)
   {
   //If the password is good, we dont show the form
   $form = false;
   //We save the user name in the session username and
the user Id in the session userid
   $_SESSION['username'] = $_POST['username'];
   $_SESSION['userid'] = $dn['id'];

if($usr_level == 1)
   {
 ?>
You have successfuly been logged in. You can now access
the admin area.
Home

You have successfuly been logged in. You can now access
to the newbe area.
Home

You have successfuly been logged in. You can now access
the advanced area.
Home
'.$message.'';
   }
   //We display the form
?>

   
   Please type your IDs to log in:
   
   Username
   Password
   
   
   


   Go
Home
   



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Members area Login with permissions!

2011-07-24 Thread Dajka Tamas
One more thought, why not separating the things? I mean separate HTML with a
template engine ( like Smarty ) and separate PHP code (  also separated to
files ).

Like:

index.php:

if ( ! $_session['username'] ) {
$_SESSION['message'] = "Please log in";
header('Location: login.php');
}

//process $_Session['message'] if any, and assign it to template variable,
etc

switch ( $_session['username'] ) {

case '10':
//processing, template display
break;
case '11':
//processing, template display
break;
}

---

login.php:

if ( $_POST['username'] & $_POST['password'] ) {
//process login
if ( $login_ok ) {
$_SESSION['message'] = MESSAGE;
header('Locatin: index.php');   
} else {
$_SESSION['message'] = MESSAGE;
}
}

//display login form, with message, if any ( bad user name, etc )

--

On more complex sites, you may want to use classes, so the PHP code gets
really separated and clean.

If you decide to a template engine, you may also want to create a global
$conf var and export that to the engine, so you can set the design, lang
code, etc from one variable.


Let me know, if I can helo you further :)

Cheers,

Tamas


-Original Message-
From: Dajka Tamas [mailto:vi...@vipernet.hu] 
Sent: Sunday, July 24, 2011 11:53 AM
To: 'alekto'; php-general@lists.php.net
Subject: RE: [PHP] Members area Login with permissions!

Hi,

I don't see any redirection in your script! It just displays the link to the
corresponding next homepage based on the user level. To really redirect, you
should user "header ('Location: URL');". Be aware, that if you pass ANY
content out, the additional headers can't be set, so either use output
buffer in php.ini, or ob_start somewhere. And hope you do session_start() in
config.php ;)

Cheers,

Tamas

-Original Message-
From: alekto [mailto:alekto.antarct...@gmail.com] 
Sent: Sunday, July 24, 2011 1:28 AM
To: php-general@lists.php.net
Subject: [PHP] Members area Login with permissions!

Hi,
I need some help with my html/php, restricted access script. 
The purpose with this script is to let users login to a members area; some
with admin permission, some with newbe permission and some with advanced
permissions. The permissions are pre-defined in the MySQL-DB with a
use_level-field in the user-table. 

The different user-groups should have access to the following content:

admin - permissions to everything (for now the same as advanced)
advanced - lecture 1 and lecture 2
newbe - only lecture 1

The problem with this script is that it does not redirect the different user
groups to their repective index-pages, please help me to detect why!




http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
http://www.w3.org/1999/xhtml";>
   
   
   
   Connexion
   
   
   
   
   

You have successfuly been loged out.
Home
0)
   {
   //If the password is good, we dont show the form
   $form = false;
   //We save the user name in the session username and
the user Id in the session userid
   $_SESSION['username'] = $_POST['username'];
   $_SESSION['userid'] = $dn['id'];

if($usr_level == 1)
   {
 ?>
You have successfuly been logged in. You can now access
the admin area.
Home

You have successfuly been logged in. You can now access
to the newbe area.
Home

You have successfuly been logged in. You can now access
the advanced area.
Home
'.$message.'';
   }
   //We display the form
?>

   
   Please type your IDs to log in:
   
   Username
   Password
   
   
   


   Go
Home
   



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Members area Login with permissions!

2011-07-24 Thread alekto
Hi,

thank you for answering! I do have a session_start() in config.php.
For now there is no redirection as you mentioned, but it should display a link 
to 
the corresponding next homepage based on user level, which it does not do at 
this time!

I thought  was only a class? I already have a $message 
variable that do display:
$message = 'The username or password is incorrect.';

When it comes to separating the code, I think this is a good idea, afraid this 
will mess the code further up to do at this point?!
 
Regards



Den 24. juli 2011 kl. 11.52 skrev Dajka Tamas:

> Hi,
> 
> I don't see any redirection in your script! It just displays the link to the
> corresponding next homepage based on the user level. To really redirect, you
> should user "header ('Location: URL');". Be aware, that if you pass ANY
> content out, the additional headers can't be set, so either use output
> buffer in php.ini, or ob_start somewhere. And hope you do session_start() in
> config.php ;)
> 
> Cheers,
> 
>   Tamas
> 
> -Original Message-
> From: alekto [mailto:alekto.antarct...@gmail.com] 
> Sent: Sunday, July 24, 2011 1:28 AM
> To: php-general@lists.php.net
> Subject: [PHP] Members area Login with permissions!
> 
> Hi,
> I need some help with my html/php, restricted access script. 
> The purpose with this script is to let users login to a members area; some
> with admin permission, some with newbe permission and some with advanced
> permissions. The permissions are pre-defined in the MySQL-DB with a
> use_level-field in the user-table. 
> 
> The different user-groups should have access to the following content:
> 
> admin - permissions to everything (for now the same as advanced)
> advanced - lecture 1 and lecture 2
> newbe - only lecture 1
> 
> The problem with this script is that it does not redirect the different user
> groups to their repective index-pages, please help me to detect why!
> 
> 
> 
>  include('config.php');
> ?>
>  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> http://www.w3.org/1999/xhtml";>
>   
>   
>title="Style" />
>   Connexion
>   
>   
>   
>   
>   
>  //If the user is logged, we log him out
> if(isset($_SESSION['username']))
> {
>   //We log him out by deleting the username and userid sessions
>   unset($_SESSION['username'], $_SESSION['userid']);
> ?>
> You have successfuly been loged out.
> Home
>  }
> else
> {
>   $ousername = '';
>   //We check if the form has been sent
>   if(isset($_POST['username'], $_POST['password']))
>   {
>   //We remove slashes depending on the configuration
>   if(get_magic_quotes_gpc())
>   {
>   $ousername = stripslashes($_POST['username']);
>   $username =
> mysql_real_escape_string(stripslashes($_POST['username']));
>   $password = stripslashes($_POST['password']);
>   }
>   else
>   {
>   $username =
> mysql_real_escape_string($_POST['username']);
>   $password = $_POST['password'];
>   }
>   //We get the password of the user
>   $req = mysql_query('select password,id,usr_level from users
> where username="'.$username.'"');
>   $dn = mysql_fetch_array($req);
>   //Get user level of the user
>   $usr_level = $req['usr_level'];
> 
>   //We compare the submited password and the real one, and we
> check if the user exists
>   if($dn['password']==$password and mysql_num_rows($req)>0)
>   {
>   //If the password is good, we dont show the form
>   $form = false;
>   //We save the user name in the session username and
> the user Id in the session userid
>   $_SESSION['username'] = $_POST['username'];
>   $_SESSION['userid'] = $dn['id'];
> 
>if($usr_level == 1)
>   {
> ?>
> You have successfuly been logged in. You can now access
> the admin area.
> Home
>}
>   if($usr_level == 10)
>   {
>   ?>
> You have successfuly been logged in. You can now access
> to the newbe area.
> Home
>}
>   if($usr_level == 11)
>   {
>   ?>
> You have successfuly been logged in. You can now access
> the advanced area.
> Home
>} 
> 
>   }
>   else
>   {
>   //Otherwise, we say the password is incorrect.
>   $form = true;
>   $message = 'The username or password is incorrect.';
>   }
>   }
>   else
>   {
>   $form = true;
>   }
>

RE: [PHP] Members area Login with permissions!

2011-07-24 Thread Dajka Tamas
Hi,

 

yes, class="message" just sets the HTML class for that div element.

 

BTW, I've found the error:

 

 

  //We get the password of the user

  $req = mysql_query('select password,id,usr_level from users
where username="'.$username.'"');

  $dn = mysql_fetch_array($req);

  //Get user level of the user

  $usr_level = $req['usr_level'];

 

You're setting $usr_level from a mysql_resource! So it's always null ( you
would have guessed it by adding a var_dump($usr_level); after setting
$usr_level ). 

 

The fix: just change it to:

 

   $usr_level = $dn['usr_level'];

 

Cheers,

 

   Tamas

 

 

 

From: alekto [mailto:alekto.antarct...@gmail.com] 
Sent: Sunday, July 24, 2011 1:00 PM
To: Dajka Tamas
Cc: php-general@lists.php.net
Subject: Re: [PHP] Members area Login with permissions!

 

Hi,

 

thank you for answering! I do have a session_start() in config.php.

For now there is no redirection as you mentioned, but it should display a
link to 

the corresponding next homepage based on user level, which it does not do at
this time!

 

I thought  was only a class? I already have a $message
variable that do display:

$message = 'The username or password is incorrect.';

 

When it comes to separating the code, I think this is a good idea, afraid
this will mess the code further up to do at this point?!

 

Regards

 

 

 

Den 24. juli 2011 kl. 11.52 skrev Dajka Tamas:





Hi,

I don't see any redirection in your script! It just displays the link to the
corresponding next homepage based on the user level. To really redirect, you
should user "header ('Location: URL');". Be aware, that if you pass ANY
content out, the additional headers can't be set, so either use output
buffer in php.ini, or ob_start somewhere. And hope you do session_start() in
config.php ;)

Cheers,

Tamas

-Original Message-
From: alekto [mailto:alekto.antarct...@gmail.com] 
Sent: Sunday, July 24, 2011 1:28 AM
To: php-general@lists.php.net
Subject: [PHP] Members area Login with permissions!

Hi,
I need some help with my html/php, restricted access script. 
The purpose with this script is to let users login to a members area; some
with admin permission, some with newbe permission and some with advanced
permissions. The permissions are pre-defined in the MySQL-DB with a
use_level-field in the user-table. 

The different user-groups should have access to the following content:

admin - permissions to everything (for now the same as advanced)
advanced - lecture 1 and lecture 2
newbe - only lecture 1

The problem with this script is that it does not redirect the different user
groups to their repective index-pages, please help me to detect why!




http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
http://www.w3.org/1999/xhtml";>
  
  
  
  Connexion
  
  
  
  
  

You have successfuly been loged out.
Home
0)
  {
  //If the password is good, we dont show the form
  $form = false;
  //We save the user name in the session username and
the user Id in the session userid
  $_SESSION['username'] = $_POST['username'];
  $_SESSION['userid'] = $dn['id'];

   if($usr_level == 1)
  {
?>
You have successfuly been logged in. You can now access
the admin area.
Home

You have successfuly been logged in. You can now access
to the newbe area.
Home

You have successfuly been logged in. You can now access
the advanced area.
Home
'.$message.'';
  }
  //We display the form
?>

  
  Please type your IDs to log in:
  
  Username
  Password
  
  
  


  Go
Home
  


 



RE: [PHP] Members area Login with permissions!

2011-07-24 Thread Dajka Tamas
I don't think, that separating the code messes up anything, cos it's just
separating processing/displaying and you can always debug processing by
adding some "echo $var", print_r($var) or var_dump($var). Moreover, by
separating the PHP and HTML you get clearer code for both, giving easier
debugging,

 

   Tamas

 

From: alekto [mailto:alekto.antarct...@gmail.com] 
Sent: Sunday, July 24, 2011 1:00 PM
To: Dajka Tamas
Cc: php-general@lists.php.net
Subject: Re: [PHP] Members area Login with permissions!

 

Hi,

 

thank you for answering! I do have a session_start() in config.php.

For now there is no redirection as you mentioned, but it should display a
link to 

the corresponding next homepage based on user level, which it does not do at
this time!

 

I thought  was only a class? I already have a $message
variable that do display:

$message = 'The username or password is incorrect.';

 

When it comes to separating the code, I think this is a good idea, afraid
this will mess the code further up to do at this point?!

 

Regards

 

 

 

Den 24. juli 2011 kl. 11.52 skrev Dajka Tamas:





Hi,

I don't see any redirection in your script! It just displays the link to the
corresponding next homepage based on the user level. To really redirect, you
should user "header ('Location: URL');". Be aware, that if you pass ANY
content out, the additional headers can't be set, so either use output
buffer in php.ini, or ob_start somewhere. And hope you do session_start() in
config.php ;)

Cheers,

Tamas

-Original Message-
From: alekto [mailto:alekto.antarct...@gmail.com] 
Sent: Sunday, July 24, 2011 1:28 AM
To: php-general@lists.php.net
Subject: [PHP] Members area Login with permissions!

Hi,
I need some help with my html/php, restricted access script. 
The purpose with this script is to let users login to a members area; some
with admin permission, some with newbe permission and some with advanced
permissions. The permissions are pre-defined in the MySQL-DB with a
use_level-field in the user-table. 

The different user-groups should have access to the following content:

admin - permissions to everything (for now the same as advanced)
advanced - lecture 1 and lecture 2
newbe - only lecture 1

The problem with this script is that it does not redirect the different user
groups to their repective index-pages, please help me to detect why!




http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
http://www.w3.org/1999/xhtml";>
  
  
  
  Connexion
  
  
  
  
  

You have successfuly been loged out.
Home
0)
  {
  //If the password is good, we dont show the form
  $form = false;
  //We save the user name in the session username and
the user Id in the session userid
  $_SESSION['username'] = $_POST['username'];
  $_SESSION['userid'] = $dn['id'];

   if($usr_level == 1)
  {
?>
You have successfuly been logged in. You can now access
the admin area.
Home

You have successfuly been logged in. You can now access
to the newbe area.
Home

You have successfuly been logged in. You can now access
the advanced area.
Home
'.$message.'';
  }
  //We display the form
?>

  
  Please type your IDs to log in:
  
  Username
  Password
  
  
  


  Go
Home
  


 



[PHP] Closing PHP tag best practice?

2011-07-24 Thread Geoff Lane
Hi All,

While watching one of Jeffrey Way's CodeIgniter tutorials, I was
gobsmacked when he noted that it was best practice not to have closing
PHP tags as closing tags might introduce whitespace issues. So I tried
syntax checking a few simple pages and, to my surprise, the syntax
checkers accepted the pages even though the closing "?>" was missing.

However, I suspect that there may be issues with this. For example,
what happens if you include or require something that has no closing
PHP tag? For example, consider two files:

File: test_inner.php 8<--



---8<

I thought that there might be an issue with the parser attemting to
parse the closing body and html tags as PHP, so I ran a check on one
of my development machines with the above files and there was no
error. It seems that, on my development machine at least, a PHP code
block can be closed either explicitly (with '?>') or implicitly by the
EOF! However, experience has shown me that what works on one server
might not work on all of them as there are so many configuration
options and so many versions of PHP 'in the wild'.

So, is Jeffrey correct when he says that omitting the closing PHP tag
is best practice? Also, are there any 'gotchas' to doing this?

TIA,

-- 
Geoff


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Closing PHP tag best practice?

2011-07-24 Thread mrfroasty
What I know its a best practice to leave the closing tag in a script
with one php opening tag.Mostly this applies in a script that present a
class, I think its not correct to leave closing tags in  template kind
of script where you have several php tags.

Gr
Muhsin


On 07/24/2011 02:33 PM, Geoff Lane wrote:
> Hi All,
>
> While watching one of Jeffrey Way's CodeIgniter tutorials, I was
> gobsmacked when he noted that it was best practice not to have closing
> PHP tags as closing tags might introduce whitespace issues. So I tried
> syntax checking a few simple pages and, to my surprise, the syntax
> checkers accepted the pages even though the closing "?>" was missing.
>
> However, I suspect that there may be issues with this. For example,
> what happens if you include or require something that has no closing
> PHP tag? For example, consider two files:
>
> File: test_inner.php 8<--
>echo "This is the inner code\n";
> ---8<
>
> File: test_outer.php 8<--
> 
>include ('test_inner.php');
>   echo "This is the outer code\n";
> ?>
> 
> ---8<
>
> I thought that there might be an issue with the parser attemting to
> parse the closing body and html tags as PHP, so I ran a check on one
> of my development machines with the above files and there was no
> error. It seems that, on my development machine at least, a PHP code
> block can be closed either explicitly (with '?>') or implicitly by the
> EOF! However, experience has shown me that what works on one server
> might not work on all of them as there are so many configuration
> options and so many versions of PHP 'in the wild'.
>
> So, is Jeffrey correct when he says that omitting the closing PHP tag
> is best practice? Also, are there any 'gotchas' to doing this?
>
> TIA,
>


-- 
Extra details:
OSS:Gentoo Linux
profile:x86
Hardware:msi geforce 8600GT asus p5k-se
location:/home/muhsin
language(s):C/C++,PHP,SQL,HTML
Typo:40WPM
url:http://www.mzalendo.net
url:http://www.zanbytes.com




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Members area Login with permissions!

2011-07-24 Thread alekto
Thanks a lot :)
This solved the user level issue, I can now login with different user levels 
and get displayed with a link to the corresponding index-pages.
But I am now facing a new issue regarding this; when I am entering the URL's of 
the corresponding index-pages I do get access to the 
corresponding index-pages without having to login at all!! Is there a way to 
prevent this form happening? 

And is there also a way to hide the 
URL's that goes beyond www.url.com, e.i. www.url.com/index_admin.php?


Regard


Den 24. juli 2011 kl. 13.26 skrev Dajka Tamas:

> Hi,
>  
> yes, class=”message” just sets the HTML class for that div element.
>  
> BTW, I’ve found the error:
>  
>  
>   //We get the password of the user
>   $req = mysql_query('select password,id,usr_level from users 
> where username="'.$username.'"');
>   $dn = mysql_fetch_array($req);
>   //Get user level of the user
>   $usr_level = $req['usr_level'];
>  
> You’re setting $usr_level from a mysql_resource! So it’s always null ( you 
> would have guessed it by adding a var_dump($usr_level); after setting 
> $usr_level ).
>  
> The fix: just change it to:
>  
>$usr_level = $dn[’usr_level’];
>  
> Cheers,
>  
>Tamas
>  
>  
>  
> From: alekto [mailto:alekto.antarct...@gmail.com] 
> Sent: Sunday, July 24, 2011 1:00 PM
> To: Dajka Tamas
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Members area Login with permissions!
>  
> Hi,
>  
> thank you for answering! I do have a session_start() in config.php.
> For now there is no redirection as you mentioned, but it should display a 
> link to 
> the corresponding next homepage based on user level, which it does not do at 
> this time!
>  
> I thought  was only a class? I already have a $message 
> variable that do display:
> $message = 'The username or password is incorrect.';
>  
> When it comes to separating the code, I think this is a good idea, afraid 
> this will mess the code further up to do at this point?!
>  
> Regards
>  
>  
>  
> Den 24. juli 2011 kl. 11.52 skrev Dajka Tamas:
> 
> 
> Hi,
> 
> I don't see any redirection in your script! It just displays the link to the
> corresponding next homepage based on the user level. To really redirect, you
> should user "header ('Location: URL');". Be aware, that if you pass ANY
> content out, the additional headers can't be set, so either use output
> buffer in php.ini, or ob_start somewhere. And hope you do session_start() in
> config.php ;)
> 
> Cheers,
> 
> Tamas
> 
> -Original Message-
> From: alekto [mailto:alekto.antarct...@gmail.com] 
> Sent: Sunday, July 24, 2011 1:28 AM
> To: php-general@lists.php.net
> Subject: [PHP] Members area Login with permissions!
> 
> Hi,
> I need some help with my html/php, restricted access script. 
> The purpose with this script is to let users login to a members area; some
> with admin permission, some with newbe permission and some with advanced
> permissions. The permissions are pre-defined in the MySQL-DB with a
> use_level-field in the user-table. 
> 
> The different user-groups should have access to the following content:
> 
> admin - permissions to everything (for now the same as advanced)
> advanced - lecture 1 and lecture 2
> newbe - only lecture 1
> 
> The problem with this script is that it does not redirect the different user
> groups to their repective index-pages, please help me to detect why!
> 
> 
> 
>  include('config.php');
> ?>
>  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> http://www.w3.org/1999/xhtml";>
>   
>   
>title="Style" />
>   Connexion
>   
>   
>   
>   
>   
>  //If the user is logged, we log him out
> if(isset($_SESSION['username']))
> {
>   //We log him out by deleting the username and userid sessions
>   unset($_SESSION['username'], $_SESSION['userid']);
> ?>
> You have successfuly been loged out.
> Home
>  }
> else
> {
>   $ousername = '';
>   //We check if the form has been sent
>   if(isset($_POST['username'], $_POST['password']))
>   {
>   //We remove slashes depending on the configuration
>   if(get_magic_quotes_gpc())
>   {
>   $ousername = stripslashes($_POST['username']);
>   $username =
> mysql_real_escape_string(stripslashes($_POST['username']));
>   $password = stripslashes($_POST['password']);
>   }
>   else
>   {
>   $username =
> mysql_real_escape_string($_POST['username']);
>   $password = $_POST['password'];
>   }
>   //We get the password of the user
>   $req = mysql_query('select password,id,usr_level from users
> where username="'.$username.'"');
>   $dn = mysql_fetch_array($req);
>   //Get user level of the user
>   $usr_le

RE: [PHP] Members area Login with permissions!

2011-07-24 Thread Dajka Tamas
You're welcome J

 

Yes, you can hide the urls, just google for "url rewriting" or "seo urls".
Unfortunatelly, this is not basic level stuff and you cannot hide completly
the urls.

 

About your issue: that's why I've added to my example's index.php this line:

 

if ( ! $_session['username'] ) {

  $_SESSION['message'] = "Please log in";

  header('Location: login.php');

}

 

For your situation, I would change it a bit ( for ANY index pages, which is
not a login page ):

 

if ( ! $_SESSION['username'] || $_SESSION['usr_level'] !=
CURRENT_SITE_PERMISSION ) {

  //we set a message in session to the user

$_SESSION['message'] = "Please log in";

//we redirect the user to the login page

  header('Location: index.php');

}

 

This will redirect an unlogged user to the login form ( if logged in, but
has no access rights, your login page will log out the user ).

 

Don't forget to store the users' access level in the session, or this will
not work!

 

Cheers,

 

   Tamas

 

From: alekto [mailto:alekto.antarct...@gmail.com] 
Sent: Sunday, July 24, 2011 3:23 PM
To: Dajka Tamas
Cc: php-general@lists.php.net
Subject: Re: [PHP] Members area Login with permissions!

 

Thanks a lot :)

This solved the user level issue, I can now login with different user levels
and get displayed with a link to the corresponding index-pages.

But I am now facing a new issue regarding this; when I am entering the URL's
of the corresponding index-pages I do get access to the 

corresponding index-pages without having to login at all!! Is there a way to
prevent this form happening? 

 

And is there also a way to hide the 

URL's that goes beyond www.url.com, e.i. www.url.com/index_admin.php?

 

 

Regard

 

 

Den 24. juli 2011 kl. 13.26 skrev Dajka Tamas:





Hi,

 

yes, class="message" just sets the HTML class for that div element.

 

BTW, I've found the error:

 

 

  //We get the password of the user

  $req = mysql_query('select password,id,usr_level from users
where username="'.$username.'"');

  $dn = mysql_fetch_array($req);

  //Get user level of the user

  $usr_level = $req['usr_level'];

 

You're setting $usr_level from a mysql_resource! So it's always null ( you
would have guessed it by adding a var_dump($usr_level); after setting
$usr_level ).

 

The fix: just change it to:

 

   $usr_level = $dn['usr_level'];

 

Cheers,

 

   Tamas

 

 

 

From: alekto [mailto:alekto.antarct...@gmail.com] 
Sent: Sunday, July 24, 2011 1:00 PM
To: Dajka Tamas
Cc: php-general@lists.php.net
Subject: Re: [PHP] Members area Login with permissions!

 

Hi,

 

thank you for answering! I do have a session_start() in config.php.

For now there is no redirection as you mentioned, but it should display a
link to 

the corresponding next homepage based on user level, which it does not do at
this time!

 

I thought  was only a class? I already have a $message
variable that do display:

$message = 'The username or password is incorrect.';

 

When it comes to separating the code, I think this is a good idea, afraid
this will mess the code further up to do at this point?!

 

Regards

 

 

 

Den 24. juli 2011 kl. 11.52 skrev Dajka Tamas:






Hi,

I don't see any redirection in your script! It just displays the link to the
corresponding next homepage based on the user level. To really redirect, you
should user "header ('Location: URL');". Be aware, that if you pass ANY
content out, the additional headers can't be set, so either use output
buffer in php.ini, or ob_start somewhere. And hope you do session_start() in
config.php ;)

Cheers,

Tamas

-Original Message-
From: alekto [mailto:alekto.antarct...@gmail.com] 
Sent: Sunday, July 24, 2011 1:28 AM
To: php-general@lists.php.net
Subject: [PHP] Members area Login with permissions!

Hi,
I need some help with my html/php, restricted access script. 
The purpose with this script is to let users login to a members area; some
with admin permission, some with newbe permission and some with advanced
permissions. The permissions are pre-defined in the MySQL-DB with a
use_level-field in the user-table. 

The different user-groups should have access to the following content:

admin - permissions to everything (for now the same as advanced)
advanced - lecture 1 and lecture 2
newbe - only lecture 1

The problem with this script is that it does not redirect the different user
groups to their repective index-pages, please help me to detect why!




http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
http://www.w3.org/1999/xhtml";>
  
  
  
  Connexion
  
  
  
  
  

You have successfuly been loged out.
Home
0)
  {
  //If the password is good, we dont show the form
  $form = false;
  //We save the user name in the session username and
the user Id in t

Re: [PHP] Closing PHP tag best practice?

2011-07-24 Thread Ashley Sheridan
On Sun, 2011-07-24 at 14:55 +0200, mrfroasty wrote:

> What I know its a best practice to leave the closing tag in a script
> with one php opening tag.Mostly this applies in a script that present a
> class, I think its not correct to leave closing tags in  template kind
> of script where you have several php tags.
> 
> Gr
> Muhsin
> 
> 
> On 07/24/2011 02:33 PM, Geoff Lane wrote:
> > Hi All,
> >
> > While watching one of Jeffrey Way's CodeIgniter tutorials, I was
> > gobsmacked when he noted that it was best practice not to have closing
> > PHP tags as closing tags might introduce whitespace issues. So I tried
> > syntax checking a few simple pages and, to my surprise, the syntax
> > checkers accepted the pages even though the closing "?>" was missing.
> >
> > However, I suspect that there may be issues with this. For example,
> > what happens if you include or require something that has no closing
> > PHP tag? For example, consider two files:
> >
> > File: test_inner.php 8<--
> >  >   echo "This is the inner code\n";
> > ---8<
> >
> > File: test_outer.php 8<--
> > 
> >  >   include ('test_inner.php');
> >   echo "This is the outer code\n";
> > ?>
> > 
> > ---8<
> >
> > I thought that there might be an issue with the parser attemting to
> > parse the closing body and html tags as PHP, so I ran a check on one
> > of my development machines with the above files and there was no
> > error. It seems that, on my development machine at least, a PHP code
> > block can be closed either explicitly (with '?>') or implicitly by the
> > EOF! However, experience has shown me that what works on one server
> > might not work on all of them as there are so many configuration
> > options and so many versions of PHP 'in the wild'.
> >
> > So, is Jeffrey correct when he says that omitting the closing PHP tag
> > is best practice? Also, are there any 'gotchas' to doing this?
> >
> > TIA,
> >
> 
> 
> -- 
> Extra details:
> OSS:Gentoo Linux
> profile:x86
> Hardware:msi geforce 8600GT asus p5k-se
> location:/home/muhsin
> language(s):C/C++,PHP,SQL,HTML
> Typo:40WPM
> url:http://www.mzalendo.net
> url:http://www.zanbytes.com
> 
> 
> 
> 



The PHP parser will automatically "add" the closing tag when it reaches
the end of the file, so you don't have to worry about the final closing
tag. This is perfectly valid:




some content
copyright' . date('Y') . '

Not the missing closing ?> tag and that this isn't a pure PHP script,
but it mixes in HTML too.

As for best practices, it can be if you're using this on an include
file, such as a class, where any whitespace after the closing ?> tag
would be considered output, which can lead to header issues later on
down the line.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk




[PHP] Three new versions of EasyPHP (WAMP package) with PHP 5.3.6, 5.3.7 RC3 and 5.4.0 alpha2

2011-07-24 Thread EasyPHP
Those versions are important ones. For the first time, you can
configure Apache (httpd.conf) and PHP (php.ini) directly from the
administration page. Thus, you can adapt easily the environment to
your needs.

Screenshots : www.easyphp.org/screenshots.php

EasyPHP is 11 years old now. It exists since 2000 (we were dealing
with PHP/Fi, PHP2 at this time). This is the first WAMP package ever
created.
EasyPHP can be installed anywhere : hard drive, USB drive...
You can also install modules (WordPress, Drupal, Joomla!, Prestashop,
Spip...). That means that you can install a version of WordPress,
Spip, Prestashop, Drupal... and test it immediately. It's
pre-configured. Perfect if you want to discover the last version of an
application.

Through the administration you can easily list the docroot,
extensions, change the Apache port, the timezone, max execution time,
error reporting, upload max filesize, add/remove alias, manage
modules...

Website : www.easyphp.org
Facebook page : www.facebook.com/easywamp
Twitter : www.twitter.com/easyphp
Sourceforge : www.sourceforge.net/projects/quickeasyphp/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Segmentation Fault

2011-07-24 Thread Floyd Resler

On Jul 23, 2011, at 9:14 PM, Nilesh Govindarajan wrote:

> On 07/23/2011 09:38 PM, Floyd Resler wrote:
>> I moved to our new server which is using 5.3.2.  I'm getting a segmentation 
>> fault error on certain ODBC queries I run.  For some reason when I ask for 
>> particular columns from the database table I get the error.  The error is 
>> Program received signal SIGSEGV, Segmentation fault.
>> 0x7530df1a in memcpy () from /lib/libc.so.6
>> 
>> Does anyone have any ideas why this is happening?
>> 
>> Thanks!
>> Floyd
>> 
>> 
> 
> There is something fishy about libc, php or the odbc driver you are
> using on the new server. Try recompiling php, odbc. You wouldn't be able
> to compile libc, unless you're using a source based distribution like
> gentoo.
> 

I'll give that a shot.  I've been just using the standard installs for Ubuntu 
10.04.

Thanks!
Floyd


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Use of preg_replace

2011-07-24 Thread Tim Streater
I need to be able to convert a line of the form:

>>>From

to have either one more or one less > at the front. A web site tells me that 
the regexps to use are:

1,$s/^>*From />&/

and

1,$s/^>(>*From )/\1/

respectively (there is a single space after "From"). So, if my text string is 
in $line, I ought to be able to do something like:

$line = preg_replace ($pattern, $replacement, $line);

But, since all regexps are to me, like TECO commands, no better than 
line-noise, how do I make up $pattern and $replacement from the proffered 
regexps?

Thanks.

--
Cheers  --  Tim

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: [PHP] Use of preg_replace

2011-07-24 Thread Dajka Tamás
Hi,

I lost trail, what do you want to do?

You want to convert

>>>From

to this:

>>From

Or what's the goal?

Cheers,

Tamas

-Original Message-
From: Tim Streater [mailto:t...@clothears.org.uk] 
Sent: Sunday, July 24, 2011 8:07 PM
To: PHP General List
Subject: [PHP] Use of preg_replace

I need to be able to convert a line of the form:

>>>From

to have either one more or one less > at the front. A web site tells me that 
the regexps to use are:

1,$s/^>*From />&/

and

1,$s/^>(>*From )/\1/

respectively (there is a single space after "From"). So, if my text string is 
in $line, I ought to be able to do something like:

$line = preg_replace ($pattern, $replacement, $line);

But, since all regexps are to me, like TECO commands, no better than 
line-noise, how do I make up $pattern and $replacement from the proffered 
regexps?

Thanks.

--
Cheers  --  Tim



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: RE: [PHP] Use of preg_replace

2011-07-24 Thread Tim Streater
On 24 Jul 2011 at 19:35, Dajka Tamás  wrote: 

> I lost trail, what do you want to do?
>
> You want to convert
>
 From
>
> to this:
>
>>> From

The number of > in front of "From " is not known. I want to be able to add or 
remove one.

--
Cheers  --  Tim

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: RE: [PHP] Use of preg_replace

2011-07-24 Thread Dajka Tamás
You want to do it in a greater text, I think.


1,$s/^>(>*From )/\1/


$line = preg_replace ($pattern, $replacement, $line);


Adding one '>':

preg_replace('/(^[>]+From )/','>$1', $line)

Removing one '>':

preg_replace('/(^>([>]+From )/','$1', $line)

Cheers,

Tamas

-Original Message-
From: Tim Streater [mailto:t...@clothears.org.uk] 
Sent: Sunday, July 24, 2011 8:51 PM
To: Dajka Tamás; PHP General List
Subject: Re: RE: [PHP] Use of preg_replace

On 24 Jul 2011 at 19:35, Dajka Tamás  wrote: 

> I lost trail, what do you want to do?
>
> You want to convert
>
 From
>
> to this:
>
>>> From

The number of > in front of "From " is not known. I want to be able to add or 
remove one.

--
Cheers  --  Tim



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: RE: RE: [PHP] Use of preg_replace

2011-07-24 Thread Tim Streater
On 24 Jul 2011 at 19:57, Dajka Tamás  wrote: 

> You want to do it in a greater text, I think.
>
> 1,$s/^>(>*From )/\1/
>
> $line = preg_replace ($pattern, $replacement, $line);
>
> Adding one '>':
>
> preg_replace('/(^[>]+From )/','>$1', $line)
>
> Removing one '>':
>
> preg_replace('/(^>([>]+From )/','$1', $line)

Thanks, I'll try that.

--
Cheers  --  Tim

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: RE: RE: [PHP] Use of preg_replace

2011-07-24 Thread Tim Streater
On 24 Jul 2011 at 19:57, Dajka Tamás  wrote: 

> You want to do it in a greater text, I think.

See below.

> 1,$s/^>(>*From )/\1/
>
> $line = preg_replace ($pattern, $replacement, $line);
>
> Adding one '>':
>
> preg_replace('/(^[>]+From )/','>$1', $line)
>
> Removing one '>':
>
> preg_replace('/(^>([>]+From )/','$1', $line)
 ^
 |
Missing ) ---+

In fact I forgot to mention that the string always starts at the start of the 
line. So, I experimented a bit and the following works:


$onemore = preg_replace ('/^(>*From )/', '>$1', $line);
$oneless = preg_replace ('/^>(>*From )/', '$1', $line);

Thanks for the help.

--
Cheers  --  Tim

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Members area Login with permissions!

2011-07-24 Thread alekto
One again, Thank you!! Your excellent advice saved my day ;)



Den 24. juli 2011 kl. 16.07 skrev Dajka Tamas:

> You’re welcome J
>  
> Yes, you can hide the urls, just google for „url rewriting” or „seo urls”. 
> Unfortunatelly, this is not basic level stuff and you cannot hide completly 
> the urls…
>  
> About your issue: that’s why I’ve added to my example’s index.php this line:
>  
> if ( ! $_session['username'] ) {
>   $_SESSION['message'] = "Please log in";
>   header('Location: login.php');
> }
>  
> For your situation, I would change it a bit ( for ANY index pages, which is 
> not a login page ):
>  
> if ( ! $_SESSION['username'] || $_SESSION[’usr_level’] != 
> CURRENT_SITE_PERMISSION ) {
>   //we set a message in session to the user
> $_SESSION['message'] = "Please log in";
> //we redirect the user to the login page
>   header('Location: index.php');
> }
>  
> This will redirect an unlogged user to the login form ( if logged in, but has 
> no access rights, your login page will log out the user ).
>  
> Don’t forget to store the users’ access level in the session, or this will 
> not work!
>  
> Cheers,
>  
>Tamas
>  
> From: alekto [mailto:alekto.antarct...@gmail.com] 
> Sent: Sunday, July 24, 2011 3:23 PM
> To: Dajka Tamas
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Members area Login with permissions!
>  
> Thanks a lot :)
> This solved the user level issue, I can now login with different user levels 
> and get displayed with a link to the corresponding index-pages.
> But I am now facing a new issue regarding this; when I am entering the URL's 
> of the corresponding index-pages I do get access to the 
> corresponding index-pages without having to login at all!! Is there a way to 
> prevent this form happening? 
>  
> And is there also a way to hide the 
> URL's that goes beyond www.url.com, e.i. www.url.com/index_admin.php?
>  
>  
> Regard
>  
>  
> Den 24. juli 2011 kl. 13.26 skrev Dajka Tamas:
> 
> 
> Hi,
>  
> yes, class=”message” just sets the HTML class for that div element.
>  
> BTW, I’ve found the error:
>  
>  
>   //We get the password of the user
>   $req = mysql_query('select password,id,usr_level from users 
> where username="'.$username.'"');
>   $dn = mysql_fetch_array($req);
>   //Get user level of the user
>   $usr_level = $req['usr_level'];
>  
> You’re setting $usr_level from a mysql_resource! So it’s always null ( you 
> would have guessed it by adding a var_dump($usr_level); after setting 
> $usr_level ).
>  
> The fix: just change it to:
>  
>$usr_level = $dn[’usr_level’];
>  
> Cheers,
>  
>Tamas
>  
>  
>  
> From: alekto [mailto:alekto.antarct...@gmail.com] 
> Sent: Sunday, July 24, 2011 1:00 PM
> To: Dajka Tamas
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Members area Login with permissions!
>  
> Hi,
>  
> thank you for answering! I do have a session_start() in config.php.
> For now there is no redirection as you mentioned, but it should display a 
> link to 
> the corresponding next homepage based on user level, which it does not do at 
> this time!
>  
> I thought  was only a class? I already have a $message 
> variable that do display:
> $message = 'The username or password is incorrect.';
>  
> When it comes to separating the code, I think this is a good idea, afraid 
> this will mess the code further up to do at this point?!
>  
> Regards
>  
>  
>  
> Den 24. juli 2011 kl. 11.52 skrev Dajka Tamas:
> 
> 
> 
> Hi,
> 
> I don't see any redirection in your script! It just displays the link to the
> corresponding next homepage based on the user level. To really redirect, you
> should user "header ('Location: URL');". Be aware, that if you pass ANY
> content out, the additional headers can't be set, so either use output
> buffer in php.ini, or ob_start somewhere. And hope you do session_start() in
> config.php ;)
> 
> Cheers,
> 
> Tamas
> 
> -Original Message-
> From: alekto [mailto:alekto.antarct...@gmail.com] 
> Sent: Sunday, July 24, 2011 1:28 AM
> To: php-general@lists.php.net
> Subject: [PHP] Members area Login with permissions!
> 
> Hi,
> I need some help with my html/php, restricted access script. 
> The purpose with this script is to let users login to a members area; some
> with admin permission, some with newbe permission and some with advanced
> permissions. The permissions are pre-defined in the MySQL-DB with a
> use_level-field in the user-table. 
> 
> The different user-groups should have access to the following content:
> 
> admin - permissions to everything (for now the same as advanced)
> advanced - lecture 1 and lecture 2
> newbe - only lecture 1
> 
> The problem with this script is that it does not redirect the different user
> groups to their repective index-pages, please help me to detect why!
> 
> 
> 
>  include('config.php');
> ?>
>  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transiti

Re: [PHP] Three new versions of EasyPHP (WAMP package) with PHP 5.3.6, 5.3.7 RC3 and 5.4.0 alpha2

2011-07-24 Thread Sharl.Jimh.Tsin

On 2011年07月24日 23:42, EasyPHP wrote:

Those versions are important ones. For the first time, you can
configure Apache (httpd.conf) and PHP (php.ini) directly from the
administration page. Thus, you can adapt easily the environment to
your needs.

Screenshots : www.easyphp.org/screenshots.php

EasyPHP is 11 years old now. It exists since 2000 (we were dealing
with PHP/Fi, PHP2 at this time). This is the first WAMP package ever
created.
EasyPHP can be installed anywhere : hard drive, USB drive...
You can also install modules (WordPress, Drupal, Joomla!, Prestashop,
Spip...). That means that you can install a version of WordPress,
Spip, Prestashop, Drupal... and test it immediately. It's
pre-configured. Perfect if you want to discover the last version of an
application.

Through the administration you can easily list the docroot,
extensions, change the Apache port, the timezone, max execution time,
error reporting, upload max filesize, add/remove alias, manage
modules...

Website : www.easyphp.org
Facebook page : www.facebook.com/easywamp
Twitter : www.twitter.com/easyphp
Sourceforge : www.sourceforge.net/projects/quickeasyphp/


Great Job! thanks!

--
Best regards,
Sharl.Jimh.Tsin (From China *Obviously Taiwan INCLUDED*)

Using Gmail? Please read this important notice: 
http://www.fsf.org/campaigns/jstrap/gmail?10073.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP frameworks

2011-07-24 Thread Laruence

Hi:

if you have high performance need, you can considering Yaf( a PHP 
framework which is build in PHP extension)


http://pecl.php.net/package/Yaf

thanks

Best regards

惠新宸 Xinchen Hui
http://www.laruence.com/


On 2011/7/22 20:38, Floyd Resler wrote:

On Jul 22, 2011, at 8:33 AM, Richard Quadling wrote:


On 22 July 2011 13:26, Floyd Resler  wrote:

On Jul 21, 2011, at 11:41 PM, Micky Hulse wrote:


On Thu, Jul 21, 2011 at 6:44 PM, Shawn McKenzie  wrote:

A la CakePHP.  Will automagically build controllers and views for the
admin of your tables/models if you wish.

Oooh, interesting! I will check out CakePHP! Thanks for tip! :)


I actually use my own framework.  I needed a very light weight, flexible 
framework.  I designed it from the ground up to be very flexible and to use 
AJAX and jQuery on the client side.  If you'd be interested in check it out, 
just let me know and I'll give you a link to the source code.

Take care,
Floyd


http://www.brandonsavage.net/why-every-developer-should-write-their-own-framework/


Good article!  I knew there was a reason why I never released mine but just 
offer it up on occasion to someone who might find it useful!  :)

Take care,
Floyd



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php