Jump to content

Change content based on many urls


Wunderkid

Recommended Posts

Hello!

I`m newbie and just started with php. Could you help me?

I want to change text based on many url.

I write code, but it filtering only one url icon_sad.gif

 

<?php
$ref=getenv('HTTP_REFERER');
if (strpos($ref,"www.site.com/news")>0)
{
echo "News;
}
else
{
echo "";
};
?>

 

I want to make something like that, but it is not working, maybe you can edit it make it work :)

 

<?php
$ref=getenv('HTTP_REFERER');
if (strpos($ref,"www.site.com/1")>0)
{
echo "1;
}
else
{
if (strpos($ref,"www.site.com/2")>0)
{
echo "2;
}
else
{
if (strpos($ref,"www.site.com/3")>0)
{
echo "3;
}
else
{
?>

Link to comment
Share on other sites

I don't think you want to use HTTP_REFERER. For one, you're not guaranteed that it will have a value. Two, HTTP_REFERER refers to the previous site the user was on. So, if I came here from google, HTTP_REFERER (if it had a value) would be http://www.google.com.

 

If you're trying to do what I think you want, you instead need to use query strings. If you have a url like:

 

www.site.com/index.php?p=news

 

The part starting at the '?' is known as a query string. You can grab its value by using the $_GET[] superglobal array, like so:

 

$page = $_GET['p']; // $page now contains 'news'

 

Obviously, you'd need to ensure that:

 

1. 'p' exists

2. it doesn't contain bad/dangerous data

 

But that's the general idea.

 

To make that work with a 'pretty' url, like:

 

www.site.com/news

 

You'll need to write a .htaccess file with the appropriate mod_rewrite rule(s). I suck at writing those, so someone else can address that part of it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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