Wunderkid Posted February 21, 2013 Share Posted February 21, 2013 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 <?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 https://forums.phpfreaks.com/topic/274774-change-content-based-on-many-urls/ Share on other sites More sharing options...
KevinM1 Posted February 21, 2013 Share Posted February 21, 2013 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 https://forums.phpfreaks.com/topic/274774-change-content-based-on-many-urls/#findComment-1413906 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.