/    Sign up×
Community /Pin to ProfileBookmark

php request url

Hi

is there a way that I can get a pages url and assign it to a variable using php

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@The_Little_GuyAug 24.2006 — Example URL: http://example.com/index.php?page=mypage

$myvariable = $_GET['page'];

$myvariable now contains [B]mypage[/B]

Or do you want the entire URL?
Copy linkTweet thisAlerts:
@kprocauthorAug 24.2006 — yes I know how to do that but I want to get everything before the ?
Copy linkTweet thisAlerts:
@The_Little_GuyAug 24.2006 — do you want the current page? or a page from somewhere else?

If you want the current page:

echo $_SERVER['PHP_SELF'];

$val = $_SERVER['PHP_SELF'];
Copy linkTweet thisAlerts:
@kprocauthorAug 24.2006 — Thank you for the info, I gave it a try and did not work.

I have a calendar that offers each day of the week as link. I want to offer a calendar icon for the user to click which will popup the calendar and when the user clicks a date it files a forms text field with the date.

I'm thinking that I would have to make the begining url a variable as I only want to have to create one calendar and At the end of the webpage address I was set a variable like

?id=$id

then set the form field to request the id
Copy linkTweet thisAlerts:
@NogDogAug 24.2006 — Probably the most dependable way would be something like:
[code=php]
$thisPageUrl = 'http://www.mydomain.com'.array_shift(explode('?', $_SERVER['PHP_SELF']));
[/code]

If you want to include any query string as well, then get rid of the array_shift/explode stuff, but be aware that users could manually add anything to the query string, so you'll need to screen it for anything you don't want to be output (htmlspecialchars(), perhaps?).
Copy linkTweet thisAlerts:
@The_Little_GuyAug 24.2006 — Try this:

echo "http://mysite.com".$_SERVER['PHP_SELF'];

why don't you just have a URL that looks like this:

http://mysite.com/page.php?month=8&day=24&year=2006

It will be one URL, where you could get the month day and year, and then do what you want using $_GET
Copy linkTweet thisAlerts:
@kprocauthorAug 24.2006 — I have it working so that the url show the page were I I want the value to go. I ran into a snag.

A window with a calendar is opened via a pop-up from an icon next to the field were I want the information to go. The prblem is when I click the date I need it to send the value to the form field.

thank you for the help
Copy linkTweet thisAlerts:
@bokehAug 24.2006 — Probably the most dependable way would be something like:
[code=php]
$thisPageUrl = 'http://www.mydomain.com'.array_shift(explode('?', $_SERVER['PHP_SELF']));
[/code]

If you want to include any query string as well, then get rid of the array_shift/explode stuff, but be aware that users could manually add anything to the query string, so you'll need to screen it for anything you don't want to be output (htmlspecialchars(), perhaps?).[/QUOTE]
[I]$_SERVER['PHP_SELF'][/I] shouldn't contain the query string if one were to exist.
Copy linkTweet thisAlerts:
@kprocauthorAug 24.2006 — The calendar is a seperate page which is opened via javascript. the dates are hyperlinks which when licked I want the value written to the form

So if user clicks

24

the value 08-24-2006 which is stored in id would be entered into a form on the active page. just like if I click a smile it sends the code to my post equals ?
×

Success!

Help @kproc 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.13,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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