Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
setting page title with php using URL ?title=Homepage
Old 08-26-2004, 07:44 AM setting page title with php using URL ?title=Homepage
Skilled Talker

Posts: 79
Trades: 0
Hello

I read in a PHP book (written tin 2001) that I could set up variables by using the URL:

eg: http://www.primoweb.biz/index.php?name=hamish

Then, in that index.php file, I would have a bit which says

hello, <?php echo ("$name"); ?> and it would work.

Now, I am trying to cut a chunk of code out of my websites by doing the same thing for my page titles:

http://www.primoweb.biz/index.php?title=Homepage

and in the <title></title> tags for the page I could call the variable "$title" and it would print the word "Homepage".

However, I have tried this unsuccessfully.

Is this because this command is out of date? (it is an old book I saw it in) or is it because the variable is in the wrong place?

Thanks for any suggestions
Hamish
__________________

Please login or register to view this content. Registration is FREE
secure and fully automated computer data backup for small and medium sized companies.


Please login or register to view this content. Registration is FREE
hamish is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-26-2004, 10:17 AM
KeithMcL's Avatar
Super Talker

Posts: 128
Location: Dublin, Ireland
Trades: 0
Try changing the php code to
PHP Code:
<?php echo $_GET['$title']; ?>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
KeithMcL is offline
Reply With Quote
View Public Profile
 
Old 08-26-2004, 10:43 AM
Unknown.

Posts: 1,693
Trades: 0
This should do it...

PHP Code:
<?php 
$title 
$_GET['title'];
echo 
"<title>$title</title>";
?>
-James

Last edited by Dark-Skys99; 08-26-2004 at 11:42 AM..
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 08-26-2004, 11:23 AM
Skilled Talker

Posts: 79
Trades: 0
Hey

I tried that, but I wonder if the problem is the position of this variable on the page. Below is the part of my page which calls this variable:

PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>

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

<link rel="stylesheet" type="text/css" href="style.css">

</HEAD>

<BODY>
    <div class="container"><!-- insert container - this div is closed at the end of the specific pages -->
        <div class="clear"></div>

    <!-- start left menu -->

<div class="left">

<ul id="nav">
    <li><a href="index.php?title=Homepage" title="Home Page">Home Page</a></li>
    <li><a href="about.php?title=About_Me" title="About Me">About Me</a></li>
    <li><a href="music.php?title=Music" title="Music">Music</a></li>
    <li><a href="#.php" title="">Other Links</a></li>
</ul>


    <!-- end menu -->
</div> <!-- left -->


<div class="main"><!-- starts on this page and finished on the individual pages -->

<div class="top"><img id="logo" src="./images/blah.gif" height="90px" width="320px" alt="Welcome to blah"></div>

break" src="./images/break_pink.gif">
This page top.php is included in the rest of the pages at the top of the page.

I wonder if the fact that the menu is further down the page than the "echo "$title"" would affect it. I guess it shouldn't given that the page should get the variable $title from the URL itself.

I wonder if the reason it isn't working is a silly mistake on my part.

Any suggestions?

Thanks again
Hamish
__________________

Please login or register to view this content. Registration is FREE
secure and fully automated computer data backup for small and medium sized companies.


Please login or register to view this content. Registration is FREE
hamish is offline
Reply With Quote
View Public Profile
 
Old 08-26-2004, 11:38 AM
Novice Talker

Posts: 9
Trades: 0
Hey Hamish,

You don't need the $ to refer to variables in a querystring or POST request. Therefore:

<?php echo $_GET["title"] ?>

should work for you.

If not, it might be that 'Superglobal' variables aren't available in the version of PHP which you are using. Then you can try:

<?php echo $HTTP_GET_VARS["title"]; ?>

In either case, you don't use the dollar because the 'title' is just an array reference, taken from the Name/Value pair in the querystring, and not a *real* variable.

Hope this helps
stigthew is offline
Reply With Quote
View Public Profile
 
Old 08-26-2004, 11:49 AM
Unknown.

Posts: 1,693
Trades: 0
Just realised that...

Stupid mistake

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 08-26-2004, 12:00 PM
Skilled Talker

Posts: 79
Trades: 0
Thanks stigthew

Both of the codes you gave me work. Thank you very very much for this - i reckon that I can cut about 20 lines out of all my pages!

thanks
Hamish
__________________

Please login or register to view this content. Registration is FREE
secure and fully automated computer data backup for small and medium sized companies.


Please login or register to view this content. Registration is FREE
hamish is offline
Reply With Quote
View Public Profile
 
Old 08-26-2004, 12:29 PM
Novice Talker

Posts: 9
Trades: 0
Happy to be of assistance
stigthew is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to setting page title with php using URL ?title=Homepage
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.00213 seconds with 12 queries