Jump to content

Archived

This topic is now archived and is closed to further replies.

spfoonnewb

Posting title using $_GET

Recommended Posts

Is this possible?

I defined title on the page being includded using:

[code]<?php
$title = 'Title';
$title2 = 'Description';
?>[/code]

Then I tried to call it on the page with the array/dynamic include using:

[code]<?php
$title = $_GET['title'];
$title2 = $_GET['description'];
echo '<title>$title</title>';
echo '<description>$title2</description>';
?>[/code]

Why doesnt that work?

Share this post


Link to post
Share on other sites
What you're asking for doesn't make sense.

What about it doesn't make sense?  Are you passing $title and $title2 in the url?  If not, why are you using $_GET?

Share this post


Link to post
Share on other sites
Im using $_GET cause thats the idea, and post doesnt work.

Basically I want the value defined in the page being included

And the page that is doing the inclusion to post it

Share this post


Link to post
Share on other sites
Use double quotes:

[code]echo "<title>$title</title>";
echo "<description>$title2</description>";[/code]

Share this post


Link to post
Share on other sites
Hitman is right! It ain't working because single quotes will not parse variables, don't ask why!
They also do not parse newlines (\n) therefore you need to use double quotes, they will do the trick... There goes my fine neat coding...

Share this post


Link to post
Share on other sites
Ok, well whether I define it using

[code]<?php
$title = 'Title';
$title2 = 'Description';
?>[/code]

Or

[code]<?php
$title = "Title";
$title2 = "Description";
?>[/code]

And Use

[code]<?php
$title = $_GET['title'];
$title2 = $_GET['description'];
echo "<title>$title</title>";
echo "<description>$title2</description>";
?>[/code]

Or

[code]<?php
$title = $_POST['title'];
$title2 = $_POST['description'];
echo "<title>$title</title>";
echo "<description>$title2</description>";
?>[/code]

The output does not contain "Title" Although it was defined and it just looks like:

[code]<title></title><description></description>[/code]

Share this post


Link to post
Share on other sites
Now I think it doesnt work because its being called before its defined.

It's defined halfway through the inclusion page not the top, and its called at the top of the inclusion page.

But it doesnt work well unless its in the head, so I dunno.

Is there a way to say : Execute this last! :?

Share this post


Link to post
Share on other sites
Please put these lines at the top of you script:
[code]<?php
if (isset($_GET)) echo '<pre>$_GET: ' . print_r($_GET,true) . '</pre>';
if (isset($_POST)) echo '<pre>$_POST: ' . print_r($_POST,true) . '</pre>';
?>[/code]
and post whatever is printed on your screen.

If you are not starting your script from a forn or using someother way to pass data via the POST array, you will get nothing when using $_POST. If there are not values on the URL, there will be nothing in $_GET.

Also describe exactly what you are trying to do. Post all the scripts if necessary.

Ken

Share this post


Link to post
Share on other sites
heres what that gave me:

[code]$_GET: Array
(
    [p] => test
)

$_POST: Array
(
)[/code]



Leme type some more

Share this post


Link to post
Share on other sites
So there is no title= or description= on the URL. That's why you're not seeing anything.

Ken

Share this post


Link to post
Share on other sites
I am basically using:

[code]<?php
   $pages = array(
               'test' => 'includes/test.php',

       );
           
           if (isset($_GET['p']) && isset($pages[$_GET['p']]))
               {
                   include($pages[$_GET['p']]);
                   } else {
                   header("Location:index.php");
               }

?>[/code]

So I am trying to title the page based on what I want it to be.

So what I tried to do was define the title in the page being included i.e: test.php

Then on the page doing the inclusion I added a $_POST or $_GET to try and get that variable that was defined.

The script looks kinda like this:

[code]
<html>
<head>
<title>$_GET/POST[title];</title>
</head>
<body>
THE ARRAY
</body>
</html>
[/code]

test.php Is whatever I want it to be and I am trying to define the title.

[code]<?php
$title = 'Title';
$title2 = 'Description';
?>[/code]

Share this post


Link to post
Share on other sites
I use a header and a footer page that are generic and then a content page that differes for each page.. In the header page I have this:
[code]<?php

echo<<<FACE_BEGIN
<!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>
<title>$title</title>[/code] and it continues on with the rest of the header... In the content page it is like this:
[code]<?php

/* Page Title */
$title="Paige's Movies";[/code] and that continues... If you want to see the pages go to www.paigejohnston.com... The front page doesn't use this format, but every other page on the site does.

Share this post


Link to post
Share on other sites
Ok I know exactly what you are trying to do. I just figured it out for my own website. Try this. On the page being included, before everything else a he floowing code.

[code]
<?php

$pages = array(
                'test' => 'includes/test.php',

        );
           
            if (isset($_GET['p']) && isset($pages[$_GET['p']]))
                {

                   $title = "[i]title[/i]";
                   $description = "[i]description[/i]"; //Can also be $pages or whatever your varible is
                }else{
                     $title = "[i]alternate_title[/i]"; //You can leave blank
                     $descrition = "[i]alternate_description[/i]"; //You can leave blank
               }
?>
[/code]

Then where you call these put this:
[code]<?php echo $title; ?>
<?php echo $description; ?>[/code]

or however you want to call them

Below is an example of the script my site uses:

[code]<?PHP
$valid_pages = array('news', 'about', 'contact', 'pricing', 'portfolio', 'main', 'legal');
$page = $_GET['page'];
if (in_array($page, $valid_pages))
{
$subTitle = $title." - ".$page;
}
else
{
$subTitle = $title;

}
?>[/code]

then when I call the script I used:

[code]<title><?php echo $subTitle; ?></title>[/code]

Share this post


Link to post
Share on other sites
use
[code]
echo "<title>{$_GET[title]}</title>";
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.