php-general Digest 21 Jul 2008 15:11:34 -0000 Issue 5581

Topics (messages 277133 through 277144):

Re: Pasword Protecting several pages
        277133 by: Micah Gersten
        277134 by: R.C.
        277135 by: Micah Gersten

Re: accessing variable value
        277136 by: Chris

syntax error
        277137 by: Ronald Wiplinger
        277138 by: Ted Wood
        277139 by: Eric Butera
        277140 by: Aschwin Wesselius
        277141 by: Eric Butera
        277142 by: Aschwin Wesselius
        277143 by: Eric Butera

Re: session ok? [SOLVED]
        277144 by: tedd

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 ---
Set a session variable after the login has been confirmed and check for
it at the beginning of every page.  If it's not set, then redirect to login.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



R.C. wrote:
> I'm still trying to get this scenario worked out and don't seem to be able
> to get it done.
>
> Here's what I'm trying to do:
> User logs into a login page and inputs email address and password.  User
> accessess password protected page, which contains a few links.  User clicks
> on one of the links, opens page, looks at content and then clicks back to
> main page.
>
> User is now asked to input password again.... what do I have to do to make
> sure all related links/pages on the main.php page are accessible with that
> same password the user input the first time?  Also.. how can I password
> protect ALL the linked pages on the main.php site with the same password but
> user only has to log in once!!
>
> No database, but just sessions?  I looked at those and also Tedd was kind
> enough to send something but for some reason I can't get it to go.
>
> Can someone forward some good instructions on how to accomplish this task?
> I would greatly appreciate it. Still learning this program as you can tell.
>
> Best
> Ref
>
>
>
>
>
>   

--- End Message ---
--- Begin Message ---
Thank you Micah,

Could you give me some code on that?

Ref

"Micah Gersten" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Set a session variable after the login has been confirmed and check for
> it at the beginning of every page.  If it's not set, then redirect to
login.
>
> Thank you,
> Micah Gersten
> onShore Networks
> Internal Developer
> http://www.onshore.com
>
>
>
> R.C. wrote:
> > I'm still trying to get this scenario worked out and don't seem to be
able
> > to get it done.
> >
> > Here's what I'm trying to do:
> > User logs into a login page and inputs email address and password.  User
> > accessess password protected page, which contains a few links.  User
clicks
> > on one of the links, opens page, looks at content and then clicks back
to
> > main page.
> >
> > User is now asked to input password again.... what do I have to do to
make
> > sure all related links/pages on the main.php page are accessible with
that
> > same password the user input the first time?  Also.. how can I password
> > protect ALL the linked pages on the main.php site with the same password
but
> > user only has to log in once!!
> >
> > No database, but just sessions?  I looked at those and also Tedd was
kind
> > enough to send something but for some reason I can't get it to go.
> >
> > Can someone forward some good instructions on how to accomplish this
task?
> > I would greatly appreciate it. Still learning this program as you can
tell.
> >
> > Best
> > Ref
> >
> >
> >
> >
> >
> >



--- End Message ---
--- Begin Message ---
checkLogin.php

<?php

session_start();
if ($_SESSION['login'] != true)
{
    header("Location: login.php");
    exit();
}

?>

info.php

<?php

include_once('checkLogin.php');

...Code goes here...

?>

login.php

<?php

session_start();

if ($_POST['Username'] == *Check Credentials Here*)
{
    $_SESSION['login'] = true;
    header("Location: info.php");
    exit();
}

//Output Form Here

?>

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



R.C. wrote:
> Thank you Micah,
>
> Could you give me some code on that?
>
> Ref
>
> "Micah Gersten" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>   
>> Set a session variable after the login has been confirmed and check for
>> it at the beginning of every page.  If it's not set, then redirect to
>>     
> login.
>   
>> Thank you,
>> Micah Gersten
>> onShore Networks
>> Internal Developer
>> http://www.onshore.com
>>
>>
>>
>> R.C. wrote:
>>     
>>> I'm still trying to get this scenario worked out and don't seem to be
>>>       
> able
>   
>>> to get it done.
>>>
>>> Here's what I'm trying to do:
>>> User logs into a login page and inputs email address and password.  User
>>> accessess password protected page, which contains a few links.  User
>>>       
> clicks
>   
>>> on one of the links, opens page, looks at content and then clicks back
>>>       
> to
>   
>>> main page.
>>>
>>> User is now asked to input password again.... what do I have to do to
>>>       
> make
>   
>>> sure all related links/pages on the main.php page are accessible with
>>>       
> that
>   
>>> same password the user input the first time?  Also.. how can I password
>>> protect ALL the linked pages on the main.php site with the same password
>>>       
> but
>   
>>> user only has to log in once!!
>>>
>>> No database, but just sessions?  I looked at those and also Tedd was
>>>       
> kind
>   
>>> enough to send something but for some reason I can't get it to go.
>>>
>>> Can someone forward some good instructions on how to accomplish this
>>>       
> task?
>   
>>> I would greatly appreciate it. Still learning this program as you can
>>>       
> tell.
>   
>>> Best
>>> Ref
>>>
>>>
>>>
>>>
>>>
>>>
>>>       
>
>
>
>   

--- End Message ---
--- Begin Message ---
Sudhakar wrote:
> i need help with accessing the value of a variable from a different page.
> 
> i have an index.php file which has 2 files included to display header and
> footer and the center portion changes based on the link clicked on the
> footer.
> 
> header.php
> 
> <?php
> echo "<h2> Text from header.php file </h2>";
> ?>
> 
> footer.php
> 
> <?php
> $title="Title of Footer Page";
> ?>
> <a href="index.php?page=web">Web Development</a> | <a
> href="index.php?page=software">Software </a>
> 
> index.php
> 
> <?php
> $pagename=$_GET["page"];
> $title="Index page of Company name";
> ?>
> <html>
> <head>
> <title><?php echo $title; ?> </title>
> <meta name="keywords" content="<?php echo $keyword; ?>">
> <meta name="description" content="<?php echo $pagedescription; ?>">
> </head>
> <body>
> <?php include("header.php");  ?> <p> </p>
> <center>This is the text in the center</center> <p> </p>
> <?php
> if($pagename=="web")
> {
> include("web.php");
> }
> if($pagename=="software")
> {
> include("software.php");
> }
> ?>
> <?php include("footer.php");  ?>
> </body>
> </html>
> 
> whenever i click the links for Web Development or Software which appears
> from the footer a query string is passed to index.php I am able to display
> the content of web.php and software.php using the if() condition and
> include()
> what i need to display is a different title for web.php and software.php
> when a user clicks Web Development along with the content i want the title
> of the page to change for SEO purpose. i have defined $title differently in
> web.php and software.php however presently the title being displayed for
> index.php when a user clicks web.php and software.php the title is the same
> "Index page of Company name" as this is defined in index.php and my title
> tag is written as
> <title><?php echo $title; ?> </title> however the title tag remains the same
> whether i click web development or software link. how change i change the
> code to display different titles.


<?php
$pagename = '';
if (isset($_GET['pagename'])) {
        $pagename = strtolower($_GET['pagename']);
}

switch ($pagename) {

        // hardcode the pages you *know* exist.
        // don't just "include $pagename.php"
        // as i can make up a "pagename" of whatever i like
        // and it will break your site

        // i know "web.php" and "software.php" exist
        // so if the pagename is one of those,
        // just include the relevant file.
        case 'web':
        case 'software':
                include($pagename.'.php');
        break;

        // just in case I remove the "pagename" variable from the query string
        // or make up a random pagename
        // make sure you set up some default values!
        default:
                include('defaults.php');
}
?>
<html>
<head>
<title>
        <?php echo $title; ?>
</title>
...
<body>
<?php
echo $content;

include 'footer.php';



inside the 'web.php' and 'software.php' files, set your variables:

in web.php:
<?php
$title = 'This is the "web.php" page title';
$keywords = 'These are the keywords for the web.php page';

$content = <<<EOD
This is the content of the page.
Read up about heredoc syntax here:

http://www.php.net/heredoc

EOD;

and to the same inside the software.php and any other files you need.

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

--- End Message ---
--- Begin Message ---
On a system with php4 and mysql 4.x I had these lines:

require("../db-config");     // includes $dbhost, $buname, $dbpass
$db = mysql_connect($dbhost, $dbuname, $dbpass);
mysql_select_db($dbname,$db);

    $sql = "SELECT * FROM CATEGORY WHERE .....";
    $result = mysql_query($sql,$db);
    $num=mysql_num_rows($result);
    while ($myrow = mysql_fetch_array($result)) {
....

Moving the *.php to a php5 and mysql 5.x site I get these errors:

PHP Warning:  mysql_num_rows(): supplied argument is not a valid MySQL
result resource in ...
PHP Warning:  mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in ...


Looking at the manual, I cannot see what I am doing wrong.

bye

R.

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

Not a syntax error. It's not successfully connecting to the database. Check your settings.

~Ted



On 21-Jul-08, at 4:24 AM, Ronald Wiplinger wrote:

On a system with php4 and mysql 4.x I had these lines:

require("../db-config");     // includes $dbhost, $buname, $dbpass
$db = mysql_connect($dbhost, $dbuname, $dbpass);
mysql_select_db($dbname,$db);

   $sql = "SELECT * FROM CATEGORY WHERE .....";
   $result = mysql_query($sql,$db);
   $num=mysql_num_rows($result);
   while ($myrow = mysql_fetch_array($result)) {
....

Moving the *.php to a php5 and mysql 5.x site I get these errors:

PHP Warning:  mysql_num_rows(): supplied argument is not a valid MySQL
result resource in ...
PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in ...


Looking at the manual, I cannot see what I am doing wrong.

bye

R.


--- End Message ---
--- Begin Message ---
On Mon, Jul 21, 2008 at 7:24 AM, Ronald Wiplinger <[EMAIL PROTECTED]> wrote:
> On a system with php4 and mysql 4.x I had these lines:
>
> require("../db-config");     // includes $dbhost, $buname, $dbpass
> $db = mysql_connect($dbhost, $dbuname, $dbpass);
> mysql_select_db($dbname,$db);
>
>    $sql = "SELECT * FROM CATEGORY WHERE .....";
>    $result = mysql_query($sql,$db);
>    $num=mysql_num_rows($result);
>    while ($myrow = mysql_fetch_array($result)) {
> ....
>
> Moving the *.php to a php5 and mysql 5.x site I get these errors:
>
> PHP Warning:  mysql_num_rows(): supplied argument is not a valid MySQL
> result resource in ...
> PHP Warning:  mysql_fetch_array(): supplied argument is not a valid MySQL
> result resource in ...
>
>
> Looking at the manual, I cannot see what I am doing wrong.
>
> bye
>
> R.
>

Your mysql_connect is probably failing.  Look at your error log or
look at mysql_error() for a reason why.

--- End Message ---
--- Begin Message ---
Eric Butera wrote:
On Mon, Jul 21, 2008 at 7:24 AM, Ronald Wiplinger <[EMAIL PROTECTED]> wrote:
On a system with php4 and mysql 4.x I had these lines:

require("../db-config");     // includes $dbhost, $buname, $dbpass
$db = mysql_connect($dbhost, $dbuname, $dbpass);
mysql_select_db($dbname,$db);

   $sql = "SELECT * FROM CATEGORY WHERE .....";
   $result = mysql_query($sql,$db);
   $num=mysql_num_rows($result);
   while ($myrow = mysql_fetch_array($result)) {
....

Moving the *.php to a php5 and mysql 5.x site I get these errors:

PHP Warning:  mysql_num_rows(): supplied argument is not a valid MySQL
result resource in ...
PHP Warning:  mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in ...


Looking at the manual, I cannot see what I am doing wrong.

bye

R.


Your mysql_connect is probably failing.  Look at your error log or
look at mysql_error() for a reason why.

Probably the mysql extension is not found or not loaded (due to not being compiled with the right path or the default path in PHP is not the right one). Happened to me a couple of times.....


--

Aschwin Wesselius

/'What you would like to be done to you, do that to the other....'/

--- End Message ---
--- Begin Message ---
On Mon, Jul 21, 2008 at 7:55 AM, Aschwin Wesselius
<[EMAIL PROTECTED]> wrote:
> Eric Butera wrote:
>
> On Mon, Jul 21, 2008 at 7:24 AM, Ronald Wiplinger <[EMAIL PROTECTED]>
> wrote:
>
>
> On a system with php4 and mysql 4.x I had these lines:
>
> require("../db-config");     // includes $dbhost, $buname, $dbpass
> $db = mysql_connect($dbhost, $dbuname, $dbpass);
> mysql_select_db($dbname,$db);
>
>    $sql = "SELECT * FROM CATEGORY WHERE .....";
>    $result = mysql_query($sql,$db);
>    $num=mysql_num_rows($result);
>    while ($myrow = mysql_fetch_array($result)) {
> ....
>
> Moving the *.php to a php5 and mysql 5.x site I get these errors:
>
> PHP Warning:  mysql_num_rows(): supplied argument is not a valid MySQL
> result resource in ...
> PHP Warning:  mysql_fetch_array(): supplied argument is not a valid MySQL
> result resource in ...
>
>
> Looking at the manual, I cannot see what I am doing wrong.
>
> bye
>
> R.
>
>
>
> Your mysql_connect is probably failing.  Look at your error log or
> look at mysql_error() for a reason why.
>
> Probably the mysql extension is not found or not loaded (due to not being
> compiled with the right path or the default path in PHP is not the right
> one). Happened to me a couple of times.....
>
>
> --
>
> Aschwin Wesselius
>
> 'What you would like to be done to you, do that to the other....'
>

Wouldn't that be  call to undefined function then?

--- End Message ---
--- Begin Message ---
Eric Butera wrote:
On Mon, Jul 21, 2008 at 7:55 AM, Aschwin Wesselius
<[EMAIL PROTECTED]> wrote:
Probably the mysql extension is not found or not loaded (due to not being
compiled with the right path or the default path in PHP is not the right
one). Happened to me a couple of times.....


--

Aschwin Wesselius

'What you would like to be done to you, do that to the other....'


Wouldn't that be  call to undefined function then?

Oh my..... I'm so sorry. You're absolutely right. I mixed these two. I'm a bit side-tracked today.....

Thanks for pointing that out.


--

Aschwin Wesselius

/'What you would like to be done to you, do that to the other....'/

--- End Message ---
--- Begin Message ---
On Mon, Jul 21, 2008 at 8:32 AM, Aschwin Wesselius
<[EMAIL PROTECTED]> wrote:
> Oh my..... I'm so sorry. You're absolutely right. I mixed these two. I'm a
> bit side-tracked today.....
>
> Thanks for pointing that out.
>
>
> --
>
> Aschwin Wesselius


It's no problem, I got scared I was spreading propaganda!  hehe :)

--- End Message ---
--- Begin Message ---
Hi gang:

I found the problem I was having with sessions and want to share it with you -- it surprised me.

To refresh -- I was having a problem with destroying a session. I went through all the steps shown in the manual and dozens of recommended ways of doing it I found on the net.

However, I found that while I was actually destroying the session I wanted, another session was being created in a very unexpected way.

Now, the manual says:

"session_start() creates a session or resumes the current one based on the current session id that's being passed via a request, such as GET, POST, or a cookie."

From that one assumes that if you place a session_start at the beginning of each page, then the first time it's encountered, a session will be created and with every encounter thereafter the established session will be used.

That's the way it works PROVIDED that you do not use the following in your code:

header('Location: http://www.yourdomain.com/whatever/index.php');

If you use that statement, then a new session will be created AND you will find that you'll have two sessions working concurrently. That creates several problems -- one of them being while you may destroy the first session, the second will be still remain.

Now, how many people knew this?

Am I the only one who didn't?

Cheers,

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---

Reply via email to