Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

Variables..

General discussions related to php

Moderators: macek, egami, gesf

Variables..

Postby Insolence » Sat Aug 23, 2003 1:16 pm

in this:
Code: Select all
<?
  //Retrieves data from end of URL
  function get_args($string) {
     return substr($string, $strpos($string, '?') + 1);
  }
  //Data is sent to ?
 
  switch($??)
  {
    case "redirect" :
      echo "Bahumbug";
      break;
    case "links" :
      echo "Bahumbug2";
      break;
    case "home" :
      echo "Bahumbug3";
      break;
    default :
      echo "Where are you going, young man?";
      break;
   }
     


Where is the data, after the url, sent to? Sorry if this is a dumb question, i tried most of the variables up there, do i have to do something like switch(get_args($string))
Insolence
New php-forum User
New php-forum User
 
Posts: 43
Joined: Tue Aug 19, 2003 1:27 pm

Re: Variables..

Postby swirlee » Sat Aug 23, 2003 1:26 pm

Insolence wrote:do i have to do something like switch(get_args($string))


Yes. A function doesn't run until you call it. Either you can access its output directly (as above) or you can assign its output to a variable (e.g. $myvar = get_args($string)).
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby Insolence » Sat Aug 23, 2003 1:39 pm

Code: Select all
<?
  //Retrieves data from end of URL
  function get_args($string) {
     return substr($string, $strpos($string, '?') + 1);
  }
  //Data is sent to ?
  $myvar = get_args($string);
  switch($myvar)
  {
    case "redirect" :
      echo "Bahumbug";
      break;
    case "links" :
      echo "Bahumbug2";
      break;
    case "home" :
      echo "Bahumbug3";
      break;
    default :
      echo "Where are you going, young man?";
      break;
   }
     
?>


Shouldn't that work? im getting this error:Fatal error: Call to undefined function: () in c:\apache\htdocs\ybabtu\redirect.php on line 20

BTW, thanks for your god-like speed in replying to my problems ;) it is much appriciated, you answered before my friend did.. lol
Insolence
New php-forum User
New php-forum User
 
Posts: 43
Joined: Tue Aug 19, 2003 1:27 pm

Postby swirlee » Sat Aug 23, 2003 2:09 pm

Insolence wrote:Shouldn't that work? im getting this error:Fatal error: Call to undefined function: () in c:\apache\htdocs\ybabtu\redirect.php on line 20


Unless you're posting the entire contents of your code, you need to tell us which line is the line referred to in the error.

The problem is that on the third line of the code you posted, you have $strpos($string, '?') instead of strpos($string, '?').
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby Insolence » Sat Aug 23, 2003 2:14 pm

K i think i see a few problems aside from that, ill just fiddle with it
Insolence
New php-forum User
New php-forum User
 
Posts: 43
Joined: Tue Aug 19, 2003 1:27 pm

Postby tryton » Sat Aug 23, 2003 6:15 pm

Insolence wrote:BTW, thanks for your god-like speed in replying to my problems ;) it is much appriciated, you answered before my friend did.. lol


As far as I know, swirlee has a bunk in the back.
User avatar
tryton
New php-forum User
New php-forum User
 
Posts: 49
Joined: Wed Jul 09, 2003 8:25 am
Location: Joze

Postby swirlee » Sat Aug 23, 2003 7:24 pm

tryton wrote:As far as I know, swirlee has a bunk in the back.


lol. :mrgreen: sig'd.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby Insolence » Sat Aug 23, 2003 7:57 pm

I figured out what the problem is, you have to get the url, and send it to the variable, THEN check it, i thought what you posted, reads the url, atleast i think thats whats going on, ima fiddle with it (this sure is a boat load of fun ;))

EDIT: Done, and done :)
Code: Select all
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<img src="images/spacer.gif" height="200">
<table width="700" height="100" align="center">
  <tr>
    <td valign="middle" align="center" bgcolor="#F1F1F1"><font face="verdana" size=-2 color="#333333"> Please wait, you are being redirected, if you do not wish to be redirected, hit the back button in your browser now.</font></td>
  </tr>
</table>
</body>
</html>

<?
  //Retrieves data from end of URL
  $url_in = $_SERVER['REQUEST_URI'];
  //looks for ? and reads data after it
  function get_args($url_in) {
     return substr($url_in, strpos($url_in, '?') + 1);
  }
  //assigns data to a variable
  $myvar = get_args($url_in);
  switch($myvar)
  {
    case "redirect" :
      echo "Bahumbug";
      break;
    case "links" :
      echo "Bahumbug2";
      break;
    case "home" :
      echo "Bahumbug3";
      break;
    default :
      echo "Where are you going, young man?";
      break;
   }
     
?>

I guess i took something i didnt understand, next time i'll do a bit more research before i ask questions :)[/code]
Insolence
New php-forum User
New php-forum User
 
Posts: 43
Joined: Tue Aug 19, 2003 1:27 pm

Postby Joel » Sun Aug 24, 2003 2:46 am

Insolence, you could always use $_GET['varname']. Like this in the URL page.php?varname=varvalue
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

Postby Insolence » Sun Aug 24, 2003 1:32 pm

ALL FIXED!!

Thank you, so much everyone :)
Insolence
New php-forum User
New php-forum User
 
Posts: 43
Joined: Tue Aug 19, 2003 1:27 pm


Return to PHP General

Who is online

Users browsing this forum: No registered users and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.