The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Adding to link urls
Discuss Adding to link urls in the PHP Development forum on Dev Shed. Adding to link urls PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

July 18th, 2012, 07:42 PM
|
|
|
|
Adding to link urls
I wish to debug my JS on IE browsers. To do so, thinking of using fire-bug light. So, I want to add the following on my site. I have one entry point, so it will be easy.
PHP Code:
<script type="text/javascript" src="https://getfirebug.com/firebug-lite-debug.js"></script>
Now, don't want it always to be included, only when I enter debug mode. To do so, I will enter the url http://mysite.com?data=whatever&debug=123.
My PHP script will then check if $_GET['debug']==123, and if so, add the <script>.
Now, when I click an internal link on my site, I want to include debug=123 in the link. Looks like I have several options: - On every internal link, include PHP to add it. Kind of a pain, but not impossible.
- Send the entire output to an ob_buffer, and parse it to add it. Seems like a pain as well, but I typically do send my output to a buffer first so maybe okay.
- Use some sort of .htaccess script. Would rather not because I always forget when I do so.
- Use a session to save it. Problem is hard to exist debug mode.
- Something better?
Any suggestions? Thanks
|

July 18th, 2012, 08:27 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
Quote: | Originally Posted by NotionCommotion Any suggestions? |
A cookie.
|

July 18th, 2012, 08:52 PM
|
|
|
|
Wouldn't a cookie be the same as a session?
|

July 18th, 2012, 09:53 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
Basically, but cookies are easier to manage. Like you can set them on client-side.
|

July 19th, 2012, 03:55 AM
|
 |
Square Peg in a Round Hole
|
|
Join Date: Oct 2007
Location: North Yorkshire, UK
|
|
Untested
PHP Code:
//
if($_GET['debug'] == 'mySecret') {
setcookie("debug","mySecret",(time()+(30*24*60*60))); //set for a month
$loadDebug = true;
}
if($_GET['clearDebug'] == 'true') {
setcookie("debug","mySecret",(time()-(3600))); //delete by making cookie expire an hour ago
$loadDebug = false;
}
Then where you need this
PHP Code:
//
if($_COOKIE['debug'] == "mySecret" xor $loadDebug) {
echo "<script type='text/javascript' src='https://getfirebug.com/firebug-lite-debug.js'></script>"; //carefull when mixing https and http between page scheme and source schemes - they should match!
}
Last edited by Northie : July 19th, 2012 at 04:00 AM.
|

July 19th, 2012, 09:53 PM
|
 |
Lost in code
|
|
|
|
|
That's the approach I would take as well, but I recommend not using the xor there; if I had a script where debugging mode was enabled and I told it to enable debugging mode again and the result was it turned off debugging output I would be pretty confused.
|

July 19th, 2012, 10:15 PM
|
|
|
|
Thanks given to all the great people on this forum. I agree that this solution works best with the requirements I have given. I without telling you wanted to also use it to allow "administrators" to view a front-end site. I feel cookies are too persistent for this additional use, and will use your solution for debugging, but probably hardcoding the special code for the later purpose.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|