/    Sign up×
Community /Pin to ProfileBookmark

Finding the first part of a url

Hi,

I am doin this to check that it has come from a certain page

[code=php]
if($_SERVER[‘HTTP_REFERER’] !== “http://127.0.0.1/link.php”
[/code]

This works great but that i because it is location to an actual file i.e link.php. How do i get it so that it it will work when i put it as [url]http://127.0.0.1/[/url] it doesn’t work just doing it like that i think it needs something like

[code=php]
!== ??something like first 17 charactors or watever =(“http://127.0.0.1/”)
[/code]

but im not sure how

Thanks Adam

to post a comment
PHP

13 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 08.2004 — How about:
[code=php]if(! preg_match("^/http:\/\/127.0.0.1\//", $_SERVER['HTTP_REFERER'])
{
# invalid
}[/code]
Copy linkTweet thisAlerts:
@pyroOct 08.2004 — Perhaps a more efficient way would be to use [URL=http://www.php.net/manual/en/function.strpos.php]strpos[/URL].
Copy linkTweet thisAlerts:
@NogDogOct 08.2004 — [i]Originally posted by pyro [/i]

[B]Perhaps a more efficient way would be to use [URL=http://www.php.net/manual/en/function.strpos.php]strpos[/URL]. [/B][/QUOTE]

Probably - I learned Perl (at least some of it) before PHP, so I'm always thinking in terms of regexp's. ?
Copy linkTweet thisAlerts:
@pyroOct 08.2004 — Well, at least you use PCRE. When I see people using POSIX regex, I just shake my head and ask why... ?
Copy linkTweet thisAlerts:
@JonaOct 09.2004 — [font=trebuchet ms]To provide yet another option, and possibly closer to what was originally asked, the [url=http://php.net/substr]substr[/url]() function can be used to check the value of the first 17 characters of the string.[/font]

[code=php]
if(substr($_SERVER["HTTP_REFERER"], 0, 17) != "http://127.0.0.1") {
# ...
}
[/code]
Copy linkTweet thisAlerts:
@k0r54authorOct 09.2004 — Hi,

can any tell why this isn't working all i get is the echo sorry error

[code=php]
if(substr($_SERVER["HTTP_REFERER"], 0, 40) !== "https://www.paypal.com/uk/cgi-bin/webscr") {
echo "Sorry Error";
} else {
[/code]



when i am on the site, the url on paypal is actually that so i dunno :p???

Cheers Adam
Copy linkTweet thisAlerts:
@drythirstOct 09.2004 — Maybe you should post a new thread about that...
Copy linkTweet thisAlerts:
@k0r54authorOct 09.2004 — Hi,

sorry why? it is related to this???
Copy linkTweet thisAlerts:
@JonaOct 09.2004 — [font=trebuchet ms]A new topic shouldn't be posted as it's the same person with a relatively similar question.

K0r54, print out the referrer to see what it's saying the referrer is. If it's empty, therein lies your problem. Also, if you're checking for a full address, you should use the equivalency operator ([/font][font=courier new]==[/font][font=trebuchet ms]), not the [/font][font=courier new]substr()[/font][font=trebuchet ms] function, as it just adds to the processing time.[/font]
Copy linkTweet thisAlerts:
@drythirstOct 09.2004 — Oh, sorry, I didn't really understand the post...

Next time I will (hopefully) remember to think before I post...
Copy linkTweet thisAlerts:
@JonaOct 09.2004 — [i]Originally posted by drythirst [/i]

[B]Oh, sorry, I didn't really understand the post...

Next time I will (hopefully) remember to think before I post... [/B]
[/QUOTE]


[font=trebuchet ms]That's usually a good idea as it can keep you out of a good deal of trouble.[/font]
Copy linkTweet thisAlerts:
@drythirstOct 09.2004 — [i]Originally posted by drythirst [/i]

[B]Oh, sorry, I didn't really understand the post...

Next time I will (hopefully) remember to think before I post... [/B]
[/QUOTE]

Yes, you are right Jonathan ?
Copy linkTweet thisAlerts:
@k0r54authorOct 09.2004 — hi,

I have posted a new thread with a similar problem but the only reason y i posted in a new thread of because it can help some1 else. I tried to echo it and its blank. I noticed it is httpS and i think it has blocked it

please look here

http://www.webdeveloper.com/forum/showthread.php?s=&threadid=46175

Thanks

Adam
×

Success!

Help @k0r54 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...