IPB

Welcome Guest ( Log In | Register )



Tags
This content has not been tagged yet
2 Pages V   1 2 >  
Reply to this topicStart new topic

Getting And Recording A Portion Of The Address Bar

, Similar to AIM subprofiles' features

snlildude87
no avatar
Moderator
***************
Group: Members
Posts: 2,325
Joined: 8-March 05
From: Mawson, Antarctica
Member No.: 4,254



Post #1 post Mar 8 2005, 10:32 PM
Does anyone know how to get a portion of the URL, record it somewhere, and display it later? For example, for something like index.php?name=blah, "blah" would be taken out, recorded, and displayed wherever you want it to.

That was a terrible explanation, but imagine those AIM subprofiles where each time a user visits, it remembers who you are and how many times you've visited.

Thank you in advance!
Go to the top of the page
+Quote Post
millertime
no avatar
It's Miller Time
********
Group: Members
Posts: 168
Joined: 8-February 05
Member No.: 3,672



Post #2 post Mar 8 2005, 10:35 PM
i used to know how to do that. i know it would end up being $blah and you take the value from that
Go to the top of the page
+Quote Post
beeseven
no avatar
Privileged Member
*********
Group: Members
Posts: 629
Joined: 26-February 05
Member No.: 3,995



Post #3 post Mar 8 2005, 11:31 PM
If the URL was "myfile.php" and they typed "myfile.php?hello=yes" then in the PHP code you do this:
CODE
<?php
$hello = $_GET['hello'];
echo "hello = " . $hello;
?>
And the output will be "hello = yes"
Go to the top of the page
+Quote Post
snlildude87
no avatar
Moderator
***************
Group: Members
Posts: 2,325
Joined: 8-March 05
From: Mawson, Antarctica
Member No.: 4,254



Post #4 post Mar 9 2005, 01:02 AM
OOO!! I'd have to try that sometime.

Now, how would you store $hello so you can use it some other time?
Go to the top of the page
+Quote Post
beeseven
no avatar
Privileged Member
*********
Group: Members
Posts: 629
Joined: 26-February 05
Member No.: 3,995



Post #5 post Mar 9 2005, 02:31 AM
If you mean a file, you can do this:
CODE
<?php
$hello = $_GET['hello'];
$file = "info.txt";
$handle = fopen($file, 'a'); //Says to open file (or create file) for writing and starts the pointer at the end
if(!fwrite($handle,$hello)) //If it can't write
{
       echo "Could not save information";
}
else
{
       echo "Information saved!";
}
fclose($handle); //Closes file connection
?>
Go to the top of the page
+Quote Post
millertime
no avatar
It's Miller Time
********
Group: Members
Posts: 168
Joined: 8-February 05
Member No.: 3,672



Post #6 post Mar 9 2005, 03:06 AM
wow, i'm going to have to try that sometime too. looks pretty simple
Go to the top of the page
+Quote Post
snlildude87
no avatar
Moderator
***************
Group: Members
Posts: 2,325
Joined: 8-March 05
From: Mawson, Antarctica
Member No.: 4,254



Post #7 post Mar 15 2005, 01:59 AM
QUOTE(beeseven @ Mar 8 2005, 11:31 PM)
If you mean a file, you can do this:
CODE
<?php
$hello = $_GET['hello'];
$file = "info.txt";
$handle = fopen($file, 'a'); //Says to open file (or create file) for writing and starts the pointer at the end
if(!fwrite($handle,$hello)) //If it can't write
{
       echo "Could not save information";
}
else
{
       echo "Information saved!";
}
fclose($handle); //Closes file connection
?>

[right][snapback]57900[/snapback][/right]

It turns out this is not simple as it seems - not for me, at least.

This is what I did:
1. Created a blank info.txt file
2. Created a blah.php file (I chose a random name)
3. Copied your code above to blah.php
4. Saved blah.php
5. Uploaded info.txt to my public_html/www folder
6. Uploaded blah.php to my public_html/www folder
7. Changed info.txt's and blah.php's permissions to 777 - just in case
8. Went to sang.trap17.com/blah.php&hello=yes
9. The browser redirected me to my custom 404 error page

Is there a step I'm missing in this seemingly easy process because my PHP knowledge is severly limited?

Please post a reply. Thank you!
Go to the top of the page
+Quote Post
beeseven
no avatar
Privileged Member
*********
Group: Members
Posts: 629
Joined: 26-February 05
Member No.: 3,995



Post #8 post Mar 16 2005, 11:03 PM
Sorry, didn't see this. When you're putting a variable in the address bar, the first variable has to be after a question mark, not an ampersand. Each subsequent variable is after an ampersand. Like this:

site.trap17.com/blah.php?hello=yes&goodbye=no&sixtimesnine=42
Go to the top of the page
+Quote Post
snlildude87
no avatar
Moderator
***************
Group: Members
Posts: 2,325
Joined: 8-March 05
From: Mawson, Antarctica
Member No.: 4,254



Post #9 post Mar 17 2005, 01:30 AM
Bee! I got the page to work...all by myself! biggrin.gif No offense to you of course.

I went to the library and checked out a book called Sams Teach Yourself PHP4 in 24 Hours. There is a section in there on how to read and write files, so I used their examples as a guide for my own code. Of course, I used your code as a template. Here is the final code that works:

CODE

<?php
$hello = $_GET["name"];
$file = "info.txt";
$handle = fopen($file, "a"); //Says to open file (or create file) for writing and starts the pointer at the end
fwrite($handle, $hello); //takes whatever is in the address bar and append to info.txt
fwrite($handle, ";\n"); //adds a newline
fclose($handle); //Closes file connection
?>


I created a info.txt and placed it in the same directory as my blah.php file.

Aren't you proud of me? I have barely no knowledge of PHP whatsoever! Man, I'm excited!
Go to the top of the page
+Quote Post
beeseven
no avatar
Privileged Member
*********
Group: Members
Posts: 629
Joined: 26-February 05
Member No.: 3,995



Post #10 post Mar 17 2005, 02:01 AM
Some of the first things I did were with fwrite, it's a pretty neat command. Maybe soon you'll be coding a forum with a flat file database like me =O I gave up on that though when I came to Trap17, becausee mySQL is a lot easier.
Go to the top of the page
+Quote Post

2 Pages V   1 2 >
Reply to this topicStart new topic

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   5 zak92 844 18th October 2007 - 12:02 AM
Last post by: Tramposch
No New Posts   1 Editor 555 23rd December 2004 - 05:37 PM
Last post by: wassie
No New Posts   6 my_hero51 1,487 29th October 2008 - 03:41 AM
Last post by: iGuest-steve
No new   54 fan198281 2,626 31st October 2008 - 07:38 AM
Last post by: iGuest-robert james peterson
No New Posts   11 krap 1,198 21st November 2005 - 03:14 AM
Last post by: Tyssen
No New Posts   5 yoofus 636 26th March 2005 - 09:39 PM
Last post by: maddog39
No New Posts   2 badinfluence 608 2nd April 2005 - 04:28 AM
Last post by: badinfluence
No New Posts   1 -Smiley- 526 20th November 2004 - 08:47 PM
Last post by: -abcde-
No New Posts   4 technobot 665 22nd August 2007 - 05:27 PM
Last post by: technobot
No new   14 -chakhei- 1,449 13th November 2008 - 12:14 PM
Last post by: iG-Sonu Kumar
No New Posts   2 techclave 416 16th June 2007 - 12:05 AM
Last post by: jlhaslip
No New Posts   0 -welbis- 318 23rd January 2005 - 03:55 PM
Last post by: -welbis-
No new   48 -Gohst- 1,734 5th March 2005 - 02:21 PM
Last post by: -Little Brother-
No New Posts   11 husker 758 28th July 2006 - 02:17 PM
Last post by: willywonker
No New Posts   9 EinReaper 175 25th October 2008 - 08:08 AM
Last post by: velma