Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

php help


  • Please log in to reply

#1
amunra

amunra

    Member

  • Member
  • PipPipPip
  • 112 posts
I need to be able to turn my url from the simple index.php to index.php?act=blablabla. IE: index.php?act=home is an example.

Thanks a lot :tazz:
  • 0

Advertisements


#2
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
Put this at the start of your PHP script:
header( "Location:index.php?act=blablabla");

  • 0

#3
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
sorry that would actually recurse the page. Try this:
if (!isset($_GET["act"])) header("Location:index.php?act=blablabla");

  • 0

#4
amunra

amunra

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 112 posts
Cool, what else do I need to do? Do I need to add seperate pages? What I am trying to do is make a redirect page named redir.php. Then I need to add the redirect script to that page to transfer it. ie:msn
redir.php?act=redir&id=msn
for instance.

Thanks
  • 0

#5
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
Um, I am not sure what you are trying to achieve. Isn't is simpler to just add a hyperlink in HTML?

If this is not the case, please describe the situation and we'll see what can be done. :tazz:
  • 0

#6
amunra

amunra

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 112 posts
What I need to do is make a single page called redir.php. Then I need to add url redirects to that page that link to outside pages.
<? header("Location: http://www.msn.com"); ?>
is an example of what I use as a redirect code. I need to place several of these into redir.php and be able to choose which one I want via the address bar. I have tried this for the redirect code
$msn = header("Location: http://www.msn.com"); ?>
and typed this ini the address bar
redir.php?$msn
But nothing happens.

Any other ideas?

Thanks
  • 0

#7
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
Well it seems very strange why not use <A> in HTML, but what you want is this:

<?php
	switch ($_GET["act"]) {
		case "msn": 
			header("Location: http://www.msn.com");
			break;
		case "yahoo": 
			header("Location :http://www.yahoo.com");
			break;
	}
?>

add more branches to the switch and you will get more redirects possible. And don't forget to break :tazz:

Edited by Hai Mac, 31 December 2005 - 03:04 PM.

  • 0

#8
amunra

amunra

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 112 posts
Ok I just tried it and all it did is print the code on the screen. what would I type in the address bar to use this?
redir.php?act=msn
mabe

Thanks
  • 0

#9
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
Sorry, messed it up a bit. Now it should work
  • 0

#10
amunra

amunra

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 112 posts
SWEET it works, now I am going to add some more links to test. THANKS A LOT
  • 0

#11
amunra

amunra

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 112 posts
Lets see if I can make a lesson on this. :tazz:

To make a php redirect page follow these directions.

1. Open notepad and enter the following code
<?php
	switch ($_GET["act"]) 
		{
			case "[color=#3333FF]google[/color]": 
				header("Location: [color=#FF0000]http://www.google.com[/color]");
				break;
		}	
?>
The text in blue is what you will need to type in the address bar after the ?act=, for mine I used a number, but you can use any name you want. for this redirection script you will need to type name of your file.php?act=google to use the google redirection. You can change the text in red to any url you want.

Now to break down the code
<?php
Starts the php script
switch ($_GET["act"])
means it will use the GET method to check if the ?act= is in the address bar
{
starts the main redirect code
case "google":
Specifies what you need to type after the ?act=. It can be anything you want.
header(Location:http://www.google.com");
Specifies where the page should send the user after the ?act=google is entered in the address bar.
break;
I do not yet know what this means.When i do I will update this. If someone knows let me know
}
Ends the main redirect code
?>
Ends the php script
Now you can save the file as anything you want, but make shure you include the .php at the end of the file name or it will not work. To link to this page from another, like you index.php page you could use this code to go to google as long as this redirect page is in the same directory
<a href=name of your redirect page.php?act=google
Save it and test it. I have found that testing the scripts is a very important part of the scripting process. I created a special folder called test that I do this in.

If anything here is incorect please let me know so I can update this.
Thanks again Hai Mac!
  • 0

#12
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
The first part is good, but few amendments: switch tells PHP something like look at this variable and tell me what it contains. In case it contains google redirect me to blah blah. break tells PHP to get out to the end of the switch that is to }. Otherwise PHP will just redirect to all pages mentioned in the rest of the code.

And that's all folks :tazz:

Edited by Hai Mac, 31 December 2005 - 03:54 PM.

  • 0

#13
amunra

amunra

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 112 posts
Cool did not know that. Check out my other script lesson, its on a scroling news ticker. I will update the post when I get time.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP