php-general Digest 25 Jan 2009 09:51:35 -0000 Issue 5921
Topics (messages 287077 through 287082):
New PHP User with a simple question
287077 by: Christopher W
287078 by: Michael Kubler
287079 by: Lars Torben Wilson
287080 by: Christopher W
287081 by: Christopher W
287082 by: Carlos Medina
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 ---
At least I hope it is simple...
I am trying to get an HTML menu link to set a variable's value. For
example, when a user clicks the "Home" button on my page it would cause
$page = "home"; or clicking the "About Us" button will set $page="about_us";
etc.
I think this should be fairly simple but being completely new to php I just
cannot seem to get it right.
Any help would be greatly appreciate.
Thank you in advance.
--
--- End Message ---
--- Begin Message ---
The easiest way would be to use GET parameters (i.e data in the actual URL).
There are a number of ways you can structure a HTML link to get what you
want.
You can have something basic (but not very elegant looking), like
<a href="index.php?page=Home">Home</a>
Then in your index.php code you'd probably have something like :
<?php
$page = urldecode(*$_GET['page']); *
include_once header.inc; //Include a script that contains the
general header information
if(is_file(pages/*$page*.inc;)) //make sure they haven't requested a
non-existant file
{
include_once pages/*$page*.inc; //Doesn't have to be .inc you
could simply output HTML data if that's all your using.
}
else
{
include_once pages/Home.inc; //If the user wanted a file that
doesn't exist, then just take them to the home page (or you could
take them to an error page if that's what you want).
}
include_once footer.inc; //Which would contain the footer if you've
got one.
?>
This is approximately how I do it although sometimes have a functions
file I call, or a config file with basic presets, and various other
things. I use .inc (for inclusion) as the file extension, so I can
easily differentiate between .php files that customers will use (such as
index.php, admin.php, login.php, etc..), and the included files.
In the header file I usually have something like that below.
----------- header.inc starts below this line ---------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<title><?php echo *$page*; ?> - Insert Company or Website Name</title>
<!-- Meta Tags -->
<meta http-equiv="content-type" content="application/xhtml+xml;
charset=utf-8">
<meta name="robots" content="index, follow">
<!-- CSS -->
<link rel="stylesheet" href="css/main.css"
media="screen,projection,tv,tty,handheld,embossed,braille,aural"
type="text/css">
<link rel="stylesheet" href="css/print.css" media="print"
type="text/css">
</head>
<body>
<div id="header">
<h1>HEADER INFORMATION (or image) HERE</h1>
<br />
<!-- end header div -->
</div>
<div id="mainNav">
<?php
*$main_navigation_list* = array(0 => array( 'name' => 'Home',
'url' => 'index.php?page=Contact',
'title' => 'The home page'),
1 => array('name' =>
'Contact' ,
'url'
=> 'index.php?page=Contact',
'title' => 'The contact details')
);
?>
<ul id="main_nav_list">
<?php
foreach(*$main_navigation_list* as *$index* => *$nav_list*)
{
echo '<li><a href="' . *$nav_list*['url'] .'" title="' .
*$nav_list*['title'] . '">'. *$nav_list*['name'] . '</a></li>';
}
?>
</ul>
</div>
<!-- end mainNav div -->
</div>
--------------- END header.inc ----------
In the header.inc I've manually created an array, then got PHP to go
through the array to add the name, URL and other details from the array,
but that's just to simplify this, usually I pull the navigation data
from a database (or if there's no MySQL installed I might unserialise it
from a file).
There are other ways of pulling the data. If you want nice URLs, you can
have something like /pages/Home/ and then have a mod_rewrite rule in
Apache to then change that into index.php?page=Home, (although you'll
also need to change the <a href> to the new links. If you aren't running
on apache, you can manually find the page information by doing
print_r($_SERVER), and seeing what bits and pieces you can put together,
but that's not nearly as good or reliable.
Sorry if there's too much info, but I'm guessing this is roughly what
you'll be doing.
If you want to have more than one variable (like say a sub page) then
you add *&* between each variable. E.g
<a href="index.php?page=Home&sub_page=more%20news">Home -
Archived News</a>
You can usually get away with just using *&* as the separator but it
probably won't validate properly if your making it in xhtml (as you
should be). Also, if your not sure what the %20 means (a space) then
look up urlencode <http://au.php.net/manual/en/function.urlencode.php>
and urldecode <http://au.php.net/url_decode>.
Michael Kubler
*G*rey *P*hoenix *P*roductions <http://www.greyphoenix.biz>
Christopher W wrote:
At least I hope it is simple...
I am trying to get an HTML menu link to set a variable's value. For
example, when a user clicks the "Home" button on my page it would cause
$page = "home"; or clicking the "About Us" button will set $page="about_us";
etc.
I think this should be fairly simple but being completely new to php I just
cannot seem to get it right.
Any help would be greatly appreciate.
Thank you in advance.
--- End Message ---
--- Begin Message ---
2009/1/24 Christopher W <cwei...@adelphia.net>:
> At least I hope it is simple...
>
> I am trying to get an HTML menu link to set a variable's value. For
> example, when a user clicks the "Home" button on my page it would cause
> $page = "home"; or clicking the "About Us" button will set $page="about_us";
> etc.
>
> I think this should be fairly simple but being completely new to php I just
> cannot seem to get it right.
>
> Any help would be greatly appreciate.
>
> Thank you in advance.
Hi there,
A good way to increase your chance of getting a useful response is to
post the smallest example you can which clearly illustrates the
problem you're having. In this case, you say you're not able to get
this to work, but we could waste quite a bit of time trying to guess
what you've tried and what didn't work.
In the simplest case, you could make your menu items look something
like this: <a href="target.html?page=home">Home</a> and then use $page
= $_GET['page'] in your script, but I wouldn't recommend it since now
you have user data floating around in your script and it will later
become a pain in the butt to sanitize for security. For a learning
script it'll be fine though.
Torben
--- End Message ---
--- Begin Message ---
Sorry, I am also new to the etiquette of these mail lists.
Anyway what I was attempting to do, in the full picture, was be able to just
switch the text in the text area without actually changing pages. For
example, if the user clicks "About Us" (from the home page) the page doesn't
change, just the text (in the area I designated for text).
Since I have never used php before (but have read some online and in books)
what I was trying was:
if ($page == "home") {echo $home_text;}
elseif ($page == "about") {echo $about_text;}
...
else {echo $error_text;}
My problem is that I can't figure out how to get the link-click to assign
the value to the variable. I didn't try any php for that end because I
really didn't know where to begin.
Thanks for the replies and the help. I truly appreciate it.
--
"Lars Torben Wilson" <larstor...@gmail.com> wrote in message
news:36d4833b0901242313r435860b3q7f3f4f0eea621...@mail.gmail.com...
> 2009/1/24 Christopher W <cwei...@adelphia.net>:
>> At least I hope it is simple...
>>
>> I am trying to get an HTML menu link to set a variable's value. For
>> example, when a user clicks the "Home" button on my page it would cause
>> $page = "home"; or clicking the "About Us" button will set
>> $page="about_us";
>> etc.
>>
>> I think this should be fairly simple but being completely new to php I
>> just
>> cannot seem to get it right.
>>
>> Any help would be greatly appreciate.
>>
>> Thank you in advance.
>
> Hi there,
>
> A good way to increase your chance of getting a useful response is to
> post the smallest example you can which clearly illustrates the
> problem you're having. In this case, you say you're not able to get
> this to work, but we could waste quite a bit of time trying to guess
> what you've tried and what didn't work.
>
> In the simplest case, you could make your menu items look something
> like this: <a href="target.html?page=home">Home</a> and then use $page
> = $_GET['page'] in your script, but I wouldn't recommend it since now
> you have user data floating around in your script and it will later
> become a pain in the butt to sanitize for security. For a learning
> script it'll be fine though.
>
>
> Torben
--- End Message ---
--- Begin Message ---
Mr. Kubler,
Thank you for the help. I have to admit, I am still in over my head, I
think. Perhaps I should just stick to static pages...
Anyway what I was attempting to do, in the full picture, was be able to just
switch the text in the text area without actually changing pages. For
example, if the user clicks "About Us" (from the home page)the page doesn't
change, just the text (in the area I designated for text).
Since I have never used php before (but have read some online and in books)
what I was trying was:
if ($page == "home") {echo $home_text;}
elseif ($page == "about") {echo $about_text;}
...
else {echo $error_text;}
My problem is that I can't figure out how to get the link-click to assign
the value to the variable. I didn't try any php for that end because I
really didn't know where to begin. Perhaps I am just going about this the
wrong way but from the extremely little I have learned about php, I thought
that I could do it this way easily.
Thanks for the replies and the help. I truly appreciate it.
--
"Michael Kubler" <greyphoenixproducti...@gmail.com> wrote in message
news:497c0275.80...@gmail.com...
> The easiest way would be to use GET parameters (i.e data in the actual
> URL).
> There are a number of ways you can structure a HTML link to get what you
> want.
> You can have something basic (but not very elegant looking), like
>
> <a href="index.php?page=Home">Home</a>
>
> Then in your index.php code you'd probably have something like :
>
> <?php
> $page = urldecode(*$_GET['page']); *
> include_once header.inc; //Include a script that contains the
> general header information
> if(is_file(pages/*$page*.inc;)) //make sure they haven't requested a
> non-existant file
> {
> include_once pages/*$page*.inc; //Doesn't have to be .inc you
> could simply output HTML data if that's all your using.
> }
> else
> {
> include_once pages/Home.inc; //If the user wanted a file that
> doesn't exist, then just take them to the home page (or you could
> take them to an error page if that's what you want).
> }
> include_once footer.inc; //Which would contain the footer if you've
> got one.
> ?>
>
>
> This is approximately how I do it although sometimes have a functions
> file I call, or a config file with basic presets, and various other
> things. I use .inc (for inclusion) as the file extension, so I can
> easily differentiate between .php files that customers will use (such as
> index.php, admin.php, login.php, etc..), and the included files.
>
> In the header file I usually have something like that below.
>
> ----------- header.inc starts below this line ---------------
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html lang="en">
> <head>
>
> <title><?php echo *$page*; ?> - Insert Company or Website Name</title>
>
> <!-- Meta Tags -->
> <meta http-equiv="content-type" content="application/xhtml+xml;
> charset=utf-8">
> <meta name="robots" content="index, follow">
>
> <!-- CSS -->
> <link rel="stylesheet" href="css/main.css"
> media="screen,projection,tv,tty,handheld,embossed,braille,aural"
> type="text/css">
> <link rel="stylesheet" href="css/print.css" media="print"
> type="text/css">
> </head>
> <body>
> <div id="header">
> <h1>HEADER INFORMATION (or image) HERE</h1>
> <br />
> <!-- end header div -->
> </div>
> <div id="mainNav">
> <?php
> *$main_navigation_list* = array(0 => array( 'name' => 'Home',
>
> 'url' => 'index.php?page=Contact',
>
> 'title' => 'The home page'),
>
> 1 => array('name' =>
> 'Contact' ,
> 'url'
> => 'index.php?page=Contact',
>
> 'title' => 'The contact details')
> );
> ?>
> <ul id="main_nav_list">
> <?php
> foreach(*$main_navigation_list* as *$index* => *$nav_list*)
> {
> echo '<li><a href="' . *$nav_list*['url'] .'" title="' .
> *$nav_list*['title'] . '">'. *$nav_list*['name'] . '</a></li>';
> }
> ?>
> </ul>
> </div>
>
> <!-- end mainNav div -->
> </div>
>
> --------------- END header.inc ----------
>
>
>
> In the header.inc I've manually created an array, then got PHP to go
> through the array to add the name, URL and other details from the array,
> but that's just to simplify this, usually I pull the navigation data
> from a database (or if there's no MySQL installed I might unserialise it
> from a file).
>
> There are other ways of pulling the data. If you want nice URLs, you can
> have something like /pages/Home/ and then have a mod_rewrite rule in
> Apache to then change that into index.php?page=Home, (although you'll
> also need to change the <a href> to the new links. If you aren't running
> on apache, you can manually find the page information by doing
> print_r($_SERVER), and seeing what bits and pieces you can put together,
> but that's not nearly as good or reliable.
>
> Sorry if there's too much info, but I'm guessing this is roughly what
> you'll be doing.
> If you want to have more than one variable (like say a sub page) then
> you add *&* between each variable. E.g
>
> <a href="index.php?page=Home&sub_page=more%20news">Home -
> Archived News</a>
>
> You can usually get away with just using *&* as the separator but it
> probably won't validate properly if your making it in xhtml (as you
> should be). Also, if your not sure what the %20 means (a space) then
> look up urlencode <http://au.php.net/manual/en/function.urlencode.php>
> and urldecode <http://au.php.net/url_decode>.
>
> Michael Kubler
> *G*rey *P*hoenix *P*roductions <http://www.greyphoenix.biz>
>
>
>
> Christopher W wrote:
>> At least I hope it is simple...
>>
>> I am trying to get an HTML menu link to set a variable's value. For
>> example, when a user clicks the "Home" button on my page it would cause
>> $page = "home"; or clicking the "About Us" button will set
>> $page="about_us";
>> etc.
>>
>> I think this should be fairly simple but being completely new to php I
>> just
>> cannot seem to get it right.
>>
>> Any help would be greatly appreciate.
>>
>> Thank you in advance.
>>
>
--- End Message ---
--- Begin Message ---
Michael Kubler schrieb:
The easiest way would be to use GET parameters (i.e data in the actual
URL).
There are a number of ways you can structure a HTML link to get what you
want.
You can have something basic (but not very elegant looking), like
<a href="index.php?page=Home">Home</a>
Then in your index.php code you'd probably have something like :
<?php
$page = urldecode(*$_GET['page']); *
include_once header.inc; //Include a script that contains the
general header information
if(is_file(pages/*$page*.inc;)) //make sure they haven't requested a
non-existant file
{
include_once pages/*$page*.inc; //Doesn't have to be .inc you
could simply output HTML data if that's all your using.
}
else
{
include_once pages/Home.inc; //If the user wanted a file that
doesn't exist, then just take them to the home page (or you could
take them to an error page if that's what you want).
}
include_once footer.inc; //Which would contain the footer if you've
got one.
?>
This is approximately how I do it although sometimes have a functions
file I call, or a config file with basic presets, and various other
things. I use .inc (for inclusion) as the file extension, so I can
easily differentiate between .php files that customers will use (such as
index.php, admin.php, login.php, etc..), and the included files.
In the header file I usually have something like that below.
----------- header.inc starts below this line ---------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<title><?php echo *$page*; ?> - Insert Company or Website Name</title>
<!-- Meta Tags -->
<meta http-equiv="content-type" content="application/xhtml+xml;
charset=utf-8">
<meta name="robots" content="index, follow">
<!-- CSS -->
<link rel="stylesheet" href="css/main.css"
media="screen,projection,tv,tty,handheld,embossed,braille,aural"
type="text/css">
<link rel="stylesheet" href="css/print.css" media="print"
type="text/css">
</head>
<body>
<div id="header">
<h1>HEADER INFORMATION (or image) HERE</h1>
<br />
<!-- end header div -->
</div>
<div id="mainNav">
<?php
*$main_navigation_list* = array(0 => array( 'name' => 'Home',
'url' => 'index.php?page=Contact',
'title' => 'The home page'),
1 => array('name' =>
'Contact' ,
'url'
=> 'index.php?page=Contact',
'title' => 'The contact details')
);
?>
<ul id="main_nav_list">
<?php
foreach(*$main_navigation_list* as *$index* => *$nav_list*)
{
echo '<li><a href="' . *$nav_list*['url'] .'" title="' .
*$nav_list*['title'] . '">'. *$nav_list*['name'] . '</a></li>';
}
?>
</ul>
</div>
<!-- end mainNav div -->
</div>
--------------- END header.inc ----------
In the header.inc I've manually created an array, then got PHP to go
through the array to add the name, URL and other details from the array,
but that's just to simplify this, usually I pull the navigation data
from a database (or if there's no MySQL installed I might unserialise it
from a file).
There are other ways of pulling the data. If you want nice URLs, you can
have something like /pages/Home/ and then have a mod_rewrite rule in
Apache to then change that into index.php?page=Home, (although you'll
also need to change the <a href> to the new links. If you aren't running
on apache, you can manually find the page information by doing
print_r($_SERVER), and seeing what bits and pieces you can put together,
but that's not nearly as good or reliable.
Sorry if there's too much info, but I'm guessing this is roughly what
you'll be doing.
If you want to have more than one variable (like say a sub page) then
you add *&* between each variable. E.g
<a href="index.php?page=Home&sub_page=more%20news">Home -
Archived News</a>
You can usually get away with just using *&* as the separator but it
probably won't validate properly if your making it in xhtml (as you
should be). Also, if your not sure what the %20 means (a space) then
look up urlencode <http://au.php.net/manual/en/function.urlencode.php>
and urldecode <http://au.php.net/url_decode>.
Michael Kubler
*G*rey *P*hoenix *P*roductions <http://www.greyphoenix.biz>
Christopher W wrote:
At least I hope it is simple...
I am trying to get an HTML menu link to set a variable's value. For
example, when a user clicks the "Home" button on my page it would
cause $page = "home"; or clicking the "About Us" button will set
$page="about_us"; etc.
I think this should be fairly simple but being completely new to php I
just cannot seem to get it right.
Any help would be greatly appreciate.
Thank you in advance.
I think this is the best way to open hackers a door to your system. Read
more about PHP please.
Regards
Carlos Medina
--- End Message ---