Jump to content
xisto Community
Sign in to follow this  
snlildude87

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

Recommended Posts

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!

Share this post


Link to post
Share on other sites

If the URL was "myfile.php" and they typed "myfile.php?hello=yes" then in the PHP code you do this:

<?php$hello = $_GET['hello'];echo "hello = " . $hello;?>
And the output will be "hello = yes"

Share this post


Link to post
Share on other sites

If you mean a file, you can do this:

<?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 endif(!fwrite($handle,$hello)) //If it can't write{        echo "Could not save information";}else{        echo "Information saved!";}fclose($handle); //Closes file connection?>

Share this post


Link to post
Share on other sites

If you mean a file, you can do this:

<?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 endif(!fwrite($handle,$hello)) //If it can't write{        echo "Could not save information";}else{        echo "Information saved!";}fclose($handle); //Closes file connection?>

57900[/snapback]

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!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Bee! I got the page to work...all by myself! :angry: 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:

<?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 endfwrite($handle, $hello); //takes whatever is in the address bar and append to info.txtfwrite($handle, ";\n"); //adds a newlinefclose($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!

Share this post


Link to post
Share on other sites

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 Xisto, becausee mySQL is a lot easier.

Share this post


Link to post
Share on other sites

Try looking into the parse_url() function - it allows you to disassemble the URI, after which you could, for example, split() it. For example:

$purl = parse_url($url);$query = split('=',$purl['query']);

Try looking at the $_SERVER variable, namedly the REQUEST_URI index.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.