meriwynn Posted May 2, 2008 Share Posted May 2, 2008 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 More sharing options...
DyslexicDog Posted May 2, 2008 Share Posted May 2, 2008 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. Link to comment https://forums.phpfreaks.com/topic/103876-need-help-creating-meta-tags/#findComment-531763 Share on other sites More sharing options...
meriwynn Posted May 2, 2008 Author Share Posted May 2, 2008 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 Link to comment https://forums.phpfreaks.com/topic/103876-need-help-creating-meta-tags/#findComment-531769 Share on other sites More sharing options...
DyslexicDog Posted May 2, 2008 Share Posted May 2, 2008 Can you change the code to this and see if there's any output? mt_srand((double)microtime() * 1000000); print_r($thisData); $index = mt_rand(0, sizeof($thisData)-1); Link to comment https://forums.phpfreaks.com/topic/103876-need-help-creating-meta-tags/#findComment-532064 Share on other sites More sharing options...
DarkWater Posted May 2, 2008 Share Posted May 2, 2008 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. Link to comment https://forums.phpfreaks.com/topic/103876-need-help-creating-meta-tags/#findComment-532067 Share on other sites More sharing options...
DyslexicDog Posted May 3, 2008 Share Posted May 3, 2008 Which function do you need to see the code for? Link to comment https://forums.phpfreaks.com/topic/103876-need-help-creating-meta-tags/#findComment-532291 Share on other sites More sharing options...
meriwynn Posted May 5, 2008 Author Share Posted May 5, 2008 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... Link to comment https://forums.phpfreaks.com/topic/103876-need-help-creating-meta-tags/#findComment-533367 Share on other sites More sharing options...
DyslexicDog Posted May 5, 2008 Share Posted May 5, 2008 Are the ad pages called with includes? If not you may need to use java script or a database to pass information. Javascript being client side is unreliable, IMO a database might be the best way to handle this. Link to comment https://forums.phpfreaks.com/topic/103876-need-help-creating-meta-tags/#findComment-533388 Share on other sites More sharing options...
thebadbad Posted May 5, 2008 Share Posted May 5, 2008 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 ?> Link to comment https://forums.phpfreaks.com/topic/103876-need-help-creating-meta-tags/#findComment-533408 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.