Jump to content

link id


manalnor

Recommended Posts

Hello dear friends,

 

Let say we have

 

$space ="hello world";

 

then remove spaces between the words by using

 

$title = str_replace(' ', '-', trim($space));

 

so it would be here as "hello-world"

 

and let say we have stored title,article text...whever in an database table that call back all this using id then for an article with id=1 its link will be

 

site.com/index.php?id=1

 

it is clear that the

 

echo "$id"; //<--- 1

 

now some wordpress or/and blogs using rewrite .htaccess to make the link as

 

site.com/$title-$id 

 

(as our example site.com/hello-world-1)

 

then how they know its $id = 1 to get any variables from database that needs the id

 

i've tried but never works and only works if i made something like

 

site.com/$title_$id  //<-- site.com/hello-word_1

 

cause it needs difference separate in order to understand the id

 

so how to make it ? how to make it understand that the last separated is the id

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/230907-link-id/
Share on other sites

The sites you are reffering to mainly use the MVC (Model View Controller) design pattern. this reflects in the URL. Each Controller has a set of Actions which take in the user parameters and pass them to the model etc.. Therefore if you are passing a variable through the url:

 

// www.somewebsite.com/ControllerName/ActionName/Variable1Name/Variable1Value/Variable2Name/Variable2value
// which translates looks like:
// www.somewebsite.com/Loginpage/loguserin/myusername/name1/password/logmein

 

obviuously you would not pass sensitive data like this, but i hope it explains it for you

Link to comment
https://forums.phpfreaks.com/topic/230907-link-id/#findComment-1188639
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.