Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 31st, 2003, 02:32 PM
Authorized User
 
Join Date: Jun 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to natmaster Send a message via AIM to natmaster Send a message via MSN to natmaster
Default php in html

as part of my context handling code for my frames, if a visitor comes from a site and enters mine attempting to goto any file other than my framset page, it will record where they came from in a session variable, then redirect them to my frameset page with appropriate directions to display that file within the frame....then my counter will record where they came from and what page they were trying to view.

in my php pages this works fine, i use:
<?php include('../assets/include/header.php'); ?>

(here is my header.php file)
<?php
session_start();
$_SESSION['referrer']=$_SERVER['HTTP_REFERER'];
?>

but on my html pages it won't record the information properly, $_SESSION['referrer'] will end up being blank when the visitor came from another website.

here is what i tried:
<script language="php" type="text/php" runat="server" src="../assets/include/header.php"></script>
i also tried using an image to include the php file, but that didn't help.

i thought maybe the problem was that header.php was actually running seperatly, rather than being included in the html file's execution....

any words of wisdom?

----------------------------
http://aeonofdarkness.com
__________________
----------------------------
Aeon of Darkness MUD - Free Online Roleplaying Game
http://aeonofdarkness.com
 
Old July 31st, 2003, 02:41 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, the HTTP_REFERER variable is set by the client's browser. There's no guarantee that it ever WILL be set. If a user is at some other site, and manually types in your URL, the referer will not likely be set. If a user clicks a link on another page and goes to your site, odds are the referer will be set.

I would change your "include" to "require_once". include() doesn't require the target file to be included... if it does not exist, or the paths/permissions are wrong, PHP just issues a warning about it and continues execution. If your PHP is set up to ignore warnings, you're left completely in the dark about why things are not working properly.

Have you tried directly accessing these non-frameset pages yourself to see if the HTTP_REFERER is set? Session data should persist across multiple redirects, but you should make sure that you start the session on every page to keep the session alive.


Take care,

Nik
http://www.bigaction.org/
 
Old July 31st, 2003, 02:52 PM
Authorized User
 
Join Date: Jun 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to natmaster Send a message via AIM to natmaster Send a message via MSN to natmaster
Default

i am familiar with when referer is set, i think you misunderstood my problem. the files that are php and use the include() work perfectly, i tested it myself. it is the html files that i can't figure out how to get to work right.

----------------------------
http://aeonofdarkness.com
 
Old July 31st, 2003, 02:52 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh crap, wait a minute -- I just realized something.

When you attempt to execute PHP in HTML files using the <script> tag, you need to make sure that your webserver is configured to treat .html files as PHP files and run them through the interpreter.

The proper way to embed PHP in an HTML file is to use <script langauge="php"> as a replacement for <?php. (</script>, therefore, obviously replaces ?>).

Example:
Code:
<html>
<head><title>&lt;script language="php"&gt;</title></head>
<body>
<script language="php">
session_start();
if(!isset($_SESSION['count']))
    $_SESSION['count'] = 0;

++$_SESSION['count'];
echo "Hello, world!  You've seen this page {$_SESSION['count']} times.";
</script>

</body>
</html>

Take care,

Nik
http://www.bigaction.org/
 
Old August 1st, 2003, 02:48 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Setting up your interpreter to parse .html, or .htm pages can (usually) be done through a .htaccess file (depending on server configuration). If you're on a third party ISP send in a tech support query to see how it can be done for your server's configuration. Or do a Google search to find someone who's already done it.

I missed your reply on the '$GLOBALS' post, about the same topic, sorry. I didn't realize that the Javascript was in an included file and on non PHP enabled page.

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::





Similar Threads
Thread Thread Starter Forum Replies Last Post
write HTML into TEXTAREA using PHP anshul PHP How-To 6 March 27th, 2009 12:15 PM
Passing variables from HTML to php manunair PHP How-To 9 April 9th, 2006 11:27 PM
Writing on html templates using PHP anshul Pro PHP 12 January 5th, 2005 03:09 PM
php doesn't pick up an html variable m3rajk Beginning PHP 11 July 25th, 2003 07:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.