php-general Digest 25 Jul 2011 12:13:38 -0000 Issue 7415

Topics (messages 314191 through 314195):

Re: Use of preg_replace
        314191 by: Tim Streater

Re: Members area Login with permissions!
        314192 by: alekto

Re: Three new versions of EasyPHP (WAMP package) with PHP 5.3.6, 5.3.7 RC3 and 
5.4.0 alpha2
        314193 by: Sharl.Jimh.Tsin

Re: PHP frameworks
        314194 by: Laruence

Re: Closing PHP tag best practice?
        314195 by: Daniel Brown

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
On 24 Jul 2011 at 19:57, Dajka Tamás <[email protected]> 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

--- End Message ---
--- Begin Message ---
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:[email protected]] 
> Sent: Sunday, July 24, 2011 3:23 PM
> To: Dajka Tamas
> Cc: [email protected]
> 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:[email protected]] 
> Sent: Sunday, July 24, 2011 1:00 PM
> To: Dajka Tamas
> Cc: [email protected]
> 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 <div class="message"> 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:[email protected]] 
> Sent: Sunday, July 24, 2011 1:28 AM
> To: [email protected]
> 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!
> 
> 
> 
> <?php
> include('config.php');
> ?>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> <html xmlns="http://www.w3.org/1999/xhtml";>
>   <head>
>       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
>       <link href="<?php echo $design; ?>/style.css" rel="stylesheet"
> title="Style" />
>       <title>Connexion</title>
>   </head>
>   <body>
>       <div class="header">
>               <a href="<?php echo $url_home; ?>"><img src="<?php echo
> $design; ?>/images/logo.png" alt="Members Area" /></a>
>           </div>
> <?php
> //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']);
> ?>
> <div class="message">You have successfuly been loged out.<br />
> <a href="<?php echo $url_home; ?>">Home</a></div>
> <?php
> }
> 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)
>                       {
>                         ?>
> <div class="message">You have successfuly been logged in. You can now access
> the admin area.<br />
> <a href="index2.php">Home</a></div>
> <?php
>                       }
>                       if($usr_level == 10)
>                       {
>                       ?>
> <div class="message">You have successfuly been logged in. You can now access
> to the newbe area.<br />
> <a href="index1.php">Home</a></div>
> <?php
>                       }
>                       if($usr_level == 11)
>                       {
>                       ?>
> <div class="message">You have successfuly been logged in. You can now access
> the advanced area.<br />
> <a href="index2.php">Home</a></div>
> <?php
>                       }                            
> 
>               }
>               else
>               {
>                       //Otherwise, we say the password is incorrect.
>                       $form = true;
>                       $message = 'The username or password is incorrect.';
>               }
>       }
>       else
>       {
>               $form = true;
>       }
>       if($form)
>       {
>               //We display a message if necessary
>       if(isset($message))
>       {
>               echo '<div class="message">'.$message.'</div>';
>       }
>       //We display the form
> ?>
> <div class="content">
>   <form action="connexion.php" method="post">
>       Please type your IDs to log in:<br />
>       <div class="center">
>           <label for="username">Username</label><input type="text"
> name="username" id="username" value="<?php echo htmlentities($ousername,
> ENT_QUOTES, 'UTF-8'); ?>" /><br />
>           <label for="password">Password</label><input type="password"
> name="password" id="password" /><br />
>           <input type="submit" value="Log in" />
>               </div>
>   </form>
> </div>
> <?php
>       }
> }
> ?>
>               <div class="foot"><a href="<?php echo $url_home; ?>">Go
> Home</a></div>
>       </body>
> </html>
> 
>  
>  


--- End Message ---
--- Begin Message ---
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.


--- End Message ---
--- Begin Message ---
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<[email protected]>  wrote:
On Jul 21, 2011, at 11:41 PM, Micky Hulse wrote:

On Thu, Jul 21, 2011 at 6:44 PM, Shawn McKenzie<[email protected]>  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



--- End Message ---
--- Begin Message ---
On Sun, Jul 24, 2011 at 10:18, Ashley Sheridan <[email protected]> 
wrote:
>
> 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.

    I quit using closing tags years ago and haven't looked back once
(except for code snippets, since explanatory text generally follows
the block).

-- 
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/

--- End Message ---

Reply via email to