php-general Digest 3 Feb 2009 03:25:52 -0000 Issue 5937

Topics (messages 287539 through 287556):

Re: PHP Enclosing Tags? Do You Close Your PHP Declarations?
        287539 by: Larry Garfield

Re: More questions about SESSION use
        287540 by: Terion Miller
        287553 by: Chris

Blank page of hell..what to look for
        287541 by: Terion Miller
        287542 by: Jason Pruim
        287543 by: Richard Heyes
        287544 by: Terion Miller
        287545 by: Jim Lucas
        287548 by: Frank Stanovcak
        287549 by: Lupus Michaelis

IP to location / XML
        287546 by: Jônatas Zechim
        287547 by: Jônatas Zechim

Re: Boolean Assignment Operator
        287550 by: Nitsan Bin-Nun

pear:Auth invalid username/password
        287551 by: John Corry
        287552 by: Chris

Another matching question
        287554 by: Ron Piggott
        287555 by: Ashley Sheridan

How can I do the opposite of property_exists(), maybe a creat_property() in 
PHP5?
        287556 by: Daevid Vincent

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On Mon, 2 Feb 2009 08:23:49 +0100, Yannick Mortier <mvmort...@googlemail.com> 
wrote:
> 2009/2/2 Alpár Török <torokal...@gmail.com>:
>>
>>
>> 2009/2/1 Yannick Mortier <mvmort...@googlemail.com>
>>>
>>> I once read that this is even recommended by the PHP developers... Has
>>> anyone got a quote for me about this?
>>>
>>
>> I know thw ZF codinf style includes it as a must. See here :
>>
>>
> http://framework.zend.com/manual/en/coding-standard.php-file-formatting.html#coding-standard.php-file-formatting.general

The Drupal coding standards say to exclude the closing ?> on files for the same 
reason: It avoids a host of problems with whitespace handling and is just one 
less thing to have to deal with.

http://drupal.org/coding-standards

--Larry Garfield


--- End Message ---
--- Begin Message ---
> Show the code where your session vars are written and I would prefer using
> isset() instead of empty() if you want to check if this var is set or not.
>
> -eddy
>
Hi All, here is the index page where users login and the sessions are set:

<?php
//start session
session_start();
//db connection include
include("inc/dbconn_open.php") ;
//errors on
error_reporting(E_ALL);
ini_set('display_errors', '1');

if (!empty($_POST['UserName']) && !empty($_POST['Password'])) {
   $UserName = $_POST['UserName'];
   $Password = $_POST['Password'];
}
$msg = '';

if (!empty($UserName)) {

    $sql = "SELECT `AdminID`,`UserName` FROM `admin` WHERE
`UserName`='$UserName' and    `Password`='$Password'";
    $result = mysql_query ($sql);
    $row = mysql_fetch_object ($result);

 If (mysql_num_rows($result) > 0) {
       $_SESSION['AdminLogin'] = true;
       $_SESSION['user'] = $UserName;
       $_SESSION['AdminID'] = $row->AdminID;


        header ('Location: Main.php');
        exit;


    } else {
        $msg = "Sorry You Entered  An Invalid Login<br>Please Try
Again<br>Click to Contact <a href='mailto:b...@blahblah.com'><b>blah
blah</b></a> If You Need Help";
    }
}
 //include ("VariableReveal2.php");
?>

--- End Message ---
--- Begin Message ---
Edmund Hertle wrote:
2009/2/1 Terion Miller <webdev.ter...@gmail.com>

This is how it was originally written:
if (empty($_SESSION['AdminLogin']) || $_SESSION['AdminLogin'] !=
 true){
    header ("Location: LogOut.php");
    $_SESSION['user']=$UserName;
    $_SESSION['AdminID']=$AdminID; <--*I added this one originally the
script only used 'user' and 'AdminLogin'* but passed them in urls
}

Those two lines after header() will not be executed.

Yes they will because there is no 'exit'.

Header is just a function call, if you want to stop processing you have to do it yourself.

--
Postgresql & php tutorials
http://www.designmagick.com/


--- End Message ---
--- Begin Message ---
Is there a certain thing that should be suspected and looked at first when
getting the php blank page of hell....
I have errors on and nothing is being output anywhere to lead me in the
right direction, I have a VariableReveal script (one of you provide and
THANK YOU IT HAS BEEN A LIFESAVER) But it is doing nothing today, yesterday
the page worked today I get the blank page with not a clue in sight....
ARGH...
Terion

--- End Message ---
--- Begin Message ---

On Feb 2, 2009, at 12:02 PM, Terion Miller wrote:

Is there a certain thing that should be suspected and looked at first when
getting the php blank page of hell....
I have errors on and nothing is being output anywhere to lead me in the right direction, I have a VariableReveal script (one of you provide and THANK YOU IT HAS BEEN A LIFESAVER) But it is doing nothing today, yesterday the page worked today I get the blank page with not a clue in sight....
ARGH...

What I typically do with that is make sure that if you are using HEREDOC you don't have any extra spaces after the opening or closing HEREDOC statements.

Also, I have gone through and put just: echo "1"; echo "2"; etc through out the code to see if i could pin down exactly WHERE the problem was starting... It help to narrow it down.

What might help is if it's a small script, go ahead and post it to the list and maybe we can find something quickly.


--
Jason Pruim
japr...@raoset.com
616.399.2355




--- End Message ---
--- Begin Message ---
> I have errors on

Including E_NOTICE ?

-- 
Richard Heyes

HTML5 Graphing for Firefox, Chrome, Opera and Safari:
http://www.rgraph.org (Updated January 31st)

--- End Message ---
--- Begin Message ---
I just use error_reporting(E_ALL);
that would include the E_NOTICE right?

On Mon, Feb 2, 2009 at 11:27 AM, Richard Heyes <rich...@php.net> wrote:

> > I have errors on
>
> Including E_NOTICE ?
>
> --
> Richard Heyes
>
> HTML5 Graphing for Firefox, Chrome, Opera and Safari:
> http://www.rgraph.org (Updated January 31st)
>

--- End Message ---
--- Begin Message ---
Terion Miller wrote:
> Is there a certain thing that should be suspected and looked at first when
> getting the php blank page of hell....
> I have errors on and nothing is being output anywhere to lead me in the
> right direction, I have a VariableReveal script (one of you provide and
> THANK YOU IT HAS BEEN A LIFESAVER) But it is doing nothing today, yesterday
> the page worked today I get the blank page with not a clue in sight....
> ARGH...
> Terion
> 

More then likely it is a parse error within the page.  And no matter what error 
reporting you have turned on "within" the script will effect the outcome.

You have two choices.  Turn on error reporting from apache using the httpd.conf 
file, in your php.ini file, or with a .htaccess file.

This is the only way to get around parse errors without having error reporting 
turned on globally.

The other way is to cut/paste your code into sections.

Cut out a large chunk of it, see if it works, if it does, paste it back in and 
remove a smaller chunk,  rinse/repeat until your find the error of your
ways... :)

Better yet, use a IDE the does code highlighting.  This would point you to the 
problem rather quickly.

-- 
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--- End Message ---
--- Begin Message ---
"Terion Miller" <webdev.ter...@gmail.com> wrote in message 
news:37405f850902020902j624356ccp4ea869bc45161...@mail.gmail.com...
> Is there a certain thing that should be suspected and looked at first when
> getting the php blank page of hell....
> I have errors on and nothing is being output anywhere to lead me in the
> right direction, I have a VariableReveal script (one of you provide and
> THANK YOU IT HAS BEEN A LIFESAVER) But it is doing nothing today, 
> yesterday
> the page worked today I get the blank page with not a clue in sight....
> ARGH...
> Terion
>

I'm not sure what your setup is, but I get this frequently when testing on 
my windows server with IE

What I do to get the error is save a blank page over the one that is causing 
the problem.  Load it in the browser, then resave the probelem code, and 
refresh.  I almost always end up having left off a ; or } somewhere, and it 
just won't report it till I refresh like this.

Hope that helps.
Frank. 



--- End Message ---
--- Begin Message ---
Terion Miller a écrit :
Is there a certain thing that should be suspected and looked at first when
getting the php blank page of hell....

Did you check error logs from Apache or the one you configured in php.ini ?
--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org

Seeking for a position <http://lupusmic.org/pro/>

--- End Message ---
--- Begin Message ---
Hi there,

I want do discover the location from a IP, I use this url '
http://www.onflex.org/geo/xml/ ', that's does a XML file, it's ok on my
browser, but when i try to read this file with php:

$myxml = simplexml_load_file ('http://www.onflex.org/geo/xml/');

That's gives a error:

Warning: simplexml_load_file() [function.simplexml-load-file]:
http://www.onflex.org/geo/xml/:8: parser error : Input is not proper UTF-8,
indicate encoding ! Bytes: 0xE3 0x6F 0x20 0x50 *****


Anyone Who might help me with this?

zechim



--- End Message ---
--- Begin Message ---
Hi Nathan, i'll try max minds geo ip, that's what i want.

-----Mensagem original-----
De: Nathan Rixham [mailto:nat...@gmail.com] 
Enviada em: segunda-feira, 2 de fevereiro de 2009 16:13
Para: php-gene...@lists.php.net; Jônatas Zechim
Cc: 'PHP General'
Assunto: Re: IP to location / XML

Jônatas Zechim wrote:
> Hi there,
> 
> I want do discover the location from a IP, I use this url '
> http://www.onflex.org/geo/xml/ ', that's does a XML file, it's ok on my
> browser, but when i try to read this file with php:
> 
> $myxml = simplexml_load_file ('http://www.onflex.org/geo/xml/');
> 
> That's gives a error:
> 
> Warning: simplexml_load_file() [function.simplexml-load-file]:
> http://www.onflex.org/geo/xml/:8: parser error : Input is not proper
UTF-8,
> indicate encoding ! Bytes: 0xE3 0x6F 0x20 0x50 *****
> 
> 
> Anyone Who might help me with this?
> 
> zechim
> 
> 

try this:
$file = get_file_contents('http://www.onflex.org/geo/xml/');
$file = utf8_decode($file);
$myxml = simplexml_load_string($file);

the above assumes the problem is because the file is really latin-1

quick note, using the service at onflex.org will always return you're 
servers ip address not the end users (as you're calling from server not 
clients browser) if this is what you want great, if not then you may 
want to try max minds geo ip.

regards!


--- End Message ---
--- Begin Message ---
It actually will return FATAL ERROR or something like that since you didn't
echo'ed variables or string ;)

On Mon, Feb 2, 2009 at 3:03 PM, Edmund Hertle <edmund.her...@student.kit.edu
> wrote:

> 2009/2/2 Gavin Hodge <gavin.ho...@gmail.com>
>
> > Hi,
> >
> > I'm fairly new to PHP, having migrated from the Java / C# world.
> >
> > I wrote some code similar to the following:
> >
> > $success = true;
> > $success &= operation1();
> > $success &= operation2();
> >
> > if ($success === true) {
> >    operation3(); // depends on 1 and 2 being successful
> > }
> >
> > This didn't work as expected. After a bit of digging I found:
> > * The &= operation isn't mentioned anywhere in the PHP documentation
> > * The &= function seems to work as expected, however the following is
> > observed...
> >       $success = true;
> >       $success &= true;
> >       print $success == true; // outputs 1
> >       print $sucesss === true; // no output
> > * The 'or' assignment operator |= causes no errors but doesn't work.
> >
> > Can any PHP gurus explain why the &= operator works at all, and why
> > === seems to fail afterwards?
> >
> > Cheers,
> > Gavin.
>
>
> Hey,
>
> never heard of the "|=" operator. So I think php does not support it.
> I cannot say how "&=" works in Java or C# but as of php it works like that
> (IMO) (reference instead of copy):
> $var1 = "test1";
> $var2 = $var1;
> $var3 &= $var1;
> $var1 = "test2";
>
> echo var1; // "test2"
> echo var2; // "test1"
> echo var3; // "test2"
>

--- End Message ---
--- Begin Message ---
I'm using Pear Auth on several sites and am looking for suggestions on the
best way to implement error reporting on a failed log-in.

Currently I'm using a function that checks if the posted username is in the
users table...and if the password is a match. Auth logs the user on if
so...but if not it takes manually running the queries to generate the right
failure message.

Is there a cleaner way using error messages generated by the getAuth()
method or another method in the Auth class? I didn't see anything in the
docs...but it seems like an obvious bit of functionailty I would sort of
expect it to be included.

Anyone know of such a thing?

John Corry

--- End Message ---
--- Begin Message ---
John Corry wrote:
I'm using Pear Auth on several sites and am looking for suggestions on the
best way to implement error reporting on a failed log-in.

Currently I'm using a function that checks if the posted username is in the
users table...and if the password is a match. Auth logs the user on if
so...but if not it takes manually running the queries to generate the right
failure message.

You mean if it's a valid username but not password?

I'd say don't. While it's a little nicer for your users ("hey, your password was wrong") - it's also a lot easier for attackers. "Hmm, that means it's a valid user, lets see if we can brute force the password".

"Username or password are incorrect" - an attacker has no idea which bit is wrong. You could force a user to use their email address as their username to make it easier to remember.

Depends on the app & audience I guess, if it's an internal only app - go with #1 (no idea about Pear Auth though), if it's public, there's no way I'd say your password is wrong, just provide a "forgot password" feature.

--
Postgresql & php tutorials
http://www.designmagick.com/


--- End Message ---
--- Begin Message ---
How do I tell if 

words_from_the_well 

is not the value of $page (whether it is the entire value of $page OR
within the value of $page)

So far I have come up with the following, but it doesn't deal with when
$page is only within the value of $page

if ( $page <> "words_from_the_well" )  {

Ron 

--- End Message ---
--- Begin Message ---
On Mon, 2009-02-02 at 20:35 -0500, Ron Piggott wrote:

> How do I tell if 
> 
> words_from_the_well 
> 
> is not the value of $page (whether it is the entire value of $page OR
> within the value of $page)
> 
> So far I have come up with the following, but it doesn't deal with when
> $page is only within the value of $page
> 
> if ( $page <> "words_from_the_well" )  {
> 
> Ron 

The <> comparison operator won't work in PHP. What you want maybe is
something like this:

if(!strstr($page, "words_from_the_well"))
{}


Ash
www.ashleysheridan.co.uk

--- End Message ---
--- Begin Message ---
Is there a way to create a new property via PHP 5.2.4?

I get a hash back from an authentication server. I'm not guaranteed that
someone in another department won't add new key/values to the returned
hash/array. I'm trying to work around that part gracefully so that the
code doesn't blow up on a customer in such an event. The main try/catch
will suppress errors already, but I thought it would be nice to be able
to handle this stuff automatically rather than constantly updating a
User.class.php file all the time.

    "creating new property this->oraclecustomerid with 1122"

but when I try to set the value with the $this->$pkey = $value; 

It triggers __call() which then triggers __set() which throws my
BadProperty exception.

How come $this->$pkey = $value isn't creating/setting a property? 
Or how do I do something like create_property($this, $pkey);
so that I can then set it via $this->oraclecustomerid = 1122 or
$this->set_oraclecustomerid(1122) ???

<?php
function load_from_user_data($user_data)
{
        //now loop through the rest of the user_data array and assign via a
set_foo() method
        foreach ($user_data as $key => $value)
        {
                        //try
                        {
                                $pkey = strtolower($key);
                                //[dv] this is sort of a hack to 
"automatically" create a new
property/variable
                                //         for 'new' hashes key/values we may 
not know about.
                                //         It's really designed to supress 
errors and they really should
be added to this User.class.php properly.
                                if ( !property_exists($this, $pkey) )
                                {
                                        echo "creating new property this->$pkey 
with $value<br>\n";
                                        $this->$pkey = $value; //THIS BLOWS UP 
ON THE __set()
                                        echo "this->$pkey = ".$this->$pkey;
                                }
                                else
                                {
                                        $class_variable = 'set_'.$pkey;
                                        $this->$class_variable($value);
                                        unset($user_data[$key]);
                                }
                        }
                        //catch (Exception $e)
                        {
                                //echo $e->getMessage()."\n";
                        }
        }

                //should new fields be returned in the $user_data that are not
accounted for above...
                if ($_SESSION['DEVELOPMENT'] && count($user_data))
                {
                        echo "<!-- Unaccounted for user_data hashes. Please add 
these into
User.class.php:\n";
                        var_dump($user_data);
                        echo "-->";
                }

        //THESE TWO LINES FATAL ERROR ON THE __get():
        echo "this->oraclecustomerid = ".$this->oraclecustomerid;
        echo "this->get_oraclecustomerid() = ".$this->get_oraclecustomerid();
}
?>

--- End Message ---

Reply via email to