Jump to content

Need help creating meta tags


meriwynn

Recommended Posts

Hi --

 

I'm new to php and having to learn it in a hurry for my job. I've encountered a problem:

 

I need to write a script that will produce a meta tag on a dynamically produced web page. I've run a search on the forum, but couldn't find anything that seemed to address my problem.

 

In detail: I'm creating an html page dynamically from two php files. My site has a row of ads and each ad spot actually holds an array of three ads. Each ad spot has its own page with the array of the ads and a function that randomly chooses which ad to display each time the page is loaded. The actual html page is generated with a combination of template file and these ad array files.

 

For SEO purposes, I need to create a script that identifies which ad is showing (each ad in the array has an unique name), takes the name of that ad currently showing and inserts it into the "content" section of a dynamically generated meta tag.

 

The randomize function is legacy code and works fine. it's just my "contributions" to it that are messing things up. Here's what I've got so far:

 

The dynamically generated page (call it 'createdPage') displays an error message that says:

 

Fatal error: Only variables can be passed by reference in /[some file path]/ad-array.php

 

Here's the code of the ad array page:

 

PHP Code:

 $thisData = array();
array_push($thisData, "ad1Name");
array_push($thisData, "ad2Name");
array_push($thisData, "ad3Name");

*******
randomize function code
*******

array_push($GLOBALS['adName'] . $thisData[index]);

 

 

On the template page I have the following code:

 

PHP Code:

$adName = array();
print ('<meta name="WT.ad" content="' . $adName . '">'); 

 

 

The tag that should appear on createdPage should be:

<meta name="WT.ad" content="adName">

 

The tag that currently does appear is:

<meta name="WT.ad" Content="Array">

 

Help!

 

Jade

Link to comment
https://forums.phpfreaks.com/topic/103876-need-help-creating-meta-tags/
Share on other sites

Well that error you have should have a line number associated with it. Could you post the line of code that's throwing that error?

 

most likely from the look of that error there is a reference or "pointer" on a non variable.

 

There is: line 21 (sorry I missed that before...it's been a difficult week). The code at line 21 is part of the randomizer. Here's that line and the one before it:

 

mt_srand((double)microtime() * 1000000);
$index = mt_rand(0, sizeof($thisData)-1);

 

Thanks for taking the time to help me out.

 

Jade

That's not the problem.  He's trying to pass the array element to the function by reference and not the array itself.  I think, at least.  He never showed us the function code.

 

Actually, what I posted is the whole code. I'm simply trying to move the value of one variable -- $thisData[index] -- into the meta tag creator on the template page.

 

print ('<meta name="WT.ad" content="' . $adName . '">'); 

 

I need a way to make $adName (on the template page) hold the value of $thisData (from the ad array page).

 

Thanks for all the help so far...

 

This doesn't make sense:

 

$adName = array();
print ('<meta name="WT.ad" content="' . $adName . '">');

 

You're defining $adName as an empty array, and then you try to print it, which can't be done (you can only print/echo an element of an array). You should do like this (including the randomizer):

 

ads.php

<?php
$thisData = array();
$thisData[] = 'ad1Name';
$thisData[] = 'ad2Name';
$thisData[] = 'ad3Name';

//pick a random ad and define the index
$index = rand(0, count($thisData) - 1);
?>

 

template file

<?php
//start of the page goes here
include 'ads.php';
echo '<meta name="WT.ad" content="', $thisData[$index], '">';
//rest of the code goes here
?>

Archived

This topic is now archived and is closed to further replies.

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