Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › php linking system/ $_GET
New Posts  All Forums:Forum Nav:

php linking system/ $_GET

post #1 of 9
Thread Starter 
Hi, basically, im building my own CMS from scratch and it was going fairly well with no hick ups, but now i have encountered one...
I need to know how to make php links for my admin menu, so that it doenst change my php file/link.
I really dont know how to do linking properly, but im doing it like this.
www.website.com/index.php?admin=add_news this give me a overlayedbox that i can fill and submit.
simply putting ?admin=add_news at my menu href.
And my php would be:

$admin = $_GET;
if ($admin == "theme") {
echo "the box that pops out";

}

This way would be nice and all, because it would work on EVERY php file of my website (The ones that users see ofc) example: index.php/view.php etc.
BUT, it doenst work in certain situations, for example, i have made users page, where you can look at other users stats etc.
www.website.com/userdetails.php?username=Zvejniex
And if there are NO match it displays an error message, obviously.. But the problem starts here, when im at that links and try to go to my, for example, ?admin=add_news (by pushing the upper menu) , so that i could add nesws from every part of my website, the site gives an error, because it now is www.website.com/userdetails.php?admin=add_news . This causes to loose my previous link (user page). How can i do this the right way?
Is it possible to have www.website.com/userdetails.php?username=Zvejniex?admin=add_news ???


Tell me if you didnt understand me..
Edited by Zvejniex - 3/23/13 at 4:09am
 
Old rig
(7 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core 4670k 4.6ghz @ 1.27v Gigabyte Z87-UD3H Nvidia MSI GTX 760 Sli - To be ordered Corsair Vengeance 8gb 1600mhz CL9 Single Channe... 
Hard DriveCoolingOSMonitor
1 TB WD 7200 RPM Hyper Evo 212 Push/Pull Win 8 Pro 64-bit Acer v223w 22 inches 
PowerCase
Corsair TX850 Cooler Master Gladiator 600 
CPUMotherboardGraphicsRAM
Intel E1400 945GCM-S2L Intel HD Junk Kingston 1gb 667mhz 
Hard DriveOSMonitor
Samsung 250gb Windows 7 Ultimate 64-bit HP w1907v 19 inches 
  hide details  
Reply
 
Old rig
(7 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core 4670k 4.6ghz @ 1.27v Gigabyte Z87-UD3H Nvidia MSI GTX 760 Sli - To be ordered Corsair Vengeance 8gb 1600mhz CL9 Single Channe... 
Hard DriveCoolingOSMonitor
1 TB WD 7200 RPM Hyper Evo 212 Push/Pull Win 8 Pro 64-bit Acer v223w 22 inches 
PowerCase
Corsair TX850 Cooler Master Gladiator 600 
CPUMotherboardGraphicsRAM
Intel E1400 945GCM-S2L Intel HD Junk Kingston 1gb 667mhz 
Hard DriveOSMonitor
Samsung 250gb Windows 7 Ultimate 64-bit HP w1907v 19 inches 
  hide details  
Reply
post #2 of 9
I'm not entirely sure what you're question is, but are you using isset to check that you have a query string?
Also, you should be checking the query string name as well as just the value (eg $_GET["username"]).

While we're on the subject of CMSs, make sure you're cleansing your input to avoid SQL injection attacks and/or malicious code being uploaded to your site. And in your web server (apache?) you'll need some URL rewriting to change your URLs from domain.com/index.php?function=value to something a little better search engine optimized (eg domain.com/function/value)
post #3 of 9
Thread Starter 
Yeah, i know those things.
And no, im not ussing isset.
You said: Also, you should be checking the query string name as well as just the value (eg $_GET["username"]).
I dont get what are you saying biggrin.gif

This is my code...
Code:
<div class="menu">
<ul>
<li><a href="<?php echo $site_url; ?>">Home</a></li>
<li><a href="users.php">User list</a></li>
<li><a href="?admin=theme">Change theme</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
</ul>
<br style="clear:left"/>
</div>
<?php

$admin2 = $_GET['admin'];
if ($admin2 == "theme")       {
echo "<div id='d'>stuff to be excetuted</div>";

}

?>
as u can see there is list item that links to ?admin=theme, the below script reads it and display a box aka here its just text, But the problem is that when i press the button it deleates the rest of the links...is it possible to add the ?admin=theme just to the end?
Something like /userdetails.php?user=Zvejniex?admin=theme
because when i press that link to the ?admin=theme it deleated the ?user=Zvejniex part, and that loses the whole point, because i need that.

Btw, how do you properly make them, ive showed my version, but it what the rest do? I mean how do YOU make domain.com/index.php?function=value
Edited by Zvejniex - 3/23/13 at 6:53am
 
Old rig
(7 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core 4670k 4.6ghz @ 1.27v Gigabyte Z87-UD3H Nvidia MSI GTX 760 Sli - To be ordered Corsair Vengeance 8gb 1600mhz CL9 Single Channe... 
Hard DriveCoolingOSMonitor
1 TB WD 7200 RPM Hyper Evo 212 Push/Pull Win 8 Pro 64-bit Acer v223w 22 inches 
PowerCase
Corsair TX850 Cooler Master Gladiator 600 
CPUMotherboardGraphicsRAM
Intel E1400 945GCM-S2L Intel HD Junk Kingston 1gb 667mhz 
Hard DriveOSMonitor
Samsung 250gb Windows 7 Ultimate 64-bit HP w1907v 19 inches 
  hide details  
Reply
 
Old rig
(7 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core 4670k 4.6ghz @ 1.27v Gigabyte Z87-UD3H Nvidia MSI GTX 760 Sli - To be ordered Corsair Vengeance 8gb 1600mhz CL9 Single Channe... 
Hard DriveCoolingOSMonitor
1 TB WD 7200 RPM Hyper Evo 212 Push/Pull Win 8 Pro 64-bit Acer v223w 22 inches 
PowerCase
Corsair TX850 Cooler Master Gladiator 600 
CPUMotherboardGraphicsRAM
Intel E1400 945GCM-S2L Intel HD Junk Kingston 1gb 667mhz 
Hard DriveOSMonitor
Samsung 250gb Windows 7 Ultimate 64-bit HP w1907v 19 inches 
  hide details  
Reply
post #4 of 9
If you want to have a popup with a submission form I would suggest using jQuery and a lightbox. Something like
Code:
<a href="#addNews" id="addNewsPop">Add news</a>
<div class="hidden han">
  <div class="addNews">
    <form>
      <input></input>
    </form>
  </div>
</div>
<script>
$(document).ready(function() {
  ('#addNews').click(function() {
    $('.han').lightbox();
});
});
</script>

Pseudo-code. But essentially what that would do with a real lightbox implementation would cause an inpage popup with the hidden form. I use colorbox for my jquery lightboxes. There are hundreds of others though so you can scout around.

If you need to do multiple URL assignments for get it would be:
www.website.com/index.php?firstKey=firstVal
www.website.com/index.php?firstKey=firstVal&secondKey=secondVal
www.website.com/index.php?firstKey=firstVal&secondKey=secondVal&thirdkey=thirdVal

The ? only happens once. Everything after uses &. You access them all the same way using $_GET.



The more advanced way to do things without having to put a hidden form on each page is to use a lightbox that requests the template and information on click. This can be done using a HTTP GET request or a more advanced AJAX request with POST/GET parameters. Still would need something like jQuery to avoid browser problems and speed up development time.
Dink
(20 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core I5 3570K Gigabyte UD3H Sapphire 7950 GSkill Ares 16gb 
Hard DriveOptical DriveCoolingOS
Samsung 840 500GB None Swiftech H220 Windows 7 Ultimate 
MonitorMonitorMonitorMonitor
Crossover 27" 27Q Acer 23" V233H Hanns-G 24" HH241 LG 55" LD520  
KeyboardPowerCaseMouse
Ducky Shine2 DK9008 with Reds Seasonic X750 Gold NZXT Switch 810 Mionix Naos 8200 
Mouse PadAudioAudioAudio
Mionix Ensis 320 LR: Focal 726 Sub: HSU VTF15-H Denon AVR1911 
  hide details  
Reply
Dink
(20 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core I5 3570K Gigabyte UD3H Sapphire 7950 GSkill Ares 16gb 
Hard DriveOptical DriveCoolingOS
Samsung 840 500GB None Swiftech H220 Windows 7 Ultimate 
MonitorMonitorMonitorMonitor
Crossover 27" 27Q Acer 23" V233H Hanns-G 24" HH241 LG 55" LD520  
KeyboardPowerCaseMouse
Ducky Shine2 DK9008 with Reds Seasonic X750 Gold NZXT Switch 810 Mionix Naos 8200 
Mouse PadAudioAudioAudio
Mionix Ensis 320 LR: Focal 726 Sub: HSU VTF15-H Denon AVR1911 
  hide details  
Reply
post #5 of 9
A better implementation would be to flag your user as an admin as part of the account information. Then the site can render admin-related information automatically without you having to muck with the query string manually. Although you haven't provided all of the implementation details, from what you've posted so far it looks like you don't have any concept of an admin user, and anyone could edit content simply by altering the query string. Do not do this. Only an authorised and authenticated user should be able to edit content.
    
CPUMotherboardGraphicsRAM
i7 920 D0 MSI X58 Pro-E GTX 560 Ti 448 3x2GB G.Skill DDR3-1333 9-9-9-24 
Hard DriveHard DriveOptical DriveOS
840 Pro Caviar Black LG BD-ROM Windows 8.1 Pro x64 
MonitorMonitorKeyboardPower
Dell U2713HM Dell U2311H Turbo-Trak (Google it :D) Corsair HX-520 
CaseMouseMouse PadAudio
CM690 Mionix Avior 7000 Everglide Titan AKG K 242 HD 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
i7 920 D0 MSI X58 Pro-E GTX 560 Ti 448 3x2GB G.Skill DDR3-1333 9-9-9-24 
Hard DriveHard DriveOptical DriveOS
840 Pro Caviar Black LG BD-ROM Windows 8.1 Pro x64 
MonitorMonitorKeyboardPower
Dell U2713HM Dell U2311H Turbo-Trak (Google it :D) Corsair HX-520 
CaseMouseMouse PadAudio
CM690 Mionix Avior 7000 Everglide Titan AKG K 242 HD 
  hide details  
Reply
post #6 of 9
Thread Starter 
No, i have an admin account.. The admin page atm is a simple menu that shows up on the top of the website.
I was asking if there are other ways how to make links like function=something, and if im making them the right way?
like this.
$admin2 = $_GET;
if ($admin2 == "theme") {
echo "
stuff to be excetuted
";

}

?>
 
Old rig
(7 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core 4670k 4.6ghz @ 1.27v Gigabyte Z87-UD3H Nvidia MSI GTX 760 Sli - To be ordered Corsair Vengeance 8gb 1600mhz CL9 Single Channe... 
Hard DriveCoolingOSMonitor
1 TB WD 7200 RPM Hyper Evo 212 Push/Pull Win 8 Pro 64-bit Acer v223w 22 inches 
PowerCase
Corsair TX850 Cooler Master Gladiator 600 
CPUMotherboardGraphicsRAM
Intel E1400 945GCM-S2L Intel HD Junk Kingston 1gb 667mhz 
Hard DriveOSMonitor
Samsung 250gb Windows 7 Ultimate 64-bit HP w1907v 19 inches 
  hide details  
Reply
 
Old rig
(7 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core 4670k 4.6ghz @ 1.27v Gigabyte Z87-UD3H Nvidia MSI GTX 760 Sli - To be ordered Corsair Vengeance 8gb 1600mhz CL9 Single Channe... 
Hard DriveCoolingOSMonitor
1 TB WD 7200 RPM Hyper Evo 212 Push/Pull Win 8 Pro 64-bit Acer v223w 22 inches 
PowerCase
Corsair TX850 Cooler Master Gladiator 600 
CPUMotherboardGraphicsRAM
Intel E1400 945GCM-S2L Intel HD Junk Kingston 1gb 667mhz 
Hard DriveOSMonitor
Samsung 250gb Windows 7 Ultimate 64-bit HP w1907v 19 inches 
  hide details  
Reply
post #7 of 9
Quote:
Originally Posted by Zvejniex View Post

No, i have an admin account.. The admin page atm is a simple menu that shows up on the top of the website.

Are you actually ensuring that only an admin user can show it though? That was my concern. If you are then that's good.

Quote:
Originally Posted by Zvejniex View Post

I was asking if there are other ways how to make links like function=something, and if im making them the right way?
like this.
$admin2 = $_GET;
if ($admin2 == "theme") {
echo "
stuff to be excetuted
";

}

?>

You should also check if $_GET('admin')** is set, using isset of course. Otherwise you'll get an exception thrown when you try to access it on the first line if it doesn't exist.

**With square brackets - the forum strips them out for security reasons so I used parentheses
Edited by randomizer - 3/28/13 at 5:15pm
    
CPUMotherboardGraphicsRAM
i7 920 D0 MSI X58 Pro-E GTX 560 Ti 448 3x2GB G.Skill DDR3-1333 9-9-9-24 
Hard DriveHard DriveOptical DriveOS
840 Pro Caviar Black LG BD-ROM Windows 8.1 Pro x64 
MonitorMonitorKeyboardPower
Dell U2713HM Dell U2311H Turbo-Trak (Google it :D) Corsair HX-520 
CaseMouseMouse PadAudio
CM690 Mionix Avior 7000 Everglide Titan AKG K 242 HD 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
i7 920 D0 MSI X58 Pro-E GTX 560 Ti 448 3x2GB G.Skill DDR3-1333 9-9-9-24 
Hard DriveHard DriveOptical DriveOS
840 Pro Caviar Black LG BD-ROM Windows 8.1 Pro x64 
MonitorMonitorKeyboardPower
Dell U2713HM Dell U2311H Turbo-Trak (Google it :D) Corsair HX-520 
CaseMouseMouse PadAudio
CM690 Mionix Avior 7000 Everglide Titan AKG K 242 HD 
  hide details  
Reply
post #8 of 9
Thread Starter 
Is there a way to add a function=something at the end of the url? I know it can be done with the &, but sometimes i need it to be the ? because no other function is named, or how can you call it.
Im using the jquery to open a popup window (the green one). It pops up when i press change theme on the menu. So the link here is index.php#cTheme

Its all fine and dandy for showing what theme i have set etc, but then it wanstn enough, i wanted to add the ability to change the theme by pressing on the name of the theme. So the link when you push on a certain theme would be ?settheme=(theme name you pressed). In this situation when im at index.php it works just fine (in theory, because i havent written the theme changer script itself.) because the link now is index.php?settheme=(theme name you pressed), but for example, when im at the users page it isnt working because its interfiering with already set variables.
See..
the link here is /userdetails.php?username=Zvejniex

When i press the button now to change theme it deletes the ?username=Zvejniex, because there only can be one ? and the website returns "no user found", but the theme link is obviously working, but i need them both, get the dillema?
And then i thought, i need to set the links ? to the & and it all should work, it did in the rest links where some variable was defined, but didnt in the index.php because it would return me index.php&settheme=(theme name you pressed) and that just doesnt work. biggrin.gif
Now im thinking of another way around this, by making two links in the menu (dynamic) if else statement to sort out which to display, the ? or the &, but that would be messy as hell because i would need to check if some variable is set. There has to be another way. As i stated before is this the right way to even make linking system in the website?


The base line is i want a admin menu that is integrated with every theme, as you can see, sitting on the top of the site and this is my interpretation how i do this, yeah, in this segment im very inexperienced. Mabey what im asking is not possible this way, please give me another. Tutorial would be great.
Edited by Zvejniex - 3/31/13 at 10:44am
 
Old rig
(7 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core 4670k 4.6ghz @ 1.27v Gigabyte Z87-UD3H Nvidia MSI GTX 760 Sli - To be ordered Corsair Vengeance 8gb 1600mhz CL9 Single Channe... 
Hard DriveCoolingOSMonitor
1 TB WD 7200 RPM Hyper Evo 212 Push/Pull Win 8 Pro 64-bit Acer v223w 22 inches 
PowerCase
Corsair TX850 Cooler Master Gladiator 600 
CPUMotherboardGraphicsRAM
Intel E1400 945GCM-S2L Intel HD Junk Kingston 1gb 667mhz 
Hard DriveOSMonitor
Samsung 250gb Windows 7 Ultimate 64-bit HP w1907v 19 inches 
  hide details  
Reply
 
Old rig
(7 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core 4670k 4.6ghz @ 1.27v Gigabyte Z87-UD3H Nvidia MSI GTX 760 Sli - To be ordered Corsair Vengeance 8gb 1600mhz CL9 Single Channe... 
Hard DriveCoolingOSMonitor
1 TB WD 7200 RPM Hyper Evo 212 Push/Pull Win 8 Pro 64-bit Acer v223w 22 inches 
PowerCase
Corsair TX850 Cooler Master Gladiator 600 
CPUMotherboardGraphicsRAM
Intel E1400 945GCM-S2L Intel HD Junk Kingston 1gb 667mhz 
Hard DriveOSMonitor
Samsung 250gb Windows 7 Ultimate 64-bit HP w1907v 19 inches 
  hide details  
Reply
post #9 of 9
Quote:
Originally Posted by Zvejniex View Post

Is there a way to add a function=something at the end of the url? I know it can be done with the &, but sometimes i need it to be the ? because no other function is named, or how can you call it.
[snip]

The ? is just telling the browser/server where the variables start. The & is for saying there are multiple. Otherwise there is no difference.

For your problem what you could do is put all the information into a javascript array and then create the URL on the page by using jquery.Param . The other option is to handle this server-side and do the same thing with http_build_query ( http://www.php.net/manual/en/function.http-build-query.php ). Ideally you want to do as much server-side as possible.
Dink
(20 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core I5 3570K Gigabyte UD3H Sapphire 7950 GSkill Ares 16gb 
Hard DriveOptical DriveCoolingOS
Samsung 840 500GB None Swiftech H220 Windows 7 Ultimate 
MonitorMonitorMonitorMonitor
Crossover 27" 27Q Acer 23" V233H Hanns-G 24" HH241 LG 55" LD520  
KeyboardPowerCaseMouse
Ducky Shine2 DK9008 with Reds Seasonic X750 Gold NZXT Switch 810 Mionix Naos 8200 
Mouse PadAudioAudioAudio
Mionix Ensis 320 LR: Focal 726 Sub: HSU VTF15-H Denon AVR1911 
  hide details  
Reply
Dink
(20 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core I5 3570K Gigabyte UD3H Sapphire 7950 GSkill Ares 16gb 
Hard DriveOptical DriveCoolingOS
Samsung 840 500GB None Swiftech H220 Windows 7 Ultimate 
MonitorMonitorMonitorMonitor
Crossover 27" 27Q Acer 23" V233H Hanns-G 24" HH241 LG 55" LD520  
KeyboardPowerCaseMouse
Ducky Shine2 DK9008 with Reds Seasonic X750 Gold NZXT Switch 810 Mionix Naos 8200 
Mouse PadAudioAudioAudio
Mionix Ensis 320 LR: Focal 726 Sub: HSU VTF15-H Denon AVR1911 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › php linking system/ $_GET