Username: Save?
Password:
Home Forum Links Search Login Register*
    News: Keep The TechnoWorldInc.com Community Clean: Read Guidelines Here.
Recent Updates
[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[February 14, 2024, 02:00:39 PM]

[February 14, 2024, 02:00:39 PM]

[February 14, 2024, 02:00:39 PM]

[February 14, 2024, 02:00:39 PM]

[February 08, 2024, 10:26:18 AM]
Subscriptions
Get Latest Tech Updates For Free!
Resources
   Travelikers
   Funistan
   PrettyGalz
   Techlap
   FreeThemes
   Videsta
   Glamistan
   BachatMela
   GlamGalz
   Techzug
   Vidsage
   Funzug
   WorldHostInc
   Funfani
   FilmyMama
   Uploaded.Tech
   MegaPixelShop
   Netens
   Funotic
   FreeJobsInc
   FilesPark
Participate in the fastest growing Technical Encyclopedia! This website is 100% Free. Please register or login using the login box above if you have already registered. You will need to be logged in to reply, make new topics and to access all the areas. Registration is free! Click Here To Register.
+ Techno World Inc - The Best Technical Encyclopedia Online! » Forum » THE TECHNO CLUB [ TECHNOWORLDINC.COM ] » Programming Zone » HTML
  Site Personalization With PHP
Pages: [1]   Go Down
  Print  
Author Topic: Site Personalization With PHP  (Read 905 times)
Daniel Franklin
TWI Hero
**********


Karma: 3
Offline Offline

Posts: 16647


View Profile Email
Site Personalization With PHP
« Posted: September 26, 2007, 03:22:42 PM »




Put sales.php on your web server and run it in your browser. You get the exact same result as you did with the HTML page. Now, for the good part.

Say you wanted to personalize one of your sales pages. Let's call that sales.php. Now, if you had a newsletter or wanted to give this "personalized link" to someone, your visitor's name could be added on-the-fly to your sales page.

Your link should look something like this:

http://www.your.host/sales.php?firstname=Big&lastname=Bird

Let's try it out:


http://www.jumpx.com utorials/1/example.php?f=Myfirstname

Click that link and your name should be near the top of the page.)

In this example, yourdomain.com represents your domain name and sales.php your HTML file turned PHP script. This would be the link you could give Big Bird when you ask him to visit your sales page.

Now, edit sales.php and find where you want Big Bird's name to appear. The first and last names are given to the script separately so you could have anything from "Hi Big Bird!" to "Dear Mr. Bird..." For simplicity let's just stick with showing both the first and last names for now.

Insert this anywhere into your "script":

<?php echo "$firstname $lastname"; ?>

Now try that sample link I gave you earlier on that sales page of yours. You should see the phrase "Big Bird" anywhere on your page.

Remember that you can stick this in anywhere on the page. So for example if you wanted it to say "Dear Big Bird," you would just do this (with the comma at the end):

Dear <?php echo "$firstname $lastname"; ?>,

If you wanted to show only the first name, use <?php echo "$firstname"; ?> instead. The same applies to the last name.

If you want to go ahead and shorten the URL even further, you can even use the letters "F" and "L" instead of firstname and lastname.

For example, try this in your page:

<?php echo "$f $l"; ?>

And then use this URL (substituting with your correct URL, of course):

http://www.your.host/sales.php?f=Oscar&l=Grouch

The result is the same. I think we want our URLs to look a little better, though.

The format I used in that above example was:

http://www.your.host/sales.php?f=Big&l=Bird

Now, the problem with this is that this link looks really ugly. Another setback with this format is that anything to the right of the "?" won't be indexed by some of the smaller search engines.

Here's a way to change this:

http://www.your.host/sales.php?f=Firstname&l=Lastname

To this:

http://www.your.host/sales.php/f=Firstname/l=Lastname

It's really easy. Just change your script to this:

<?php

$myvars = explode("/",$REQUEST_URI); for ($i=0;$i<count($myvars);$i++) { $holder = explode("=",$myvars[$i]); ${$holder[0]} = $holder[1]; }

echo "$f $l";

?>

And in just a few lines of code, your personalized PHP script's URL just looked a whole lot better.

I won't bore you with the details of what that script does, but it basically chops up the URL you gave it and picks out the pieces it wants using array exploding and variable-variables.

This snippet can also be used on almost any PHP script as well. (I used this method when I coded Brian Garvin's Lightning Track ad tracker... if you ever see a URL anywhere with "go.php/etc" in it, that's my script.)

Hopefully we all learned something today. This mini-tutorial was brought to you by the letters "P-H-P."

Articles Source - Free Articles

Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Copyright © 2006-2023 TechnoWorldInc.com. All Rights Reserved. Privacy Policy | Disclaimer
Page created in 0.164 seconds with 24 queries.