Page 1 of 1

Getting part of a link to display in page

Posted: Thu Jun 15, 2006 2:51 pm
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.

Posted: Thu Jun 15, 2006 2:53 pm
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 :)

Posted: Thu Jun 15, 2006 2:54 pm
by Oren

Code: Select all

echo $_GET['screenname'];
Edit: I was too slow I guess :D

Posted: Thu Jun 15, 2006 2:56 pm
by tail
Thanks for quick response

Posted: Thu Jun 15, 2006 5:30 pm
by tail
Is there a way to store the screennames that accessed it in a text file and include it on a page?

Posted: Thu Jun 15, 2006 5:33 pm
by John Cartwright
sure it is, look at

php4

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

or php5

file_get_contents() and file_put_contents()

Posted: Thu Jun 15, 2006 5:46 pm
by tail
That's looking too advanced for me. Can you perhaps help me out?

Posted: Thu Jun 15, 2006 11:24 pm
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?

Posted: Fri Jun 16, 2006 4:38 pm
by tail
Nevermind, I decided to go the easy way and use a MySQL database.