Variables..

A

Anonymous

Guest
in this:
Code:
<?
  //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 said:
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)).
 
Code:
<?
  //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 said:
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, '?').
 
K i think i see a few problems aside from that, ill just fiddle with it
 
Insolence said:
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.
 
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:
<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, you could always use $_GET['varname']. Like this in the URL page.php?varname=varvalue
 
Back
Top