Jump to content

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?
Link to comment
https://forums.phpfreaks.com/topic/16580-posting-title-using-_get/
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...
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]
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! :?
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
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]
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.
  • 2 months later...
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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.