chocopi Posted May 13, 2007 Share Posted May 13, 2007 Ok, So i was wondering if it would be possible to get a section of a url what i mean is: url = http://www.somesite.com/stuff.php?=blahblahblah is there anyway i could just get the 'blahblahblah' bit Thanks, ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/ Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 <?php foreach($_GET as $key => $value) { $var = $key; } echo $var; ?> Only works if that's all there is after the URL. Won't work if you have other variables there too. Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252042 Share on other sites More sharing options...
chocopi Posted May 13, 2007 Author Share Posted May 13, 2007 well i just tested it on a blank page, but its not showing anything :'( Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252049 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 Access the page with file.php?gdgdfg not ?=gdgdfg Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252052 Share on other sites More sharing options...
chocopi Posted May 13, 2007 Author Share Posted May 13, 2007 wow thanks it worked but a question mark appears after the test for example http://www.blah.com/poo.php?hat gives hat? Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252057 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 That's what you want it to do isn't it? Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252058 Share on other sites More sharing options...
chocopi Posted May 13, 2007 Author Share Posted May 13, 2007 well i would like so it says 'hat' instead of 'hat?' Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252060 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 It shouldn't do, works fine for me? :S Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252062 Share on other sites More sharing options...
chocopi Posted May 13, 2007 Author Share Posted May 13, 2007 strange so when i click on 'cheers.php?mark' it gives me 'mark?' is there anything wrong with what i did Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252065 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 Access the page in the same way (file.php?var) but change the file to this: <?php echo "<pre>"; print_r($_GET); echo "</pre>"; ?> And paste the output here. Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252067 Share on other sites More sharing options...
chocopi Posted May 13, 2007 Author Share Posted May 13, 2007 that gives me Array ( [mark?] => ) Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252070 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 Weird... <?php function urlpart() { foreach($_GET as $key => $value) { $var = $key; } $length = strlen($var); $length = $length - 1; $var = substr($var, 0, $length); return $var; } echo urlpart(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252072 Share on other sites More sharing options...
chocopi Posted May 13, 2007 Author Share Posted May 13, 2007 wow thanks it WORKS WHOOP. CHEERS could it do with the fact that im using lycos to host it ? Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252079 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 Not sure what it is, it works on all my servers normally, but you have a function now for your server specifically Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252080 Share on other sites More sharing options...
chocopi Posted May 13, 2007 Author Share Posted May 13, 2007 is there any way i can set this urlpart(); to a variable ? Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252086 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 <?php $var = urlpart(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252097 Share on other sites More sharing options...
chocopi Posted May 13, 2007 Author Share Posted May 13, 2007 thats what i thought. could you please try and sort this: <? require_once ('page_header.php'); require_once ('url.php'); $code = urlpart(); $query = "SELECT active FROM users WHERE code = '$code'"; $update = "UPDATE users SET active ='1' WHERE code = '$code'"; mysql_query($update) or die (mysql_error()); print ("<br /> \n"); print ("<center> \n"); print ("$username, your account is now active, please login on the homepage. \n"); print ("<br /> \n"); print ("<br /> \n"); print ("<a href=\"index.php\">Home Page</a> \n"); print ("</center> \n"); ?> url.php is where the code you gave me earlier and page_header.php is the database connection. so what this is meant to do is just update the active field from 0 to 1 using the code you gave me to get the activation code thanks, ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252101 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 How does it know the $username value? Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252102 Share on other sites More sharing options...
chocopi Posted May 13, 2007 Author Share Posted May 13, 2007 yea thats the sort of problem i need help with, its meant to be taken from the same row as the activation code Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252112 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 <?php require_once ('page_header.php'); require_once ('url.php'); $inputcode = urlpart(); $query = "SELECT * FROM users WHERE code = '$inputcode'"; $result = mysql_query($query) or die(mysql_error()); $result = mysql_fetch_assoc($result); $realcode = $result['code']; $username = $result['username']; $update = "UPDATE users SET active ='1' WHERE username = '$username'"; mysql_query($update) or die (mysql_error()); print ("<br /> \n"); print ("<center> \n"); print ("$username, your account is now active, please login on the homepage. \n"); print ("<br /> \n"); print ("<br /> \n"); print ("<a href=\"index.php\">Home Page</a> \n"); print ("</center> \n"); ?> Try that Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252115 Share on other sites More sharing options...
chocopi Posted May 13, 2007 Author Share Posted May 13, 2007 wow thanks it worked. just out of intrest how did you learn all of this php ? Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252124 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 Practice. Just think up interesting project ideas and don't give up until you get it how you like it Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252128 Share on other sites More sharing options...
chocopi Posted May 13, 2007 Author Share Posted May 13, 2007 kool well thanks and all the best Quote Link to comment https://forums.phpfreaks.com/topic/51190-solved-getting-section-of-a-url/#findComment-252138 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.