PHP Easy URL Problem

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

36 Replies - 3652 Views - Last Post: 08 August 2007 - 09:18 AM Rate Topic: -----

#1 duffsstuff   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 10-September 06

PHP Easy URL Problem

Posted 07 August 2007 - 12:03 PM

I am trying to make a clean URL script for my website and I have coded the base of what I need but I have come accross 3 error and I don't know how to fix them. Here are my errors:

Notice: Undefined index: PATH_INFO in /homepages/cleanurl.php5 on line 57
Notice: Undefined offset: 0 in /homepages/cleanurl.php5 on line 61
Notice: Undefined offset: 1 in /homepages/cleanurl.php5 on line 62

I have put in my code where the errors are. The beginning of the line with an error has: '{{line#}}'

/*
|---------------------------------------------------------------
| Clean URL's
|---------------------------------------------------------------
|
| Allows the script to make make clean URL's.
| 
| Example:
| http://www.domain.com/index.php/pages/home
|
*/	
{{57}}		$path_info = $_SERVER['PATH_INFO']; 
	$clean_url = explode('/',$path_info);
	array_shift($clean_url);

{{61}}	$GLOBALS['action']	= $clean_url[0]; // This is our action
{{62}}	$GLOBALS['name']	= $clean_url[1]; // This is our action's name



Is This A Good Question/Topic? 0
  • +

Replies To: PHP Easy URL Problem

#2 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: PHP Easy URL Problem

Posted 07 August 2007 - 12:24 PM

With mod_rewrite you can capture http://www.domain.co....php/pages/home and forward them to http://www.domain.co....php?u=whatever but in the address bar www.yoursite.com/xmod will be showing (the user wont know they're not at the other URL).With mod_rewrite in the .htaccess file you could add

RewriteEngine On
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?u=$1



Now with this instead of typing [http://www.domain.com/index.php/pages/home....php?u=whatever (or whatever you're trying to change to a clean URL) you can type http://www.domain.co....php/pages/home and both will take you to the same place.

Remember this is done in .htaccess file

This post has been edited by PsychoCoder: 07 August 2007 - 12:25 PM

Was This Post Helpful? 0
  • +
  • -

#3 duffsstuff   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 10-September 06

Re: PHP Easy URL Problem

Posted 07 August 2007 - 12:33 PM

I know about the .htaccess file, But I need something that will work with any type of server that runs PHP, like how CI uses URL's.
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: PHP Easy URL Problem

Posted 07 August 2007 - 01:21 PM

Heres some information on using mod_rewrite in IIS

mod_rewrite In IIS
Was This Post Helpful? 0
  • +
  • -

#5 duffsstuff   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 10-September 06

Re: PHP Easy URL Problem

Posted 07 August 2007 - 01:29 PM

:angry: I don't want to use mod_rewrite!!!! I want to use PHP!!!

Please help me fix the errors in my script, Please. I don't want to use mod_rewrite. I don't need to hear about how to use something I don't want to use. I know how to use it but don't want to for this script, it just isn't going to work for this script.

Sorry, I usually don't get mad but if I wanted to use mod_rewrite I would of used one of the ten thousand tutorials on the internet.

Can someone please help me with my script and not trying to pull me into something I don't want to use? :angry:
Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: PHP Easy URL Problem

Posted 07 August 2007 - 01:31 PM

View Postduffsstuff, on 7 Aug, 2007 - 01:29 PM, said:

:angry: I don't want to use mod_rewrite!!!! I want to use PHP!!!

Please help me fix the errors in my script, Please. I don't want to use mod_rewrite. I don't need to hear about how to use something I don't want to use. I know how to use it but don't want to for this script, it just isn't going to work for this script.

Sorry, I usually don't get mad but if I wanted to use mod_rewrite I would of used one of the ten thousand tutorials on the internet.

Can someone please help me with my script and not trying to pull me into something I don't want to use? :angry:


Theres no reason to be an ass! You asked for help, I fucking offered it! mod_rewrite IS THE BEST SOLUTION for what you want.

<edit>Its quite obvious your idea isn't working, otherwise you wouldn't be here asking for help!</edit>

This post has been edited by PsychoCoder: 07 August 2007 - 01:32 PM

Was This Post Helpful? 0
  • +
  • -

#7 duffsstuff   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 10-September 06

Re: PHP Easy URL Problem

Posted 07 August 2007 - 01:37 PM

I do thank you for the help, but it is not what I am looking for. I am sorry I have been up for about 40 hours working on my program and really just wanted some help. I know that mod_rewrite would be the best answer but I just want to do it in PHP instead. I would like some help fixing the errors in my script. I am sorry that I got mad.
Was This Post Helpful? 0
  • +
  • -

#8 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: PHP Easy URL Problem

Posted 07 August 2007 - 01:38 PM

And I offered you a clean, efficient (actually best solution for your problem) and you jumped down my throat so find your own goddamn solution! If you actually "knew" mod_rewrite you'd KNOW its the best solution for your problem. So have fun finding a solution :)
Was This Post Helpful? 0
  • +
  • -

#9 duffsstuff   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 10-September 06

Re: PHP Easy URL Problem

Posted 07 August 2007 - 01:44 PM

Thanks for the help? I am sorry. Is there anyone that understands what I want to do that can help? I really just need my errors fixed and I don't know what is wrong with my code other then what the errors gave me and I don't know how to fix it.
Was This Post Helpful? 0
  • +
  • -

#10 duffsstuff   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 10-September 06

Re: PHP Easy URL Problem

Posted 07 August 2007 - 01:51 PM

So what I want to do is have my PHP script interpret this:
http://www.domain.co....php/pages/home

Instead of having:
http://www.domain.co...on=page&id=home

I have the logic that will get the correct page based on the variables the script I posted returns. If anyone wants to see that logic just ask and I will post it, but it hasn't returned any errors when I tested it and it seems almost independent from what I posted.
Was This Post Helpful? 0
  • +
  • -

#11 Xmod   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 19-January 07

Re: PHP Easy URL Problem

Posted 07 August 2007 - 01:57 PM

Use mod_rewrite man! thats the best logic solution....
Was This Post Helpful? 0
  • +
  • -

#12 duffsstuff   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 10-September 06

Re: PHP Easy URL Problem

Posted 07 August 2007 - 02:03 PM

Thanks, but I really want to use PHP. Can you help me debug my code?
Was This Post Helpful? 0
  • +
  • -

#13 Xmod   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 19-January 07

Re: PHP Easy URL Problem

Posted 07 August 2007 - 02:14 PM

Try doing this... :)
$path_info = $_SERVER['PATH_INFO'];
	$clean_url = explode('/',$path_info);
	$cleanUrl = array_shift($clean_url);

{{61}}	$GLOBALS['action']	= $clean_url[0]; // This is our action
{{62}}	$GLOBALS['name']	= $clean_url[1]; // This is our action's name



ALso try printing out what the values of $clean_url are giving you... that might help

This post has been edited by Xmod: 07 August 2007 - 02:19 PM

Was This Post Helpful? 0
  • +
  • -

#14 snoj   User is offline

  • Married Life
  • member icon

Reputation: 93
  • View blog
  • Posts: 3,583
  • Joined: 31-March 03

Re: PHP Easy URL Problem

Posted 07 August 2007 - 02:20 PM

Everyone, lay off. He didn't ask what tool would be the best for this problem. He asked about what was wrong with the tool he was writing. Yes, mod_rewrite is the best, however not every server out there has it running and thus people are made to look for their own solutions. Also, many a tool we use today came from those who said, "eff that!" to the generally accepted method. (PHP being one of those.)

Now duffsstuff, do you have anything after the php file (index.php/more/paths)? It would appear that $_SERVER['PATH_INFO'] is not populated when there is no "path".
Was This Post Helpful? 0
  • +
  • -

#15 Xmod   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 19-January 07

Re: PHP Easy URL Problem

Posted 07 August 2007 - 02:26 PM

have you tried using $_SERVER["PHP_SELF"]??
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3