preston Posted May 12, 2011 Share Posted May 12, 2011 Hi Larry and everyone.... Please help me understand this link as used in pg 90 of Effortless E-commerce: www.example.com/activate.php?x=email@example.com&y=CODE If it was only https://www.example.com/activate.php then I'd understand how to write code to be accessed by users when they browse https://www.example.com/activate.php and that is simply writing the code I want to be displayed in activate.php and storing activate.php in the root folder www.example.com. But how about www.example.com/actvate.php?x=email@example.com&y=CODE ?? How do I write code that can be accessed by the above link? How should I understand the "?x=email@example.com&y-CODE" part in the above link? I know that by using that kind of link a link that is unique to each user's email can be used to help activate their registration... but I still don't understand how to prepare a code that can be accessed by that type of link and will respond to different users.... I hope you understand what I am trying to ask here....please help.... To use another example...I have seen an iphone program access and store a photo by accessing the following site: www.floraphotographs.com/showrandomiphone.php?color=%@&session=%d again after the .php file there is the code that starts with ? and that is "?color=%@&session=%d". I would really like to understand this and learn how a php programmer can write code that responds to similar links as above... After reading the code in the iphone....I knew that it worked..but I didn't know how it worked...and because of that, I didn't know how to write code for that purpose as well... Thank you very much... Link to comment Share on other sites More sharing options...
Jonathon Posted May 12, 2011 Share Posted May 12, 2011 Hi Preston, This book has some complicated parts to it. So you may do well to buy PHP and MYSQL that Larry is updating now. I say this because if you are unfamiliar with how that link works then you should probably back up a bit. In my opinion. But to answer your question the ? Is used to represent a $_GET variable. The code would look like: if(isset($_GET['x'])) { // use variable in script } This then allows you to pull the info from the url into your scripts to use. I hope that helps, if you need any thing else please ask To add to this: What Larry means with this link is. He will send you an email when you register saying welcome etc etc to activate your account please click the link. The link will have the user's email which is what you can see x= but it will also have another variable 'y=', although you can pick whatever to call them. 'y' will often represent a unique id. Then when you click that link you go to actiavte.php, which you write to pull the x and y variables from the url and use them usually in a MYSQL query. Such as, "UPDATE users SET `activated`=NULL WHERE `email`='$x' AND `activated`=$y LIMIT 1" This is a very basic example of how to do it and it involves no security at all. "PHP and MYSQL" has a lot of really good stuff in it including this. You're likely use most of the material in the book alot and it will compound your understanding for more complicated areas. Anyway, again, hope that helps, shout if your still confused 1 Link to comment Share on other sites More sharing options...
preston Posted May 15, 2011 Author Share Posted May 15, 2011 Hi Jonathan, Thank you very much for your reply. Your explanation has given me the tip that I needed to further understand this tool... I played around with php based on your explanation about what '?' means.... So in short I did something like... I opened example.php?x=john on the browser where example.php has the following code: <?php if($_GET['x']=='john'){ echo "john"; } ?> and the browser would display "john".... Thank you very much for helping... Hi Preston, This book has some complicated parts to it. So you may do well to buy PHP and MYSQL that Larry is updating now. I say this because if you are unfamiliar with how that link works then you should probably back up a bit. In my opinion. But to answer your question the ? Is used to represent a $_GET variable. The code would look like: if(isset($_GET['x'])) { // use variable in script } This then allows you to pull the info from the url into your scripts to use. I hope that helps, if you need any thing else please ask To add to this: What Larry means with this link is. He will send you an email when you register saying welcome etc etc to activate your account please click the link. The link will have the user's email which is what you can see x= but it will also have another variable 'y=', although you can pick whatever to call them. 'y' will often represent a unique id. Then when you click that link you go to actiavte.php, which you write to pull the x and y variables from the url and use them usually in a MYSQL query. Such as, "UPDATE users SET `activated`=NULL WHERE `email`='$x' AND `activated`=$y LIMIT 1" This is a very basic example of how to do it and it involves no security at all. "PHP and MYSQL" has a lot of really good stuff in it including this. You're likely use most of the material in the book alot and it will compound your understanding for more complicated areas. Anyway, again, hope that helps, shout if your still confused Link to comment Share on other sites More sharing options...
Jonathon Posted May 15, 2011 Share Posted May 15, 2011 ni Preston, Yeah that's it You seem to have got understood what it's used for so i'm glad. Anything else then please pop back and some one will be able to help you out Link to comment Share on other sites More sharing options...
preston Posted May 16, 2011 Author Share Posted May 16, 2011 Thank you very much... I'll surely do that...hehehe.... Link to comment Share on other sites More sharing options...
Recommended Posts