eZe616 Posted May 27, 2007 Share Posted May 27, 2007 Is it possible to pass a variable true a link?? like this http://www.sitehere.com/index.php?page=delpic&id=16&path=upload/HID16_img1 Now i'm using the the include method, to load the content already. this is the code i have <a href="index.php?page=delpic&id=".$id."&path=".$n1[0]."> Quote Link to comment https://forums.phpfreaks.com/topic/53213-solved-passing-variable-into-the-url-via-a-link/ Share on other sites More sharing options...
chronister Posted May 27, 2007 Share Posted May 27, 2007 Yes, that is correct. You would then use $_GET['page']; to retrieve your page var and $_GET['id']; to retrieve your id, and $_GET['path']; to get your path. So yes, these items should work. Quote Link to comment https://forums.phpfreaks.com/topic/53213-solved-passing-variable-into-the-url-via-a-link/#findComment-262885 Share on other sites More sharing options...
Trium918 Posted May 27, 2007 Share Posted May 27, 2007 What would be the purpose of doing this? I never used $_GET. Just asking to learn, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/53213-solved-passing-variable-into-the-url-via-a-link/#findComment-262887 Share on other sites More sharing options...
eZe616 Posted May 27, 2007 Author Share Posted May 27, 2007 for some reason it's not working though... I have this script <?php $page = $_GET['page']; $page = ($page != '') ? $page : 'hfs' ; $page .= '.php'; $page = preg_replace('%(?:\.\./)+%', '', $page); if (!is_dir($page) && file_exists($page)) { if (!(@include($page))) { include '404.txt'; } } else { echo 'File does not exist'; } ?> in my index.php to display a page. now when I try passing the url I just gave, it tell me 'file does not exist' . I don't see what the problem is, if it is possible to pass them like that What would be the purpose of doing this? I never used $_GET. Just asking to learn, thanks. Well I use them to pass variable to another page, where I don't have forms.like going to a person profile link. you get the id, and and pass that...and in the other page just use the ID to retrieve all the other info. It's the only way I know how to pass variables... Quote Link to comment https://forums.phpfreaks.com/topic/53213-solved-passing-variable-into-the-url-via-a-link/#findComment-262891 Share on other sites More sharing options...
chronister Posted May 28, 2007 Share Posted May 28, 2007 The purpose of $_GET is to grab the variables from the URL. I believe that PHP does not auto register variables by default configuration. I have simply always used it as that is the way I learned. $_POST retrieves variables in the http header of the page, and $_GET retrieves variables passed in the URL Quote Link to comment https://forums.phpfreaks.com/topic/53213-solved-passing-variable-into-the-url-via-a-link/#findComment-262981 Share on other sites More sharing options...
dmIllithid Posted May 28, 2007 Share Posted May 28, 2007 Passing variables via the link is possible. I know because I have a site that does that from page to page through-out the site. Not to mention that I fought with a small error with it for 5 hours yesterday. Anyways, make sure that the argument $page actually contains some data by running some kind of debugging script on the page that is to receive the data. Secondly, consider that you might be passing data that contains a delimeter. If so, the you will need to do a str_replace() before you pass the variable and again to convert it back once it is received by the next page. Quote Link to comment https://forums.phpfreaks.com/topic/53213-solved-passing-variable-into-the-url-via-a-link/#findComment-263032 Share on other sites More sharing options...
eZe616 Posted May 28, 2007 Author Share Posted May 28, 2007 Secondly, consider that you might be passing data that contains a delimeter. If so, the you will need to do a str_replace() before you pass the variable and again to convert it back once it is received by the next page. A delimeter?? Care to elaborate?..No idea what that is... Quote Link to comment https://forums.phpfreaks.com/topic/53213-solved-passing-variable-into-the-url-via-a-link/#findComment-263037 Share on other sites More sharing options...
chronister Posted May 28, 2007 Share Posted May 28, 2007 @dmIllithid -- Did you finally get that solved?? A delimeter is an & symbol in the url.. When you pass a var such as page.php?this=that&something=somethingelse the & is the delimiter. It separates your variables in your URL. Was trying to help dmIllithid yesterday with it. Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/53213-solved-passing-variable-into-the-url-via-a-link/#findComment-263049 Share on other sites More sharing options...
eZe616 Posted May 28, 2007 Author Share Posted May 28, 2007 ow ok ok...I get it now... Yeah I fixed it. makes everything easier now.. Quote Link to comment https://forums.phpfreaks.com/topic/53213-solved-passing-variable-into-the-url-via-a-link/#findComment-263058 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.