|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Web Coding | |
Fetch current URL in PHP?
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
PC Gamer
|
Can I fetch the current URL in PHP? I know I can do it using javascript, but I was wondering if there was a PHP function to do it
![]()
__________________
[CS:S Gun Game (ADMIN)] [My CPU-Z] [FAQ - How to make a portable USB charger] [OCN Wallpapers] [OCN Wallpapers 2] [OCN Wallpapers 3]
|
|||||||||||||
|
|
|
|
#2 (permalink) | |||||||||||||
|
Programmer
|
$current_url = 'http://www.example.com' . $_SERVER['PHP_SELF'];
__________________
|
|||||||||||||
|
|
|
|
#3 (permalink) | |||||||||||||
|
PC Gamer
|
Won't that just set the var "current_url" to example.com? I need it to grab the url that the page is at. For example: when you're at example.com/link1.php, I want that to be the current url, and when you're at example.com/index.php that to be current url, etc.
__________________
[CS:S Gun Game (ADMIN)] [My CPU-Z] [FAQ - How to make a portable USB charger] [OCN Wallpapers] [OCN Wallpapers 2] [OCN Wallpapers 3]
|
|||||||||||||
|
|
|
|
#4 (permalink) | |||||||||||||
|
Programmer
|
Did you read the whole line? A period (dot) is the PHP concatenation character, it joins two things together.
__________________
|
|||||||||||||
|
|
|
|
#5 (permalink) | |||||||||||||
|
AMD Overclocker
|
This should do the trick:
<?php echo "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']; ?>
__________________
My s939 rig build log thread - 4600+ @ 2.8Ghz stable ![]() Aumotocnic "An unfortunate member of the overclock.net insomnia club" Quebec Overclockers - 8019 in 3dMark06s939 Manny 4600+ @ 2809Mhz @ 1.425V (9 hours Orthos blend test stable - 24/7 Usage) - http://valid.x86-secret.com/show_oc.php?id=289741 @ 2945Mhz @ 1.45V (YAY! - Not stable, doh!) - http://valid.x86-secret.com/show_oc.php?id=276669
Last edited by Starholdest : 01-13-08 at 06:50 PM. |
|||||||||||||
|
|
|
|
#7 (permalink) | |||||||||||||
|
Programmer
|
If you're coding for your own website, my solution would be more ideal (and faster) as PHP doesn't have to concatenate the extra variable put in there. Also, a word of advice, use single quotes instead of double as it is faster because PHP doesn't have to scan for variables in that string. If you need to put a variable into a string, concatenate. Another thing (I'm picky
__________________ ), you should space out your coding properly, it makes it much easier for you and (if applicable) your colleagues.As you can see, I'm all about efficiency, speed and readability, instead of the "easy way out". ![]()
|
|||||||||||||
|
|
|
|
#8 (permalink) | |||||||||||||
|
PC Gamer
|
Dismounted, I tried your script but it didn't work. But starholdest's did. Thanks to both of you for your help
__________________
[CS:S Gun Game (ADMIN)] [My CPU-Z] [FAQ - How to make a portable USB charger] [OCN Wallpapers] [OCN Wallpapers 2] [OCN Wallpapers 3]
|
|||||||||||||
|
|
|
|
#9 (permalink) | |||||||||||||
|
Programmer
|
What do you mean it didn't work? You mean it didn't output anything? That's because it wasn't printed, use echo() instead of assigning it to a variable.
__________________
|
|||||||||||||
|
|
|
|
#10 (permalink) | |||||||||||||
|
PC Gamer
|
I just added echo('$current_url') at the end of the line. Did I do that wrong?
__________________
[CS:S Gun Game (ADMIN)] [My CPU-Z] [FAQ - How to make a portable USB charger] [OCN Wallpapers] [OCN Wallpapers 2] [OCN Wallpapers 3]
|
|||||||||||||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|