simonp Posted May 17, 2006 Share Posted May 17, 2006 Hi all,I'm using the code below to check that a user is coming from the correct page before allowing them to go on.It works for all but one page which passes a string in the URL, eg>[a href=\"https://www.mywebsite.com/page4.php?name=william\" target=\"_blank\"]https://www.mywebsite.com/page4.php?name=william[/a] etcHow can I make the code check that the first part is correct but ignore everything after page4.php?CheersSimon[code]<?phpif ($_SERVER['HTTP_REFERER'] != "https://www.mywebsite.com/page5.php") { header("Location: https://www.mywebsite/page1.php"); break; // END case 'OK'}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9855-string-question/ Share on other sites More sharing options...
kenrbnsn Posted May 17, 2006 Share Posted May 17, 2006 Take a look at the [a href=\"http://www.php.net/parse_url\" target=\"_blank\"]parse_url()[/a] function.Ken Quote Link to comment https://forums.phpfreaks.com/topic/9855-string-question/#findComment-36610 Share on other sites More sharing options...
simonp Posted May 17, 2006 Author Share Posted May 17, 2006 Hi folks,I can get the whole URL using[code] $refurl = $_SERVER['HTTP_REFERER']; print_r(parse_url($refurl));[/code]but how can I JUST get the scheme (https), the host and the path (ie withouth the query)?Not too good with arrays.Cheers Quote Link to comment https://forums.phpfreaks.com/topic/9855-string-question/#findComment-36698 Share on other sites More sharing options...
kenrbnsn Posted May 17, 2006 Share Posted May 17, 2006 Try:[code]<?php $refurl = $_SERVER['HTTP_REFERER']; $parsed = parse_url($refurl)); foreach($parsed as $key => $value) echo '$parsed[' . $key . '] = ' . $value . "<br>\n";?>[/code]The [b]scheme[/b] is in [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$parsed['scheme'][!--colorc--][/span][!--/colorc--]The [b]host[/b] is in [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$parsed['host'][!--colorc--][/span][!--/colorc--]The [b]path[/b] is in [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$parsed['path'][!--colorc--][/span][!--/colorc--]You really should learn to use arrays as they are very powerful in PHP and other programming languages.Ken Quote Link to comment https://forums.phpfreaks.com/topic/9855-string-question/#findComment-36711 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.