Add to Google

Getting And Recording A Portion Of The Address Bar - Similar to AIM subprofiles' features

Pages: 1, 2
free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Getting And Recording A Portion Of The Address Bar - Similar to AIM subprofiles' features

snlildude87
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!

Reply

millertime
i used to know how to do that. i know it would end up being $blah and you take the value from that

Reply

beeseven
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"

Reply

snlildude87
OOO!! I'd have to try that sometime.

Now, how would you store $hello so you can use it some other time?

Reply

beeseven
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
?>

Reply

millertime
wow, i'm going to have to try that sometime too. looks pretty simple

Reply

snlildude87
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
?>

*


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!

 

 

 


Reply

beeseven
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

Reply

snlildude87
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!

Reply

beeseven
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.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Pages: 1, 2






*SIMILAR VIDEOS*
Searching Video's for recording, portion, address, bar, similar, aim, subprofiles, features

*MORE FROM TRAP17.COM*
advertisement



Getting And Recording A Portion Of The Address Bar - Similar to AIM subprofiles' features



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE