General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 18th, 2002, 11:33 AM
roberto_nl roberto_nl is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: The Netherlands
Posts: 19 roberto_nl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Get Url

i have something like this:

PHP Code:
if ($something == false)
    {

print 
" blablabla"


is there some function like get url or something?
i want to change the print " ... " to like GOTO abc.php
what function do i need to use?

and sorry, but as you can see i dont know mutch about php...

greetz
roberto

Reply With Quote
  #2  
Old October 18th, 2002, 12:15 PM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
PHP isn't a HTML replacement. You will still need to use HTML (or other technologies) for formatting your output.

To display a link:
echo "<a href='abc.php'>This is a link</a>";

I'm not sure if that's what you wanted to know?
__________________
Best Regards,
Håvard Lindset

Reply With Quote
  #3  
Old October 18th, 2002, 12:20 PM
roberto_nl roberto_nl is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: The Netherlands
Posts: 19 roberto_nl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: RE:

no, not realy...
what i ment is something like this (i know its not the correct php scripting ;-)

If $somevar = false

goto=somepage.php

so, when $somevar is false, redirect to somepage.php

Reply With Quote
  #4  
Old October 18th, 2002, 01:38 PM
Joe4JC Joe4JC is offline
The name's Joe. Yours?
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Lurking in the shadows...
Posts: 147 Joe4JC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
PHP Code:
 header ('Location: somepage.php'); 


Try that

Cheers,
Joe of 4Life
__________________
Check out 4Life today!

Reply With Quote
  #5  
Old October 20th, 2002, 05:50 AM
fakker fakker is offline
The calm b4 the storm
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Manchester, UK
Posts: 404 fakker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via Yahoo to fakker
what you could do is see if $somevar has been populated... if not, then it could redirect to another page.....

PHP Code:
If (isempty($somevar))
{
header ('Location: somepage.php');
}
else
{
header ('Location: someotherpage.php');



So if $somevar had nothing in it, it would redirect to somepage.php... but if it was set to something... eg if the page was called with "somecript.php?somevar=x" then it would redirect to someotherpage.php

Or like your first example, you could do:

PHP Code:
If ($somevar == "false")
{
header ('Location: somepage.php');



So the page would redirect ONLY if $somevar was set to "false". eg: somescript.php?somevar=false

so if it was somescript.php?somevar=falseeee it wouldn't work...

Did you want to get the URL as well? Cos there are some PHP functions to do that............ what is it you need to get?
__________________
Matt 'Fakker' Facer

mattfacer.com

Reply With Quote
  #6  
Old October 21st, 2002, 03:30 AM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Hey fakker,
On your first code block there, I think you meant to do this ->

PHP Code:
if ( empty( $variable ) ) // Returns true if empty, (constant) NULL, (bool) false, or has a value of 0 


Also, your second code block is dangerous ->

PHP Code:
If ($somevar == "false")
{
header ('Location: somepage.php');
}

/*
  Never use comparison '==' or '!=' on (bool) true or false.
  This can be accomplished by simply using the code below.
*/

if ( $somevar )   // Will return true if $somevar is set or (bool) true
if ( !$somevar )  // Will return false if $somevar is (bool) false 

Reply With Quote
  #7  
Old October 21st, 2002, 03:44 AM
AmericanD AmericanD is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 81 AmericanD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
good job jpenn

Reply With Quote
  #8  
Old October 21st, 2002, 04:36 AM
fakker fakker is offline
The calm b4 the storm
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Manchester, UK
Posts: 404 fakker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via Yahoo to fakker
lol.... I think isempty might be an ASP function anyway?!!!

Cheers for the pointers!

Matt.

Reply With Quote
  #9  
Old October 21st, 2002, 01:20 PM
crazytrain81 crazytrain81 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 232 crazytrain81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
isempty is a vbscript function. asp is not a programming language, just a set of objects.

empty(); is a php function. if (!empty($myVar)) { do something }

You CAN use header() to send a raw header and redirect, but this will only work if you have not sent any output whatsoever to the browser, not even a DTD or <html> tag. The best way to accomplish this is just to print a meta refresh line
PHP Code:
echo '<meta http-equiv="refresh" content="3;somepage.php"/>'


That will redirect them to somepage.php after 3 seconds. That's how the login redirect is accomplished on this site as well as many others, and it can be used for a good bit of stuffs

hope this helps

Reply With Quote
  #10  
Old October 21st, 2002, 01:23 PM
crazytrain81 crazytrain81 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 232 crazytrain81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
jpenn

"Also, your second code block is dangerous ->


PHP:--------------------------------------------------------------------------------
If ($somevar == "false")
{
header ('Location: somepage.php');
}

/*
Never use comparison '==' or '!=' on (bool) true or false.
This can be accomplished by simply using the code below.
*/

if ( $somevar ) // Will return true if $somevar is set or (bool) true
if ( !$somevar ) // Will return false if $somevar is (bool) false

--------------------------------------------------------------------------------
"

Why is this dangerous? You can evaluate boolean values with == != if you want, just don't put true/false inside quotes. putting them in quotes treats them as a string. which will still yeild the same results so long as you don't put bad data in your variable at some point. It is best practice to evaluate them as you said, but using == or != is not problematic.

Reply With Quote
  #11  
Old October 21st, 2002, 02:53 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Quote:
Why is this dangerous? You can evaluate boolean values with == != if you want, just don't put true/false inside quotes. putting them in quotes treats them as a string. which will still yeild the same results so long as you don't put bad data in your variable at some point. It is best practice to evaluate them as you said, but using == or != is not problematic.

Well, no. What if he is checking against an integer of '0', but first first wants to check if the string is true, or set, it won't work as '0' will return false. Also, for backwards compatibility, comparison against (bool) true or false by means of comparison operators will not work at all in pre 4 versions....

Reply With Quote
  #12  
Old October 21st, 2002, 03:04 PM
crazytrain81 crazytrain81 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 232 crazytrain81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Hm yes good point about previous versions
I was under the impression he was setting the variable to true or false, not checking to see if it contains a non zero non null value. my bad

Reply With Quote
  #13  
Old October 21st, 2002, 03:15 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
No problem. Ive just seen many many posts on my home forum where people are having problems with thier applications, and most of the time it all comes down to bad coding practices. You will probably see alot of my posts correcting coding practices, but of course, no offense to anyone. I am just really keen on writing and running clean and efficient code within the general rules of PHP application development, makes it easier to understand also....

Chow -

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Get Url


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |