Jump to content


Photo

.html URL's calling PHP, help plz!


  • Please log in to reply
5 replies to this topic

#1 gvanto

gvanto
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 26 June 2006 - 10:22 AM

I would very much like to find out the implementation of:

www.myurl.com/myfile.html where this URL actually calls the location (and shows content) www.myurl.com/content.php?id=4

I have seen this done somewhere just cant remember where :-)

Any help much appreciated!

Gerry

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 26 June 2006 - 10:26 AM

can you be more specific? it seems what you are asking is how to have say,

index.php?id=x

and depending on x, it includes a different page on index.php is that what you are asking? if not, then be more specific.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 gvanto

gvanto
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 26 June 2006 - 01:03 PM

Umm, OK thought it was quite clear but here goes:

I have content in a database, and depending on the value of ‘id’ depends which content is shown. BUT, for each ‘page’ (ie. Page with different content, in reality still index.php), I want an HTML page as follows (ie. The html page is called / linked to / whatever):

url.com/myPage.html calls-> url.com/Index.php?id=4&someother=true
url.com/myRandomlyNamedOtherPage.html calls-> url.com/index.php?id=39&someother=blah

Hope this makes more sense,

Thanks,
Gerry


Umm, OK thought it was quite clear but here goes:

I have content in a database, and depending on the value of ‘id’ depends which content is shown. BUT, for each ‘page’ (ie. Page with different content, in reality still index.php), I want an HTML page as follows (ie. The html page is called / linked to / whatever):

url.com/myPage.html calls-> url.com/Index.php?id=4&someother=true
url.com/myRandomlyNamedOtherPage.html calls-> url.com/index.php?id=39&someother=blah

Hope this makes more sense,

Thanks,
Gerry


#4 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 26 June 2006 - 01:20 PM

Create 1 more column in table which you had stored those id's, name it url
Example of the table:
| id | url |
| 1 | url.com/12312vawafwa.html |
| 2 | url.com/2352g352vc352v352.html |
Etcs ...

In your index.php you should have:
<?php
$id = $_GET['id'];
if (isset($id)) {
    function go_to_page($id) {
        $query = "SELECT * FROM `page` WHERE id ='$id'";
        $result = mysql_query($query) or die("Query failed: " . mysql_error());
        $row = mysql_fetch_array($result);
        $pageid = $row['id'];
        $pageurl = $row['url'];
        $go = "<META HTTP-EQUIV='refresh' CONTENT='0;URL=". $pageurl ."'>";
        return $go;
    }
    echo go_to_page($id);
} else {
    echo "You didn't select any page.";
    }
?>

Tell me if there's any error, I have test it yet.
Hope this helps.

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#5 gvanto

gvanto
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 26 June 2006 - 02:13 PM

Dear Kear,

Thanks for your reply, but i just read up to here:
if (isset($id))

and immediately I sense that you have the INVERSE of the function that I want, fully explained.

In your code, you're expecting the user to enter: url.com/index.php?id=somenumber into the address bar, then call the .html file depending what this id is.

I'm looking for a way of: entering the .html file: url.com/myrandom.html which THEN calls url.com/index.php?contentid=something

Basically, a way of running a php file but which somehow has a .html extension (after which you can retrieve the current URL string, then FIND ID depending on the url location, ie. the inverse of what your code does)

Hope this makes more sense now. Any help much appreciated!
Gerry

#6 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 26 June 2006 - 02:16 PM

There's a way using .htaccess, but it's really trouble that a html file act as a php file.
Why not just use .php it's just 3 letters while .html 4 letters ?

RewriteRule ^home\.html index.php [L]
RewriteRule ^index\.html index.php [L]
RewriteRule ^(.*)\.html index.php?write=$1 [L]


Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users