Jump to content


Photo

Posting title using $_GET


  • Please log in to reply
13 replies to this topic

#1 spfoonnewb

spfoonnewb
  • Members
  • PipPipPip
  • Advanced Member
  • 276 posts

Posted 04 August 2006 - 07:21 PM

Is this possible?

I defined title on the page being includded using:

<?php
$title = 'Title';
$title2 = 'Description';
?>

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

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

Why doesnt that work?


#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 04 August 2006 - 07:23 PM

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?

#3 spfoonnewb

spfoonnewb
  • Members
  • PipPipPip
  • Advanced Member
  • 276 posts

Posted 04 August 2006 - 07:26 PM

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

#4 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 04 August 2006 - 07:29 PM

Use double quotes:

echo "<title>$title</title>";
echo "<description>$title2</description>";


#5 ignace

ignace
  • Moderators
  • Now mod flavored
  • 6,430 posts
  • LocationBelgium

Posted 04 August 2006 - 07:31 PM

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...

#6 spfoonnewb

spfoonnewb
  • Members
  • PipPipPip
  • Advanced Member
  • 276 posts

Posted 04 August 2006 - 07:34 PM

Ok, well whether I define it using

<?php
$title = 'Title';
$title2 = 'Description';
?>

Or

<?php
$title = "Title";
$title2 = "Description";
?>

And Use

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

Or

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

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

<title></title><description></description>


#7 spfoonnewb

spfoonnewb
  • Members
  • PipPipPip
  • Advanced Member
  • 276 posts

Posted 04 August 2006 - 08:11 PM

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! :?

#8 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 04 August 2006 - 08:15 PM

Please put these lines at the top of you script:
<?php
if (isset($_GET)) echo '<pre>$_GET: ' . print_r($_GET,true) . '</pre>';
if (isset($_POST)) echo '<pre>$_POST: ' . print_r($_POST,true) . '</pre>';
?>
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


#9 spfoonnewb

spfoonnewb
  • Members
  • PipPipPip
  • Advanced Member
  • 276 posts

Posted 04 August 2006 - 08:18 PM

heres what that gave me:

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

$_POST: Array
(
)



Leme type some more


#10 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 04 August 2006 - 08:20 PM

So there is no title= or description= on the URL. That's why you're not seeing anything.

Ken

#11 spfoonnewb

spfoonnewb
  • Members
  • PipPipPip
  • Advanced Member
  • 276 posts

Posted 04 August 2006 - 08:25 PM

I am basically using:

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

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

?>

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:

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

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

<?php
$title = 'Title';
$title2 = 'Description';
?>


#12 FFEMTcJ

FFEMTcJ
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 04 August 2006 - 10:45 PM

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:
<?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>
and it continues on with the rest of the header... In the content page it is like this:
<?php

/* Page Title */
$title="Paige's Movies";
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.

#13 SithLord2K

SithLord2K
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 24 October 2006 - 03:59 AM

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.

<?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
               }
?>

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

or however you want to call them

Below is an example of the script my site uses:

<?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;
	
}
?>

then when I call the script I used:

<title><?php echo $subTitle; ?></title>


#14 fert

fert
  • Members
  • PipPipPip
  • Advanced Member
  • 1,114 posts

Posted 24 October 2006 - 04:21 AM

use
echo "<title>{$_GET[title]}</title>";


Si hoc legere scis nimium eruditionis habes
Gentoo Linux 2007.0 Firefox 2




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users