Does anyone know how to 'send' a variable from one PHP script to another? I am trying to do this: If I create a variable in a PHP page ("$title"), and I want to send it to a script ("nav.php") o create navigation, how would I go about doing that? - tf
I'm not sure how your scripts work exactly, something like this maybe? Code: <a href="nav.php?title=<?=$title?>">linkie</a>
If youre including nav.php into the main script ala: Code: include("nav.php"); Then nav.php will inherit the variable from the parent script. If nav.php is a seperate webpage, just make the link like this: Code: echo "<a href='nav.php?title=$title'>Nav</a>";
I don't understand exactly what you are trying to do, but there are two basic methods of exchanging data between PHP pages. GET and POST. GET retrieves values from the URL. IE: PHP: <?php echo "Var = " . $_GET['var']; ?> If you store that in file.php, and type in your address bar (or link) as: www.homepage.com/file.php?var=hello Then it will display on the page "Var = hello". The other is POST and is used mainly for forms. ie: you have a web page that has the following html: Code: <form action="file.php" method="POST"> <input name="var" type="text"> <input type="submit" value="Go to next page"> </form> and then you have a PHP page, called file.php with: PHP: <?php echo "Var = " . $_POST['var']; ?> Then whatever you type in the text box will appear in the next page, when you click the button. Also, if you want to redirect a page, before you echo anything or write anything to screen, if you do: PHP: $url = "url/togoto.php"; header( "Location: $url" ); It will redirect to there. HTH.
Here is my code (important stuff in bold): Code: <?php // Finds the root directory $root_dir = "http://home.thursday.com/_taylor"; // Sets the title [b]$title = basename(__FILE__, ".php");[/b] ?> <html> <head> <title>thursday # <?php echo("$title"); ?></title> <link href="<? echo($root_dir . "/includes"); ?>/style.css" rel="stylesheet" type="text/css"> </head> <div align="center"> <table border="1" cellspacing="3" cellpadding="3" style="border-collapse: collapse" bordercolor="#000066" width="600"> <tr> <td width="600" colspan="2" valign="middle"> <p align="center"><img src="<? echo($root_dir); ?>/images/header.png" hspace="5" vspace="5"> </td> </tr> <tr> <td width="100" valign="top" align="right"> <div class="nav"> [b]<? include_once("$root_dir/includes/nav.php"); ?>[/b] </div> </td> <td width="500" valign="top" align="left"> <div id="main2"> <div id="punch2"><img src="images/logo.png" height="100" width="100"></div> <h2><? echo $title; ?></h2> <p> <? $content =<<<EOT Hello, and welcome to the EOT; $content .= $title; $content .=<<<EOT part of thursday. Thanks for visiting. <br><br><br> EOT; ?> <? echo $content; ?> </p> <div id="end2"> <h3> <? $author = taylor; $mail = "admin@thursday.com"; $date = "04/14/04"; $content =<<<EOT $author - $date<br><a href="mailto:$mail"><i>$mail</i></a> EOT; echo($content); ?> </h3> </div> </div> </td> </tr> <tr valign="middle"> <td width="100%" height="25" colspan="2" align="left"> <div align="center" class="copy">© Taylor Fausak 2004</div> </td> </tr> </table> </div> </body> </html> And here is the code for 'nav.php': Code: <!-- index --> <? if ($title == "index") { $nav .= "index +"; } else { if (file_exists("../index.php")) { $nav .=<<<EOT <a href="./index.php">index</a> EOT; $nav .= " #"; } else { $nav .= "index -"; } } ?> <? $nav .= "<BR><BR>"; ?> <!-- /index --> <!-- projects --> <? if ($local == "projects") { $nav .= "+ projects +"; } else { if (file_exists("../projects.php")) { $nav .= "# "; $nav .=<<<EOT <a href="./projects.php">projects</a> EOT; $nav .= " #"; } else { $nav .= "- projects -"; } } ?> <? $nav .= "<BR>"; ?> <!-- /projects --> <!-- simplicity --> <? if ($local == "simplicity") { $nav .= "simplicity +"; } else { if (file_exists("../simplicity.php")) { $nav .=<<<EOT <a href="./simplicity.php">simplicity</a> EOT; $nav .= " #"; } else { $nav .= "simplicity -"; } } ?> <? $nav .= "<BR><BR>"; ?> <!-- /simplicity --> <!-- mods --> <? if ($local == "mods") { $nav .= "+ mods +"; } else { if (file_exists("../mods.php")) { $nav .= "# "; $nav .=<<<EOT <a href="./mods.php">mods</a> EOT; $nav .= " #"; } else { $nav .= "- mods -"; } } ?> <? $nav .= "<BR>"; ?> <!-- /mods --> <!-- mobo paint --> <? if ($local == "mobo paint") { $nav .= "mobo paint +"; } else { if (file_exists("../mobo paint.php")) { $nav .=<<<EOT <a href="./mobo paint.php">mobo paint</a> EOT; $nav .= " #"; } else { $nav .= "mobo paint -"; } } ?> <!-- /simplicity --> <? echo $nav; ?> The site is at http://www.thursday.com/_taylor As you can see, it is added in by using 'include_one();' but that doesn't seemt o work. - tf
The thing I notice immediately about your bold text is it should be this: PHP: <? include_once($root_dir . "/includes/nav.php"); ?> What you were doing was trying to include: "http://$rootdir/includes/nav.php", but now it should be correct. That's for starters anyway.
you could try using hidden form fields give it a name then put the value as the variable that you are trying to send then post to the nav page, if this is included you could force a meta refresh on the page itself which would reload the page, then the variable would be sent to your nav page. i prefer using hiddne variables as the name suggest they are hidden and not displayed to the public like they would be if you put them in the url bar. failing this you could use sessions but it looks like you just want a simple solution for your nav bar so using sessions seems a bit overkill to me for this.
I have a remedial knowledge aobut sessions, so I don't think that it would be that much overkill. That, and it would help me on future websites. - tf