View Full Version : PHP Include... Again!

11-01-2005, 05:52 PM
Hey Guys,

Just wondering if its possible to do a "find and replace" on the content pulled in from a php include...??

I'm including some pages into my site (from an affiliate) but would like to change a bit of the code...


11-01-2005, 05:57 PM
You need to use an output buffer.

$inc = ob_get_contents();
You can then use str_replace() and friends on $inc, which is a string containing the page, before echoing it.

11-01-2005, 09:00 PM
use str_replace() and friends on $inc, which is a string containing the page, before echoing it.

$inc_new = str_replace("the text i want changing", "what i am changing it to?", $inc);

I'm not sure what you mean by
and friends on $inc.

11-02-2005, 04:26 PM
That's the one. Although you might as well reuse $inc, unless you'll want the original back again.

I'm not sure what you mean by
and friends on $inc.str_replace() and the other string functions (str_split(), substr(), &c.) as needed.

11-02-2005, 08:19 PM
Cheers for that.

Could you just quickly tell me what is wrong with the following code? (this has nothing to do with editing the accual page i am including...)

(before the Head)
setcookie("tracking", $tracking, time()+31536000);
$tracking = $_GET['tracking'];

(in the body)
if (isset($_COOKIE["tracking"]))
include ("http://www.affiliatewebsite.com/?tracking=" . $_COOKIE["tracking"]);

11-02-2005, 08:44 PM
setcookie("tracking", $tracking, time()+31536000);
$tracking = $_GET['tracking'];You've used $tracking before declaring it. The second argument to setcookie() will always be blank, and will throw a warning with E_STRICT error reporting.

11-02-2005, 09:04 PM
ok, i've swaped these over

$tracking = $_GET['tracking'];
setcookie("tracking", $tracking, time()+31536000);

if i use ?tracking=adwords after the url, a cookie is made, and everything works, but if i refresh the page, removing the ?tracking=adwords, the cookie gets deleted!

How can I stop this from happening??

The include also doesnt show if there is no "?tracking=xxxx" after the url

11-02-2005, 09:31 PM
The include doesn't show because the cookie doesn't get set. The cookie doesn't get set because you set a blank cookie if $_GET['tracking'] isn't set. Just use an if(isset($_GET['tracking'])) before the setcookie() call.

11-02-2005, 09:44 PM
i tried that,

the cookie still gets deleted if there is no ?tracking=xxxx

and again, no included page.

11-02-2005, 09:57 PM
Peculiar... please post your full code (inside [php] or [code] tags).

11-03-2005, 01:33 PM
before the head:

$handset = ("i-mate JASJAR");
$handsetclean = strtolower($handset);
$make = ("i-mate");
$makeclean = strtolower($make);
$makeclean2 = str_replace(" ", "-", $makeclean);
$id = ("jasjar");
$tracking = $_GET['tracking'];
$tariff = $_GET['tariff'];
$url = str_replace(" ", "-", $handsetclean);
if($_GET['tariff'] == "org") $network = (" On Orange");
if($_GET['tariff'] == "o2") $network = (" On O2");
if($_GET['tariff'] == "voda") $network = (" On Vodafone");
if($_GET['tariff'] == "tmob") $network = (" On T-Mobile");
if($_GET['tariff'] == "3xnet") $network = (" On Three");
if($_GET['tariff'] == "payg") $network = (" On Pay As You Go");
if($_GET['tariff'] == "simfree") $network = (" On SIM Free");
if($_GET['tariff'] == "xnet1") $network = (" With 100 Free Minutes");
if($_GET['tariff'] == "xnet2") $network = (" With 200 Free Minutes");
if($_GET['tariff'] == "xnet3") $network = (" With 300 Free Minutes");
if($_GET['tariff'] == "xnet4") $network = (" With 400 Free Minutes");
if($_GET['tariff'] == "xnet15") $network = (" With 500 Free Minutes");
if($_GET['tariff'] == "op") $network = (" With Free Off Peak Minutes");
if($_GET['tariff'] == "") $network = ("Online");
setcookie("tracking", $tracking, time()+31536000);

in the body:

<?php if(isset($_GET['tracking']))
include ("http://www.affiliate.com/iframe.asp?hs=$id&tariff=$tariff&col=crazy&ref=mysite.com&tracking=" .$_COOKIE["tracking"]);
include ("http://www.affiliate.com/iframe.asp?hs=$id&tariff=$tariff&col=crazy&ref=mysite.com&tracking=");

Not only does the cookie get deleted, but there is a delay with the tracking...

e.g. if i go to www.mysite.com/?tracking=blabla i need to refresh the page before it accually adds the tracking to the page i'm including.

11-03-2005, 04:31 PM
I sorted everything out.

I created a tracking.php page that creats a cookie, and refreshes to the correct page..

I then pull up the cookie within the php include url...