Getting part of a link to display in page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tail
Forum Commoner
Posts: 66
Joined: Sat Oct 01, 2005 4:42 pm
Location: NJ

Getting part of a link to display in page

Post by tail »

I was wondering if there was a way to show text in the URL on the page. Here's an example. Let's say I have a link like this: 'http://perks.mypimpedlayout.com/profile ... persons_sn'. How would I display 'persons_sn' on the page. Help is much appreciated. Thanks in advance.
User avatar
blacksnday
Forum Contributor
Posts: 252
Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(

Post by blacksnday »

Code: Select all

echo $_GET['screenname'];
$_GET will always hold the value of whatever it equals in the url.
index.php?screenname=me&yourname=you

$_GET[screenname]
would output: me

$_GET[yourname]
would output: you

cheers :)
Last edited by blacksnday on Thu Jun 15, 2006 2:56 pm, edited 1 time in total.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Code: Select all

echo $_GET['screenname'];
Edit: I was too slow I guess :D
tail
Forum Commoner
Posts: 66
Joined: Sat Oct 01, 2005 4:42 pm
Location: NJ

Post by tail »

Thanks for quick response
tail
Forum Commoner
Posts: 66
Joined: Sat Oct 01, 2005 4:42 pm
Location: NJ

Post by tail »

Is there a way to store the screennames that accessed it in a text file and include it on a page?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

sure it is, look at

php4

fopen(), fread(), and fwrite()

or php5

file_get_contents() and file_put_contents()
tail
Forum Commoner
Posts: 66
Joined: Sat Oct 01, 2005 4:42 pm
Location: NJ

Post by tail »

That's looking too advanced for me. Can you perhaps help me out?
tail
Forum Commoner
Posts: 66
Joined: Sat Oct 01, 2005 4:42 pm
Location: NJ

Post by tail »

Here's the code I'm using:

Code: Select all

<?php
$filename = 'visitors.txt';
$screenname = $_GET ['screenname'];
if (is_writable($filename)) {
   if (!$handle = fopen($filename, 'a')) {
         echo "Cannot open file ($filename)";
         exit;
   }
   if (fwrite($handle, $screenname) === FALSE) {
       echo "Cannot write to file ($filename)";
       exit;
   }
   echo "Success, wrote ($screenname) to file ($filename)";
   fclose($handle);
} else {
   echo "The file $filename is not writable";
}
?>
But the problem is I need to have a line break after every screenname that get's put in the file. Any help?
tail
Forum Commoner
Posts: 66
Joined: Sat Oct 01, 2005 4:42 pm
Location: NJ

Post by tail »

Nevermind, I decided to go the easy way and use a MySQL database.
Post Reply